diff --git a/.gitmodules b/.gitmodules index 041d8e2c..f91241a1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "PathPlanning/MixIntegerPathPlanning/matplotrecorder"] path = PathPlanning/MixIntegerPathPlanning/matplotrecorder url = https://github.com/AtsushiSakai/matplotrecorder +[submodule "PathPlanning/DynamicWindowApproach/matplotrecorder"] + path = PathPlanning/DynamicWindowApproach/matplotrecorder + url = https://github.com/AtsushiSakai/matplotrecorder diff --git a/PathPlanning/DynamicWindowApproach/animation.gif b/PathPlanning/DynamicWindowApproach/animation.gif new file mode 100644 index 00000000..47b6b2d1 Binary files /dev/null and b/PathPlanning/DynamicWindowApproach/animation.gif differ diff --git a/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py b/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py index 2afa904f..8a698630 100644 --- a/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py +++ b/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py @@ -9,6 +9,8 @@ author: Atsushi Sakai (@Atsushi_twi) import math import numpy as np import matplotlib.pyplot as plt +from matplotrecorder import matplotrecorder +matplotrecorder.donothing = False class Config(): @@ -19,13 +21,12 @@ class Config(): self.max_speed = 1.0 # [m/s] self.min_speed = -0.5 # [m/s] self.max_yawrate = 40.0 * math.pi / 180.0 # [rad/s] - self.max_accel = 0.3 # [m/ss] - self.max_dyawrate = 20.0 * math.pi / 180.0 # [rad/ss] + self.max_accel = 0.2 # [m/ss] + self.max_dyawrate = 40.0 * math.pi / 180.0 # [rad/ss] self.v_reso = 0.01 # [m/s] self.yawrate_reso = 0.1 * math.pi / 180.0 # [rad/s] - self.dt = 0.1 # [s] - self.predict_time = 2.0 # [s] + self.predict_time = 3.0 # [s] self.to_goal_cost_gain = 1.0 self.speed_cost_gain = 1.0 self.robot_radius = 1.0 # [m] @@ -115,7 +116,10 @@ def calc_final_input(x, u, dw, config, goal, ob): def calc_obstacle_cost(traj, ob, config): # calc obstacle cost inf: collistion, 0:free - for ii in range(0, len(traj[:, 1]), 1): + skip_n = 2 + minr = float("inf") + + for ii in range(0, len(traj[:, 1]), skip_n): for i in range(len(ob[:, 0])): ox = ob[i, 0] oy = ob[i, 1] @@ -126,7 +130,10 @@ def calc_obstacle_cost(traj, ob, config): if r <= config.robot_radius: return float("Inf") # collisiton - return 0.0 # OK + if minr >= r: + minr = r + + return 1.0 / minr # OK def calc_to_goal_cost(traj, goal, config): @@ -194,6 +201,7 @@ def main(): plt.axis("equal") plt.grid(True) plt.pause(0.0001) + matplotrecorder.save_frame() # check goal if math.sqrt((x[0] - goal[0])**2 + (x[1] - goal[1])**2) <= config.robot_radius: @@ -202,6 +210,8 @@ def main(): print("Done") plt.plot(traj[:, 0], traj[:, 1], "-r") + matplotrecorder.save_frame() + matplotrecorder.save_movie("animation.gif", 0.1) plt.show() diff --git a/PathPlanning/DynamicWindowApproach/matplotrecorder b/PathPlanning/DynamicWindowApproach/matplotrecorder new file mode 160000 index 00000000..adb95ae9 --- /dev/null +++ b/PathPlanning/DynamicWindowApproach/matplotrecorder @@ -0,0 +1 @@ +Subproject commit adb95ae92b0b7384fed7c1b39dd41e3ab86bad78 diff --git a/README.md b/README.md index c5e890c5..f6cea521 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,12 @@ Python sample codes for robotics algorithm. Path planning algorithm. +## Dynamic Window Approach + +This is a 2D navigation sample code with Dynamic Window Approach. + +![2](https://github.com/AtsushiSakai/PythonRobotics/blob/master/PathPlanning/DynamicWindowApproach/animation.gif) + ## Grid based search ### Dijkstra algorithm