Skip to content

Commit 385e4af

Browse files
committed
Mending many math mistakes
1 parent b7e3481 commit 385e4af

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

navigation/repulsorFieldPlanner.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# However, near the goal, we'd like to slow down. This map defines how we ramp down
5252
# the step-size toward zero as we get closer to the goal. Once we are close enough,
5353
# we stop taking steps and simply say the desired position is at the goal.
54-
GOAL_MARGIN_M = 0.05
54+
GOAL_MARGIN_M = 0.2
5555
SLOW_DOWN_DISTANCE_M = 1.5
5656
GOAL_SLOW_DOWN_MAP = MapLookup2D([
5757
(9999.0, 1.0),
@@ -240,10 +240,30 @@ def _getCmd(self, curPose:Pose2d, stepSize_m:float) -> DrivetrainCommand:
240240

241241

242242
# Assemble velocity commands based on the step we took
243-
retVal.velX = (nextTrans - curTrans).X()/0.02 * slowFactor
244-
retVal.velY = (nextTrans - curTrans).Y()/0.02 * slowFactor
245-
retVal.velT = 0.0 # Let the closed-loop controller do the work.
246-
retVal.desPose = Pose2d(nextTrans, self.goal.rotation())
243+
# Note that depending on how the substeps fell, we might have taken more than a full step
244+
# We continue to take a step _in the direction_ of the sum of the substeps, but of
245+
# the correct size.
246+
247+
# First, Scale total step to be unit length
248+
totalStep = (nextTrans - curTrans)
249+
totalStep = totalStep * (1.0/totalStep.norm())
250+
251+
# Then, Scale totalStep to the right size
252+
totalStep *= (stepSize_m * slowFactor)
253+
254+
# Periodic loops run at 0.02 sec/loop
255+
retVal.velX = totalStep.X() / 0.02
256+
retVal.velY = totalStep.Y() / 0.02
257+
retVal.velT = 0.0 # For now.... Let the closed-loop controller do the work to rotate us correctly
258+
retVal.desPose = Pose2d(curTrans + totalStep, self.goal.rotation())
259+
260+
261+
else:
262+
# Case - at goal - just send the goal as the desired pose with (hopefully) no velocity
263+
retVal.velX = 0.0
264+
retVal.velY = 0.0
265+
retVal.velT = 0.0
266+
retVal.desPose = self.goal
247267
else:
248268
self.distToGo = 0.0
249269

0 commit comments

Comments
 (0)