A balancing robot written in Go and running on ARM Linux.

Mod list

Changes to make:

  • Move the gyro down between the wheels. Reduces the acceleration seen due to falling.

Other robots

There’s a ton out there.

  • lil-bot uses the same motors (MG-6-48) but with encoders. 7xAA so 8.4 V to 10.5 V. 100 Hz control loop. MPU-6050 with 2 % complementary filter. Has a err**2 term as well.


v1 can balance but poorly. The big differences were:

  • Better pitch measurement through a complementary filter. Gives the absolutes of the accelerometers and noise rejection of the gyros.
  • Integral control to respond quicker to small offsets.

Things I also changed:

  • PWM rate up to 10 kHz
  • Control loop up to 100 Hz
  • Gyro bias removal. The gyro had a 0.34 deg/s bias.

Things to check:

  • The gyro scale might be wrong and might be over reporting the angle.
  • The deadband on the motors is quite bad and is probably hurting the small tilt response. I might be able to kick the motors to start things turning then return to the demanded speed.
  • Is the gyro saturating?
  • I2C speed
  • Add voltage compensation?


v0 is done but doesn’t really work. Issues:

  • The motors have a high deadband and are too high speed.
  • The pitch is based off the accelerometers only and seems very noisy.
  • The motors are independant, so at low drive sometimes one will start and the other stay still.

Next steps:

  • Measure the CPU load
  • Measure the pitch while standing upright and steady
  • Investigate complementry filters to combine the gyro and accelerometers
  • Investigate the IMUs advanced features to see if it already gives a good pitch
  • Profile the motors to see if I can lower the deadband (dither?)
  • Check I2C rate is 100 kHz or higher.


  • The 20 ms timer fires at ~16 ms and ~24 ms. HZ is 128. Turn on TCB as a clock source, switch to low latency, switch to tickless.

  • IMU has:

  • DLPF, a low pass filter. Use to filter accelerometers?

  • Default accelerometer range is +-2G (as the default reading is ~16000)

Michael Hope
Software Engineer