Prevent goal oscillation and unintended differential drive arcs

This commit is contained in:
DCCONSTRUCTIONS
2026-10-08 21:14:12 +03:00
parent 012286e972
commit 2e85d95c71
7 changed files with 120 additions and 20 deletions
+16 -16
View File
@@ -96,23 +96,23 @@ class ChassisSpeedFeedback:
# requested yaw differential is retained. Safety zero stays zero.
pivot_room = abs(yaw_rate) * self.track_centres / 2
correction = max(-pivot_room, min(pivot_room, correction))
corrected = velocity + correction
# Feedback may reduce translation to zero, but cannot request an
# unplanned reversal. A pivot retains its opposed side directions.
if velocity * corrected < 0:
corrected = 0.0
nominal = SideSpeeds.from_twist(velocity, yaw_rate, self.track_centres)
proposed = SideSpeeds.from_twist(corrected, yaw_rate, self.track_centres)
# The nominal envelope owns each side's reversal through zero. A
# common correction must also respect a stationary/turning inner belt.
target = SideSpeeds(
*(
value if intent * value > 0 else 0.0
for intent, value in zip(
vars(nominal).values(), vars(proposed).values(), strict=True
)
)
).bounded(self.max_side)
# Limit the common correction before applying it to either belt.
# Clipping each side independently changes their difference and can
# amplify yaw when one nominal belt is near zero after a pivot.
for intent in vars(nominal).values():
if intent > 0:
correction = max(correction, -intent)
elif intent < 0:
correction = min(correction, -intent)
else:
correction = 0.0
corrected = velocity + correction
if velocity * corrected < 0:
corrected, correction = 0.0, -velocity
target = SideSpeeds.from_twist(corrected, yaw_rate, self.track_centres).bounded(
self.max_side
)
applied = target.twist(self.track_centres)
self.metrics = dict(
nominal_twist=[velocity, yaw_rate],