A virtual version of the robot from the six classes: an MPU6050 that reads like the real one, the same complementary filter, PID, dead zone, tilt cutoff and outer loop, and a body that falls the way a real one does.
| ax 0x3B | ||
| ay 0x3D | ||
| az 0x3F | ||
| gx 0x43 | ||
| gy 0x45 | ||
| gz 0x47 |
16384 counts = 1 g, 131 counts = 1 °/s. The robot tips around the X axis, so ay and az carry the tilt and gx the turning rate.
| accAngle | ° | |
| gyroRate | °/s | |
| angle (fused) | ° | |
| true tilt | ° (sim only) | |
| u → PWM | ||
| STBY | ||
| encoder counts | 330 per wheel turn | |
| wheelSpeed | mm/s | |
| position | mm from the tape |
An accelerometer measures gravity plus every other push it feels. When the wheels speed up under the robot, that push looks exactly like a lean the other way. Tap the table or slide the robot in Class 1 to see it. On a balancing robot the wheels are always speeding up and slowing down, so the filter has to lean on the gyro. In Class 6, compare α = 0.98 and 0.995 with the same push.
To keep rolling, a motor needs a steady PWM, and with PID alone a steady PWM needs a steady lean, which makes it roll faster. The I term holds that PWM without the lean. The outer loop in Class 5 watches the encoders and tips the target angle back, so the robot finds its own balance point, even with a book on top.
The numbers are assumptions, not your robot: JGB37-520-type motors (about 315 rpm, 0.75 N·m stall at 12 V), 80 mm wheels, a 1.1 kg body with the power bank on top, an IMU mounted 1° off level. It skips gear backlash, wheel slip, I²C timing and a sagging battery. Use it to see why things happen, then tune the real robot with the knobs.