|
51 | 51 | # However, near the goal, we'd like to slow down. This map defines how we ramp down
|
52 | 52 | # the step-size toward zero as we get closer to the goal. Once we are close enough,
|
53 | 53 | # 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 |
55 | 55 | SLOW_DOWN_DISTANCE_M = 1.5
|
56 | 56 | GOAL_SLOW_DOWN_MAP = MapLookup2D([
|
57 | 57 | (9999.0, 1.0),
|
@@ -240,10 +240,30 @@ def _getCmd(self, curPose:Pose2d, stepSize_m:float) -> DrivetrainCommand:
|
240 | 240 |
|
241 | 241 |
|
242 | 242 | # 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 |
247 | 267 | else:
|
248 | 268 | self.distToGo = 0.0
|
249 | 269 |
|
|
0 commit comments