Skip to content

fix(servos): cap the slew step after a stalled loop - #120

Merged
jamro merged 1 commit into
jamro:mainfrom
BigGreenDelta:fix/servo-slew-stall-cap
Nov 23, 2026
Merged

jamro merged 1 commit into
jamro:mainfrom
BigGreenDelta:fix/servo-slew-stall-cap

Conversation

@AJIADb9

@AJIADb9 AJIADb9 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ServoWrapper::update() sizes each step from the time since the joint's previous step. When a blocking call stalls the loop while a joint is still slewing (a smooth or calibration move such as POST /test/servo or POST /setup/servo, or a flash write), the next step covers speed x stall time in one go. Example: a 3 s calibration move at 25 deg/s made another joint that was still slewing jump 75 deg at once instead of slewing.

stop() also left that timestamp in place, so a later setTarget() could time its first step from the old stop.

Changes:

  • servoSlewNext() in include/servos.h holds the step math and caps the gap at SERVO_MAX_STEP_GAP_MS (100 ms, ten loop steps), so a stalled joint resumes at its commanded speed.
  • ServoWrapper::stop() resets lastUpdateMs_.
  • New native test test/test_servo_slew.

Normal loop timing is unchanged: steps under 100 ms behave exactly as before.

Testing: pio test -e native -f test_servo_slew -f test_servo_norm passes. Found and checked on an ESP32 build of this firmware (LEDC servo outputs) with 5 SG90s on the bench.

Summary by CodeRabbit

  • New Features
    • Servo movement now advances toward its target at the configured speed, whether moving up or down, and settles directly on nearby targets.
  • Bug Fixes
    • Long pauses between updates no longer cause an oversized movement step.
    • Stopping a servo resets its timing interval, so movement toward a later target starts with a fresh interval.

ServoWrapper::update() sized each step from the time since the joint's
previous step. A blocking call (smooth or calibration move, flash write)
that stalled the loop while a joint was slewing let it cover speed x
stall time in one step: a 3 s calibration move at 25 deg/s made another
joint jump 75 deg at once. stop() also left that timestamp behind, so a
later setTarget could time its first step from the old stop.

Cap the step gap at 100 ms (servoSlewNext in servos.h) and reset the
timestamp in stop(). Adds a native test for the step math.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds a bounded servo slew-step helper, uses it in ServoWrapper, resets the update timestamp when stopping, and adds tests for movement limits and target arrival.

Changes: Servo Slew Step Control

Layer / File(s) Summary
Bound slew steps
include/servos.h
Adds SERVO_MAX_STEP_GAP_MS and servoSlewNext. The helper limits elapsed time and movement toward the target.
Apply and test slew steps
src/hardware/servo_wrapper.cpp, test/test_servo_slew/test_servo_slew.cpp
ServoWrapper::stop resets lastUpdateMs_, and ServoWrapper::update uses servoSlewNext. Tests cover movement in both directions, reaching a nearby target, capping a stalled gap, and holding at zero speed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jamro

Merge Risk: Minimal · up to b8f64

This change caps the servo step after a stalled loop and resets the update timestamp on stop. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the primary change: capping the slew step after a stalled loop. The changeset adds servoSlewNext with a 100 ms elapsed-time cap (SERVO_MAX_STEP_GAP_MS), wires ServoWrapper::update to u…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the primary change: capping the slew step after a stalled loop. The changeset adds servoSlewNext with a 100 ms elapsed-time cap (SERVO_MAX_STEP_GAP_MS), wires ServoWrapper::update to use it, and adds tests for the capped stalled gap. The title is specific and matches the objectives. The stop() reset of lastUpdateMs_ is a secondary change that the title does not mention, which is acceptable.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 58dca921-19d5-4dd7-94c7-dde2023b6f5b
Commits

Reviewing files that changed from the base of the PR and between 3778f5a and b8f6416.

Files selected for processing: 3

  • include/servos.h
  • src/hardware/servo_wrapper.cpp
  • test/test_servo_slew/test_servo_slew.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@jamro

jamro commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for this. The 100 ms cap in servoSlewNext() and the lastUpdateMs_ reset in stop() keep a stalled loop from dumping a whole slew into one step.

@jamro
jamro merged commit c4cb3f5 into jamro:main Nov 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants