Skip to content

Commit 4e7fbc3

Browse files
committed
code clean up
1 parent 7560cbd commit 4e7fbc3

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed
-241 KB
Loading

PathPlanning/DynamicWindowApproach/dynamic_window_approach.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ def calc_dynamic_window(x, config):
5555
x[3] + config.max_accel * config.dt,
5656
x[4] - config.max_dyawrate * config.dt,
5757
x[4] + config.max_dyawrate * config.dt]
58-
# print(Vs, Vd)
5958

6059
# [vmin,vmax, yawrate min, yawrate max]
6160
dw = [max(Vs[0], Vd[0]), min(Vs[1], Vd[1]),
6261
max(Vs[2], Vd[2]), min(Vs[3], Vd[3])]
6362

64-
#print(dw)
65-
6663
return dw
6764

6865

@@ -76,7 +73,6 @@ def calc_trajectory(xinit, v, y, config):
7673
traj = np.vstack((traj, x))
7774
time += config.dt
7875

79-
# print(len(traj))
8076
return traj
8177

8278

@@ -98,7 +94,7 @@ def calc_final_input(x, u, dw, config, goal, ob):
9894
speed_cost = config.speed_cost_gain * \
9995
(config.max_speed - traj[-1, 3])
10096
ob_cost = calc_obstacle_cost(traj, ob, config)
101-
#print(ob_cost)
97+
# print(ob_cost)
10298

10399
final_cost = to_goal_cost + speed_cost + ob_cost
104100

@@ -110,9 +106,6 @@ def calc_final_input(x, u, dw, config, goal, ob):
110106
min_u = [v, y]
111107
best_traj = traj
112108

113-
# print(min_u)
114-
# input()
115-
116109
return min_u, best_traj
117110

118111

@@ -144,8 +137,8 @@ def calc_to_goal_cost(traj, goal, config):
144137

145138
goal_magnitude = math.sqrt(goal[0]**2 + goal[1]**2)
146139
traj_magnitude = math.sqrt(traj[-1, 0]**2 + traj[-1, 1]**2)
147-
dot_product = (goal[0]*traj[-1, 0]) + (goal[1]*traj[-1, 1])
148-
error = dot_product / (goal_magnitude*traj_magnitude)
140+
dot_product = (goal[0] * traj[-1, 0]) + (goal[1] * traj[-1, 1])
141+
error = dot_product / (goal_magnitude * traj_magnitude)
149142
error_angle = math.acos(error)
150143
cost = config.to_goal_cost_gain * error_angle
151144

@@ -197,7 +190,7 @@ def main():
197190
x = motion(x, u, config.dt)
198191
traj = np.vstack((traj, x)) # store state history
199192

200-
#print(traj)
193+
# print(traj)
201194

202195
if show_animation:
203196
plt.cla()
@@ -218,7 +211,9 @@ def main():
218211
print("Done")
219212
if show_animation:
220213
plt.plot(traj[:, 0], traj[:, 1], "-r")
221-
plt.show()
214+
plt.pause(0.0001)
215+
216+
plt.show()
222217

223218

224219
if __name__ == '__main__':

0 commit comments

Comments
 (0)