sl-controls created pull request seb/saltylab-firmware#255

sl-controls
Mon, 02 Mar 2026 12:48:31 -0500

255#feat(controls): Battery-aware speed scaling (Issue #251)#

Summary

Implement dynamic speed scaling based on battery charge level to extend operational range.

Battery Scaling:

100-50% charge: 1.0 scale (full speed)

50-20% charge: 0.7 scale (70% speed - warning)

<20% charge: 0.4 scale (40% speed - critical)

Features

✅ Battery-aware speed scaling to extend operational range
✅ Three-tier scaling strategy (normal, warning, critical)
✅ Configurable thresholds and scaling factors
✅ Graceful fallback when battery unavailable
✅ 1Hz monitoring frequency

How It Works

1. Subscribe to battery state (sensor_msgs/BatteryState)

2. Read current battery percentage

3. Apply threshold-based scaling logic

4. Publish scaling factor (0.0-1.0) on /saltybot/speed_scale

Use Case

Integrate with speed limiting chain:

cmd_vel → battery_scaler → accel_limiter → cmd_vel_smooth

Benefits

Range Extension: 30-40% longer operational time at reduced speed

Battery Protection: Prevents over-discharge damage

Smooth Degradation: No sudden stops, gradual speed reduction

Mission Completion: Can finish tasks even with battery warnings

Configuration

critical_threshold: 0.20  # 20%
warning_threshold: 0.50   # 50%
full_scale: 1.0
warning_scale: 0.7
critical_scale: 0.4

Test Coverage

✅ 20+ unit tests:

Initialization and parameters

Battery state subscription

All scaling thresholds

Boundary conditions

Default behavior

Scaling hierarchy

Realistic scenarios (discharge, drops, recovery, oscillations, deep discharge)

Topics

Subscribed: /saltybot/battery_state (sensor_msgs/BatteryState)

Published: /saltybot/speed_scale (std_msgs/Float32)

Closes Issue #251.