Skip to content

Commit 1a97e9c

Browse files
committed
it drives! too spinny but we can fix that!
1 parent c18d6ca commit 1a97e9c

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

drivetrain/controlStrategies/autoDrive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def update(self, cmdIn: DrivetrainCommand, curPose: Pose2d) -> DrivetrainCommand
4545

4646
# If being asked to auto-align, use the command from the dynamic path planner
4747
if(self._toPickup or self._toSpeaker):
48-
cmdIn = self._dpp.get()
48+
retCmd = self._dpp.get()
4949

5050
self._toSpeakerPrev = self._toSpeaker
5151
self._toPickupPrev = self._toPickup

navigation/dynamicPathPlanner.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,26 @@ def get(self) -> DrivetrainCommand:
6161
# We'll sample the path before and after the current timestanp
6262
# and use finite differences to derive a drivetrain velocity command
6363
curTime = Timer.getFPGATimestamp() - self.trajStartTime_s
64-
prevTime = max(0.0, curTime - 0.01)
65-
nextTime = curTime + 0.01
66-
deltaTime = nextTime - prevTime
67-
68-
prevSample = self.curTraj.sample(prevTime).pose
69-
curSample = self.curTraj.sample(curTime).pose
70-
nextSample = self.curTraj.sample(nextTime).pose
71-
72-
xVel = (nextSample.translation().X() - prevSample.translation().X())/deltaTime
73-
yVel = (nextSample.translation().Y() - prevSample.translation().Y())/deltaTime
74-
rotVel = (nextSample.rotation() - prevSample.rotation()).radians()/deltaTime
75-
76-
return DrivetrainCommand(
77-
xVel,yVel,rotVel,curSample
78-
)
64+
if(curTime < self.curTraj.totalTime()):
65+
prevTime = max(0.0, curTime - 0.01)
66+
nextTime = curTime + 0.01
67+
deltaTime = nextTime - prevTime
68+
69+
prevSample = self.curTraj.sample(prevTime).pose
70+
curSample = self.curTraj.sample(curTime).pose
71+
nextSample = self.curTraj.sample(nextTime).pose
72+
73+
xVel = (nextSample.translation().X() - prevSample.translation().X())/deltaTime
74+
yVel = (nextSample.translation().Y() - prevSample.translation().Y())/deltaTime
75+
rotVel = (nextSample.rotation() - prevSample.rotation()).radians()/deltaTime
76+
77+
return DrivetrainCommand(
78+
xVel,yVel,rotVel,curSample
79+
)
80+
else:
81+
return DrivetrainCommand(
82+
0,0,0,self.curGoal.endPose
83+
)
7984

8085
else:
8186
# No path, no motion

navigation/gradientDescentCostMap.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def _gradient_descent_on_function(self, start: tuple[int, int], step_size: float
9090
max_iter = int(math.sqrt(straightline_x ** 2 + straightline_y ** 2) / step_size * 20.0)
9191

9292
path = []
93-
93+
94+
# First point is always part of the path
95+
path.append(np.array([x, y]))
96+
9497
for step in range(max_iter):
9598

9699
# Constrain x/y to be on the field
@@ -128,12 +131,12 @@ def _gradient_descent_on_function(self, start: tuple[int, int], step_size: float
128131
path.append(np.array([x_end, y_end]))
129132
break
130133

131-
x, y = new_x, new_y
134+
if step == max_iter - 1:
135+
# If max iterations reached, return path without the final point
136+
print("Max iterations reached. Stopping.")
137+
break
132138

133-
134-
# If max iterations reached, return path without the final point
135-
if step == max_iter - 1:
136-
print("Max iterations reached. Stopping.")
139+
x, y = new_x, new_y
137140

138141
# Simplify the path
139142
return self._resample_path(path, 2.5)

simgui.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@
7373
"selectable": false,
7474
"style": "Track"
7575
},
76+
"desTrajWaypoints": {
77+
"arrows": false,
78+
"color": [
79+
0.5709201693534851,
80+
0.20304691791534424,
81+
0.8284313678741455,
82+
255.0
83+
],
84+
"length": 0.20000000298023224,
85+
"weight": 6.0,
86+
"width": 0.20000000298023224
87+
},
7688
"height": 8.210550308227539,
7789
"left": 150,
7890
"right": 2961,

0 commit comments

Comments
 (0)