feat: Battery voltage telemetry + LVC (Issue #613) #626

Merged
sl-jetson merged 1 commits from sl-firmware/issue-613-battery-voltage into main 2026-03-15 13:29:32 -04:00
Collaborator

Summary

Implements 3-stage low voltage cutoff (LVC) protection using the existing battery_read_mv() ADC interface.

  • include/lvc.h / src/lvc.c — LVC state machine

    • LVC_WARNING (21.0 V): MELODY_LOW_BATTERY buzzer, every 30 s; full power
    • LVC_CRITICAL (19.8 V): double-beep every 10 s; motor speed scaled to 50%
    • LVC_CUTOFF (18.6 V): MELODY_ERROR one-shot; motors disabled; latched until reboot
    • 200 mV hysteresis on recovery to prevent threshold chatter
    • lvc_get_power_scale() returns 100/50/0 — applied to ESC speed command
  • include/jlink.hJLINK_TLM_LVC (0x8B, 4 bytes): voltage_mv, percent (fuel gauge 0-100), protection_state (LvcState)

  • src/jlink.cjlink_send_lvc_tlm() frame encoder (10 bytes total)

  • src/main.c — integration

    • lvc_init() at startup
    • lvc_tick(now, battery_read_mv()) each 1 kHz loop tick
    • lvc_is_cutoff()safety_arm_cancel + balance_disarm + motor_driver_estop
    • lvc_get_power_scale() applied to ESC speed before motor_driver_update()
    • 1 Hz JLINK_TLM_LVC telemetry with percent fuel gauge
  • include/config.hLVC_WARNING_MV, LVC_CRITICAL_MV, LVC_CUTOFF_MV, LVC_HYSTERESIS_MV, LVC_TLM_HZ

Closes #613

## Summary Implements 3-stage low voltage cutoff (LVC) protection using the existing `battery_read_mv()` ADC interface. - **`include/lvc.h` / `src/lvc.c`** — LVC state machine - `LVC_WARNING` (21.0 V): `MELODY_LOW_BATTERY` buzzer, every 30 s; full power - `LVC_CRITICAL` (19.8 V): double-beep every 10 s; motor speed scaled to **50%** - `LVC_CUTOFF` (18.6 V): `MELODY_ERROR` one-shot; motors disabled; **latched until reboot** - 200 mV hysteresis on recovery to prevent threshold chatter - `lvc_get_power_scale()` returns 100/50/0 — applied to ESC speed command - **`include/jlink.h`** — `JLINK_TLM_LVC` (0x8B, 4 bytes): `voltage_mv`, `percent` (fuel gauge 0-100), `protection_state` (LvcState) - **`src/jlink.c`** — `jlink_send_lvc_tlm()` frame encoder (10 bytes total) - **`src/main.c`** — integration - `lvc_init()` at startup - `lvc_tick(now, battery_read_mv())` each 1 kHz loop tick - `lvc_is_cutoff()` → `safety_arm_cancel + balance_disarm + motor_driver_estop` - `lvc_get_power_scale()` applied to ESC speed before `motor_driver_update()` - 1 Hz `JLINK_TLM_LVC` telemetry with percent fuel gauge - **`include/config.h`** — `LVC_WARNING_MV`, `LVC_CRITICAL_MV`, `LVC_CUTOFF_MV`, `LVC_HYSTERESIS_MV`, `LVC_TLM_HZ` Closes #613
sl-webui added 2 commits 2026-03-15 10:15:18 -04:00
Upgrades saltybot_bag_recorder (Issue #488) with:

- Motion-triggered auto-record: subscribes /cmd_vel, starts on non-zero
  velocity, stops after 30s idle timeout (configurable)
- Auto-split at 1 GB or 10 min via subprocess restart
- USB/NVMe storage selection: ordered priority list, picks first path
  with >= 2 GB free (/media/usb0 -> /media/usb1 -> /mnt/nvme -> ~/bags)
- Disk monitoring: warns at 70%, triggers cleanup of bags >7 days at 80%
- JSON status on /saltybot/bag_recorder/status at 1 Hz
- Services: /saltybot/bag_recorder/{start,stop,split}
  (legacy /saltybot/{start,stop}_recording kept for compatibility)
- bag_policy.py: pure-Python MotionState, DiskInfo, StorageSelector,
  BagPolicy — ROS2-free, fully unit-testable
- 76 unit tests passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add include/lvc.h + src/lvc.c: 3-stage low voltage cutoff state machine
  WARNING  21.0V: MELODY_LOW_BATTERY buzzer, full motor power
  CRITICAL 19.8V: double-beep every 10s, 50% motor power scaling
  CUTOFF   18.6V: MELODY_ERROR one-shot, motors disabled + latched
  200mV hysteresis on recovery; CUTOFF latched until reboot
- Add JLINK_TLM_LVC (0x8B, 4 bytes): voltage_mv, percent, protection_state
  jlink_send_lvc_tlm() frame encoder in jlink.c
- Wire into main.c:
  lvc_init() at startup; lvc_tick() each 1kHz loop tick
  lvc_is_cutoff() triggers safety_arm_cancel + balance_disarm + motor_driver_estop
  lvc_get_power_scale() applied to ESC speed command (100/50/0%)
  1Hz JLINK_TLM_LVC telemetry with fuel-gauge percent field
- Add LVC thresholds to config.h (LVC_WARNING/CRITICAL/CUTOFF/HYSTERESIS_MV)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sl-jetson force-pushed sl-firmware/issue-613-battery-voltage from 3e60d7552a to 7785a16bff 2026-03-15 11:04:46 -04:00 Compare
sl-jetson merged commit 0e8758e9e1 into main 2026-03-15 13:29:32 -04:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

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