Skip to content

Commit 1896ee7

Browse files
committed
Changed the computation method of to_goal_cost
Signed-off-by: KoenHan <[email protected]>
1 parent 323ca86 commit 1896ee7

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

PathPlanning/DynamicWindowApproach/dynamic_window_approach.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def __init__(self):
3131
self.yawrate_reso = 0.1 * math.pi / 180.0 # [rad/s]
3232
self.dt = 0.1 # [s]
3333
self.predict_time = 3.0 # [s]
34-
self.to_goal_cost_gain = 1.0
34+
self.to_goal_cost_gain = 0.15
3535
self.speed_cost_gain = 1.0
36+
self.ob_cost_gain = 1.0
3637
self.robot_radius = 1.0 # [m]
3738

3839

@@ -133,18 +134,16 @@ def calc_obstacle_cost(traj, ob, config):
133134
if minr >= r:
134135
minr = r
135136

136-
return 1.0 / minr # OK
137+
return config.ob_cost_gain / minr # OK
137138

138139

139140
def calc_to_goal_cost(traj, goal, config):
140-
# calc to goal cost. It is 2D norm.
141-
142-
goal_magnitude = math.sqrt(goal[0]**2 + goal[1]**2)
143-
traj_magnitude = math.sqrt(traj[-1, 0]**2 + traj[-1, 1]**2)
144-
dot_product = (goal[0] * traj[-1, 0]) + (goal[1] * traj[-1, 1])
145-
error = dot_product / (goal_magnitude * traj_magnitude)
146-
error_angle = math.acos(error)
147-
cost = config.to_goal_cost_gain * error_angle
141+
# calc to goal cost.
142+
143+
dx = goal[0] - traj[-1, 0]
144+
dy = goal[1] - traj[-1, 1]
145+
error_angle = math.atan2(dy, dx)
146+
cost = config.to_goal_cost_gain * abs(error_angle - traj[-1, 2])
148147

149148
return cost
150149

0 commit comments

Comments
 (0)