Share one control loop between straight() and turn(), compensate for battery voltage#104
Open
SaintSampo wants to merge 3 commits into
Open
Share one control loop between straight() and turn(), compensate for battery voltage#104SaintSampo wants to merge 3 commits into
SaintSampo wants to merge 3 commits into
Conversation
Extract shared movement logic from straight() and turn() into a unified _move() controller to reduce code duplication. Add voltage compensation that scales motor effort based on battery voltage to maintain consistent performance across different battery states. Add min_effort parameter to both movement methods for better control tuning.
Add optional distance_controller and heading_controller parameters to DifferentialDrive._move and use provided controllers if passed. Preserve existing default PID construction when controllers are None. Fix effort-floor logic by reading controller tolerances with getattr (avoids errors for controllers without tolerance). Update straight() and turn() callers to pass main/secondary controllers (turn swaps order so main/secondary map to heading/distance appropriately). No behavior change when controllers are omitted.
Adjust PID controller gains, tolerances, and minimum effort for the NanoXRP differential drive implementation. Increases min_effort from 0.05 to 0.10, refines distance and heading controller parameters, and increases tolerance_count from 3 to 10 for more stable control performance.
KalticCodes
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
straight()andturn()were near-duplicate loops solving the same problem on different axes. Both now delegate to a shared_move()that controls translation and rotation together._move()runs translation and rotation through their own controllers and mixes them asleft = translation - rotation,right = translation + rotation.straight()passesheading_target = 0,turn()passesdistance_target = 0, so each move drives one axis and actively holds the other at zero. A zero goal doesn't gate the exit, so both functions still exit on the same axis they did before.Changes
min_effortis a new optional argument on both functions.min_effort, spinning the robot in place over a fraction of a degree.__init__averages 8 readings intovoltage_scale, applied in_move.max_effortnow means fraction of nominal power, so duty can exceed it on a weak pack.arcade()unchanged.tolerance_count3 → 10 on both, since at the measured 11.2 ms loop period 3 was a 34 ms dwell — short enough to latch "done" while still moving through the band.