Project contents
← Self-balancing robot
Updates
Self-balancing robot
Every update on this project, newest first.
Updates are bullet-point summaries generated with AI from my commits and build notes, then checked by me. Project articles and learning notes are written by me.
-
- Finished the firmware side of the serial command link: received bytes now go through a buffer and a parser in the main loop, and commands are clamped, rate-limited and dropped to zero if the link goes quiet for 250 ms.
- Bench-tested it with the wheels off the ground. Arm and disarm keys still worked, a corrupted frame was rejected, and pausing the sender reported link loss after 251 ms. It has not driven on the floor yet.
- Battery readings fell to 5.4-6.0 V with the motors off, unexplained so far; the pack needs a meter check.
-
- Wrote the tests for a serial link that will let a computer send drive commands to the robot: a frame parser with a checksum, a speed governor and a receive buffer. With only stub code behind them, 22 of the 94 host tests failed, as intended.
- Checked the checksum values independently in Python, confirming that the example command frame in the plan was correct.
- Pinned down edge cases in the tests, including the maximum frame length, Windows line endings, and how far speed may change after a long gap.
-
- Designed a watchdogged serial link for driving the car: checksummed command frames with a sequence number, a 20 Hz heartbeat and a 250 ms timeout. Losing the link zeroes the targets and keeps the car balancing rather than disarming it.
- Set the initial limits at ±100 mm/s forward and ±30 deg/s turning. Not yet implemented.
-
- Enabled yaw-rate damping on hardware with
YawRateP(1.0, 30, 100)holding a target of zero. Over 248 rows of travel the mean yaw rate was −0.1 deg/s forward and −0.3 deg/s backward, so recovering pitch no longer turned the car. - At
kp=0.5, forward travel had yawed right on 45 of 47 rows, so the higher gain was kept. - Found that the left wheel free-spins about 10% faster than the right (580 vs 525 counts per 100 ms), so the car is expected to curve right at speed.
- Enabled yaw-rate damping on hardware with
-
- Measured the gyro’s yaw-rate sign on the car: four left turns read +56.9 to +78.8 deg/s and four right turns −59.0 to −87.6 deg/s, so left-positive needed no sign flip.
- Converted the gyro reading to deg/s in the hardware layer, so the application works in physical units.
- Started a yaw-rate controller,
YawRateP, as a stub returning 0. Its tests were not passing yet.
-
- Enabled the velocity integral at
Ki35 with a limit of 200. Over a 21.74 s capture the angle stayed between -8.39° and +8.42°, the peak motor command was 1040, and the car recovered from pushes. - A weaker
Ki=4trial had let the car creep backward with the integral pinned at its limit. - Verified that a stale sensor stops an armed car: with a fault injected, it disarmed exactly 25 ms after the last fresh sample and stayed stopped for 17.2 s.
- Enabled the velocity integral at
-
- Confirmed the car already balances freely: arming it with
astands it up and it holds. No telemetry of a free run exists yet, so capturing one comes next. - Verified the explicit arm gate on hardware. 8 of 10 test rows passed and the other 2 were recorded as not run. Across 14 boots and 12 faults the car armed 11 times, each straight after an operator
abyte, and never on its own. - Wrote a serial tool that sends raw keypresses while logging, so no CR/LF can follow an
aand leave the car silently refusing to arm.
- Confirmed the car already balances freely: arming it with
-
- Implemented arming over serial: only a clean
abyte arms the car, every other byte or anawith a receive error disarms it, and disarm wins a tie. The car boots disarmed. - The UART interrupt now reads the status register before the data register, so a receive error is caught for the byte it belongs to.
- All 57 host tests passed and the firmware built. Not yet tested on hardware.
- Implemented arming over serial: only a clean
-
- Planned an explicit armed state controlled over serial, so the motors drive only after an operator command.
- Found that the plan would still not detect a lift: an armed car that is picked up keeps driving.
- Planned reading the encoders on every fresh sample, so counts can no longer pile up while the motors are stopped.
-
- Found that the firmware had no launch gate: lifting the car left both motors at full PWM for a whole 8.5 s capture, because the body stayed inside the ±40° tilt cutoff.
- Found that recovering from a tilt fault was undone by encoder counts that had built up unread. The first sample after recovery read them all at once, and the motor command reached 43402 against a 2600 clamp.
- Added the velocity integral to the telemetry, since it could not be derived from the other fields.