feat(pid): runtime PID tuning via USB + telemetry (bd-18i) #3

Merged
sl-jetson merged 1 commits from sl-controls/bd-18i-pid-tuning into main 2026-02-28 13:12:14 -05:00
Collaborator

Summary

  • Add USB command interface for live PID gain adjustment — no reflash needed
  • Commands: P<kp> I<ki> D<kd> T<setpoint°> M<max_speed> ?
  • Parsing in main loop (not USB IRQ), USB IRQ just copies to shared volatile buffer
  • Bounds-checked writes: kp 0–500, ki/kd 0–50, setpoint ±20°
  • Ack echoes current gains: {"kp":...,"ki":...,"kd":...}
  • Telemetry now streams pitch, rate, PID error, integral (windup monitor), motor cmd

Tuning workflow

picocom /dev/ttyACM0 -b 115200
P35.0   # set Kp
I1.0    # set Ki  
D5.0    # set Kd
T0.5    # trim setpoint to account for COG offset
?       # query current gains

Note: bd-18i branch includes bd-2dv changes (mpu6000 fusion). Merge after PR #2.

Closes bd-18i

## Summary - Add USB command interface for live PID gain adjustment — no reflash needed - Commands: `P<kp>` `I<ki>` `D<kd>` `T<setpoint°>` `M<max_speed>` `?` - Parsing in main loop (not USB IRQ), USB IRQ just copies to shared volatile buffer - Bounds-checked writes: kp 0–500, ki/kd 0–50, setpoint ±20° - Ack echoes current gains: `{"kp":...,"ki":...,"kd":...}` - Telemetry now streams pitch, rate, PID error, integral (windup monitor), motor cmd ## Tuning workflow ``` picocom /dev/ttyACM0 -b 115200 P35.0 # set Kp I1.0 # set Ki D5.0 # set Kd T0.5 # trim setpoint to account for COG offset ? # query current gains ``` Note: bd-18i branch includes bd-2dv changes (mpu6000 fusion). Merge after PR #2. Closes bd-18i
sl-controls added 2 commits 2026-02-28 12:31:04 -05:00
Add src/mpu6000.c implementing a complementary filter (α=0.98) on top of
the existing icm42688 SPI driver. Fixes wrong scale factors in balance.c
(was ±250°/s / ±2g; hardware is configured ±2000°/s / ±16g). Fusion now
lives in the IMU driver layer; balance_update() consumes IMUData directly.

- mpu6000_init(): calls icm42688_init(), seeds filter state
- mpu6000_read(): reads raw SPI, applies complementary filter, returns
  fused pitch (degrees) + pitch_rate (°/s) + accel_x/z (g)
- balance.c: removes duplicated fusion code, uses IMUData.pitch
- main.c: switches to mpu6000_init()/mpu6000_read(), updates telemetry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add USB command interface for live PID gain adjustment without reflashing:
  P<kp>  I<ki>  D<kd>  T<setpoint_deg>  M<max_speed>  ?

Command parsing runs in main loop (sscanf-safe), not in USB IRQ.
USB IRQ copies command to shared volatile buffer (cdc_cmd_buf), sets flag.
Acknowledgement echoes current gains: {"kp":...,"ki":...,"kd":...}

Bounds checking: kp 0-500, ki/kd 0-50, setpoint ±20°, max_speed 0-1000.
Gains validated before write — silently ignored if out of range.

Telemetry updated from raw counts to physical tuning signals:
  pitch (°x10), pitch_rate (°/s x10), error (°x10),
  integral (x10 for windup monitoring), motor_cmd, state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sl-controls force-pushed sl-controls/bd-18i-pid-tuning from 69f2fa0532 to 34fdb5d11b 2026-02-28 13:10:38 -05:00 Compare
sl-jetson merged commit c719cf5467 into main 2026-02-28 13:12:14 -05:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seb/saltylab-firmware#3
No description provided.