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.
-
- Ported the MPU6050 DMP driver unchanged, but its FIFO stayed empty. The original called
IIC_MPU6050_Init()from board code outside the driver, and without it SCL sat in its reset state. - Got
printftelemetry working after fixing three silent gaps: thenosys.specs_writestub, newlib fully buffering stdout, and the ST-Link V2 having no UART. Telemetry comes out of the robot’s USB-C port through its CH340. - Traced an angle of
-2147483648in every sample to uninitialised floats in the IMU class. That value is what ARM produces when casting NaN toint. The constructor now zeroes the angles and sets the quaternion to identity.
- Ported the MPU6050 DMP driver unchanged, but its FIFO stayed empty. The original called
-
- Got the first green firmware build from GCC and CMake: 36.2 KB of the 256K flash (14%) and 2.5 KB of RAM (5%). It had not been flashed yet.
- Added a
_writeretarget soprintfreaches the UART under newlib. - Added a firmware build job to CI alongside the host tests, and both passed.
-
- Planned a GCC firmware build with
arm-none-eabi-gcc, CMake and OpenOCD, running alongside the vendor’s Keil project. - Found the vendor already shipped a GCC startup file and linker script for the STM32F103RCT6, a Cortex-M3 with 256K flash and 48K RAM.
- Vendored the CMSIS and peripheral library sources. Nothing had been compiled yet.
- Planned a GCC firmware build with
-
- Added unit tests for
AppControlusing mock sensor and motor interfaces, including the tilt cutoff at 45° and the normal drive path. All 14 test cases passed locally. - Fixed test discovery in the CMake build with
enable_testing()andDISCOVERY_MODE PRE_TEST, committed the control changes, and CI passed.
- Added unit tests for
-
- Wired the safety cutoff and the forward and turn commands (
move_x,move_z) throughAppControl::update, with the deadzone and clamp applied before the motors are driven. - A review found the commands were not yet passed into the velocity and turn controllers, and that was fixed. The changes were not yet built or committed.
- Wired the safety cutoff and the forward and turn commands (
-
- Fixed the simulator’s physics integration: each step overwrote the velocity with
velocity_ = force * dtinstead of accumulating it with+=. - Named the motor timer’s magic numbers, such as
PWM_ARR = 2880for 25kHz PWM. - Found that the control loop did not yet apply the motor deadzone, the PWM clamp or the safety cutoff.
- Fixed the simulator’s physics integration: each step overwrote the velocity with
-
- Added unit tests for the
TurnPDcontroller covering zero input, gyro output and themove_zturn offset, alongside the existingVelocityPItests. - Added a GitHub Actions workflow that builds with CMake and runs the tests with CTest on every push. It had not been pushed to GitHub yet.
- Added unit tests for the
-
- Added a CMake build for the PC targets, the simulator and the unit tests, using C++17 with Google Test fetched at configure time. The STM32 firmware still built in Keil.
- Added a Docker build environment and a VS Code devcontainer on the same Dockerfile.
- Registered each test case with CTest through
gtest_discover_tests.
-
- Wrote the hardware abstraction layer.
Stm32MotorHalandStm32SensorHalwrap the vendor drivers, and a simulated pair,SimSensorHalandSimMotorHal, share onePhysicsmodel so the same control code runs on a PC. - Added
AppControl, which reads the sensors, runs the balance, velocity and turn controllers, and mixes them asbalance + velocity - turnfor the left wheel andbalance + velocity + turnfor the right. - Wrote the STM32 entry point: motor PWM at 25kHz and a loop meant to run at 200Hz using
delay_ms(5).
- Wrote the hardware abstraction layer.
-
- Finished the
Usartclass, which sends serial output and routesprintfthroughfputcso the firmware can print telemetry. - Wrote
Stm32SensorHal, which implements the hardware-independentISensorHalinterface by delegating to the IMU, encoder and battery classes, keeping vendor driver calls out of the control code.
- Finished the