Skip to content

Commit 6fbb3cb

Browse files
authored
Merge pull request AtsushiSakai#199 from KoenHan/dwa_only
DWA cost function toward goal
2 parents 323ca86 + a4f33de commit 6fbb3cb

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

PathPlanning/DynamicWindowApproach/dynamic_window_approach.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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
3636
self.robot_radius = 1.0 # [m]
3737

@@ -137,14 +137,12 @@ def calc_obstacle_cost(traj, ob, config):
137137

138138

139139
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
140+
# calc to goal cost.
141+
142+
dx = goal[0] - traj[-1, 0]
143+
dy = goal[1] - traj[-1, 1]
144+
error_angle = math.atan2(dy, dx)
145+
cost = config.to_goal_cost_gain * abs(error_angle - traj[-1, 2])
148146

149147
return cost
150148

0 commit comments

Comments
 (0)