Email me
Updates
← Self-balancing robot

Updates

Self-balancing robot

Every update on this project, newest first.

32 updates

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.

  1. AI summary

    • 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 printf telemetry working after fixing three silent gaps: the nosys.specs _write stub, 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 -2147483648 in every sample to uninitialised floats in the IMU class. That value is what ARM produces when casting NaN to int. The constructor now zeroes the angles and sets the quaternion to identity.
  2. AI summary

    • 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 _write retarget so printf reaches the UART under newlib.
    • Added a firmware build job to CI alongside the host tests, and both passed.
  3. AI summary

    • 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.
  4. AI summary

    • Added unit tests for AppControl using 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() and DISCOVERY_MODE PRE_TEST, committed the control changes, and CI passed.
  5. AI summary

    • Wired the safety cutoff and the forward and turn commands (move_x, move_z) through AppControl::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.
  6. AI summary

    • Fixed the simulator’s physics integration: each step overwrote the velocity with velocity_ = force * dt instead of accumulating it with +=.
    • Named the motor timer’s magic numbers, such as PWM_ARR = 2880 for 25kHz PWM.
    • Found that the control loop did not yet apply the motor deadzone, the PWM clamp or the safety cutoff.
  7. AI summary

    • Added unit tests for the TurnPD controller covering zero input, gyro output and the move_z turn offset, alongside the existing VelocityPI tests.
    • 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.
  8. AI summary

    • 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.
  9. AI summary

    • Wrote the hardware abstraction layer. Stm32MotorHal and Stm32SensorHal wrap the vendor drivers, and a simulated pair, SimSensorHal and SimMotorHal, share one Physics model 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 as balance + velocity - turn for the left wheel and balance + velocity + turn for the right.
    • Wrote the STM32 entry point: motor PWM at 25kHz and a loop meant to run at 200Hz using delay_ms(5).
  10. AI summary

    • Finished the Usart class, which sends serial output and routes printf through fputc so the firmware can print telemetry.
    • Wrote Stm32SensorHal, which implements the hardware-independent ISensorHal interface by delegating to the IMU, encoder and battery classes, keeping vendor driver calls out of the control code.