Tuning Guide
RIG-Hover is a self-balancing robot. Tune carefully and change only one thing at a time.
Bring-Up Order
- Mechanical inspection
- Battery voltage check
- Motor direction check
- Encoder feedback direction check
- IMU orientation check
- Head center check
- Fall protection check
- Hand-held balance
- Free-standing balance
- Move, rotate, and head commands
Do not skip straight to free-standing balance. First prove that sensors, motor directions, and protection logic are correct.
Safety Logic
The firmware contains protection logic in update_state():
abs(pitch) >= 60 deg or abs(roll) >= 40 deg for 500 ms -> robot_state = 0
abs(pitch) < 7 deg and abs(roll) < 7 deg for 1500 ms -> robot_state = 1
abs(wheel velocity) > 350 for repeated cycles -> robot_state = 0When robot_state == 0, wheel torque output must be zero.
Default Parameters
Current defaults from InitializeController():
pid_pos.fpKp = 60.0;
pid_vel.fpKp = 0.15;
pid_vel.fpKi = 0.01;
pid_pit.fpKp = 21.0;
kd_pit = 2.3;
imu_zero = -5.0;
lqr_k[0] = 1400.0f;
lqr_k[1] = 6.8f;
lqr_k[2] = 32.0f;
lqr_k[3] = 1.6f;The current main path uses LQR-style full-state feedback. Legacy PID variables are still present and some are exposed in the Web page, but active balance behavior is mainly determined by imu_zeroand lqr_k.
LQR State
pitch_ref = imu_zero * cosf(q_head * PI / 180.0f);
lqr_x = wheel_x - stable_pos;
lqr_vx = wheek_vx - vx;
lqr_q = pitch - pitch_ref;
lqr_dq = dq;
temp_u = -(lqr_k[0] * lqr_x
+ lqr_k[1] * lqr_vx
+ lqr_k[2] * lqr_q
+ lqr_k[3] * lqr_dq);Yaw is added as differential torque:
yaw_u = k_yaw * (yaw - q_head - stable_yaw);
tor1 = -temp_u + yaw_u;
tor2 = temp_u + yaw_u;Recommended Tuning Order
Order | Parameter | Meaning | Suggested step |
1 |
| Balance reference angle | 0.5 deg |
2 |
| Pitch error recovery | 1 to 3 |
3 |
| Pitch angular velocity damping | 0.1 to 0.3 |
4 |
| Velocity feedback | 0.5 to 1 |
5 |
| Position feedback | 50 to 100 |
6 |
| Heading hold | Small changes |
Do not increase LQR_k0early. Strong position feedback can create forward/backward surging.
Web Debug Page
After Wi-Fi connection, open:
http://<RIG-Hover-IP>/Endpoints:
GET /api/data
GET /api/set?i=<index>&v=<value>Current mapping:
index | Label | Actual variable |
0 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
| actually |
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
Known cleanup item: the Web label YAW_kpat index 8 actually sets imu_zero. Future firmware should rename the label or expose a real k_yawparameter.
Symptoms
Symptom | Possible cause | Check |
Falls immediately after release | Wrong zero, low battery, motor direction error |
|
High-frequency shaking | Pitch gain too high or damping too low | Lower |
Slowly drives forward/backward | Zero offset or wheel feedback bias | Tune |
Spins in place | Wheel mismatch, yaw bias, cable mapping issue | Motor mapping, wheel friction, |
Screen works but no balance | IMU task or motor task abnormal | Serial logs and |
Acceptance Tests
- Hand-held startup enters balance without violent oscillation.
- Free-standing balance is stable.
- A light tap is followed by quick recovery.
- Move forward/backward commands do not create severe impact.
- Rotate left/right directions are correct.
- Head left/right/center directions are correct.
- Wi-Fi setup and reboot do not create uncontrolled behavior when the robot is held.
