Skip to content

Commit a9d8f51

Browse files
Astar Path Simulation Implementation
1 parent 22a6b47 commit a9d8f51

5 files changed

Lines changed: 27 additions & 35 deletions

File tree

1.03 MB
Loading

src/simulations/path_planning/astar_path_planning/astart_path_planning.py renamed to src/simulations/path_planning/astar_path_planning/astar_path_planning.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
ndt_map_construction.py
2+
astar_path_planning.py
33
4-
Author: Shisato Yano
4+
Author: Shantanu Parab
55
"""
66

77
# import path setting
@@ -18,9 +18,7 @@
1818
sys.path.append(abs_dir_path + relative_path + "state")
1919
sys.path.append(abs_dir_path + relative_path + "vehicle")
2020
sys.path.append(abs_dir_path + relative_path + "obstacle")
21-
sys.path.append(abs_dir_path + relative_path + "sensors")
22-
sys.path.append(abs_dir_path + relative_path + "sensors/lidar")
23-
sys.path.append(abs_dir_path + relative_path + "mapping/ndt")
21+
sys.path.append(abs_dir_path + relative_path + "mapping/grid")
2422
sys.path.append(abs_dir_path + relative_path + "course/cubic_spline_course")
2523
sys.path.append(abs_dir_path + relative_path + "control/pure_pursuit")
2624
sys.path.append(abs_dir_path + relative_path + "plan/astar")
@@ -35,13 +33,11 @@
3533
from four_wheels_vehicle import FourWheelsVehicle
3634
from obstacle import Obstacle
3735
from obstacle_list import ObstacleList
38-
from sensors import Sensors
39-
from sensor_parameters import SensorParameters
40-
from omni_directional_lidar import OmniDirectionalLidar
41-
from ndt_global_mapper import NdtGlobalMapper
4236
from cubic_spline_course import CubicSplineCourse
4337
from pure_pursuit_controller import PurePursuitController
4438
from astar_path_planner import AStarPathPlanner
39+
from binary_occupancy_grid import BinaryOccupancyGrid
40+
import json
4541

4642

4743
# flag to show plot figure
@@ -56,46 +52,39 @@ def main():
5652

5753
# set simulation parameters
5854
x_lim, y_lim = MinMax(-5, 55), MinMax(-20, 25)
59-
vis = GlobalXYVisualizer(x_lim, y_lim, TimeParameters(span_sec=25), show_zoom=False)
55+
navigation_gif_path = abs_dir_path + relative_simulations + "path_planning/astar_path_planning/astar_navigate.gif"
56+
map_path = abs_dir_path + relative_simulations + "path_planning/astar_path_planning/map.json"
57+
path_filename = abs_dir_path + relative_simulations + "path_planning/astar_path_planning/path.json"
58+
search_gif_path = abs_dir_path + relative_simulations + "path_planning/astar_path_planning/astar_search.gif"
6059

61-
6260

63-
obstacle_parameters = [
64-
{"x_m": 10.0, "y_m": 15.0, "yaw_rad": 0.0, "length_m": 10.0, "width_m": 8.0},
65-
{"x_m": 40.0, "y_m": 0.0, "yaw_rad": 0.0, "length_m": 2.0, "width_m": 10.0},
66-
{"x_m": 10.0, "y_m": -10.0, "yaw_rad": np.rad2deg(45), "length_m": 5.0, "width_m": 5.0},
67-
{"x_m": 30.0, "y_m": 15.0, "yaw_rad": np.rad2deg(10), "length_m": 5.0, "width_m": 2.0},
68-
{"x_m": 50.0, "y_m": 15.0, "yaw_rad": np.rad2deg(15), "length_m": 5.0, "width_m": 2.0},
69-
{"x_m": 25.0, "y_m": 0.0, "yaw_rad": 0.0, "length_m": 2.0, "width_m": 2.0},
70-
{"x_m": 35.0, "y_m": -15.0, "yaw_rad": 0.0, "length_m": 7.0, "width_m": 2.0}
71-
]
61+
vis = GlobalXYVisualizer(x_lim, y_lim, TimeParameters(span_sec=25), show_zoom=False, gif_name=navigation_gif_path)
62+
occ_grid = BinaryOccupancyGrid(x_lim, y_lim, resolution=0.5, clearance=1.5, map_path=map_path)
7263

73-
# create obstacle instances
7464
obst_list = ObstacleList()
75-
76-
for params in obstacle_parameters:
77-
obstacle = Obstacle(
78-
State(x_m=params["x_m"], y_m=params["y_m"], yaw_rad=params["yaw_rad"]),
79-
length_m=params["length_m"],
80-
width_m=params["width_m"]
81-
)
82-
obst_list.add_obstacle(obstacle)
65+
obst_list.add_obstacle(Obstacle(State(x_m=10.0, y_m=15.0), length_m=10, width_m=8))
66+
obst_list.add_obstacle(Obstacle(State(x_m=40.0, y_m=0.0), length_m=2, width_m=10))
67+
# obst_list.add_obstacle(Obstacle(State(x_m=10.0, y_m=-10.0, yaw_rad=np.rad2deg(45)), length_m=5, width_m=5))
68+
# obst_list.add_obstacle(Obstacle(State(x_m=30.0, y_m=15.0, yaw_rad=np.rad2deg(10)), length_m=5, width_m=2))
69+
# obst_list.add_obstacle(Obstacle(State(x_m=50.0, y_m=15.0, yaw_rad=np.rad2deg(15)), length_m=5, width_m=2))
70+
# obst_list.add_obstacle(Obstacle(State(x_m=25.0, y_m=0.0), length_m=2, width_m=2))
71+
# obst_list.add_obstacle(Obstacle(State(x_m=35.0, y_m=-15.0), length_m=7, width_m=2))
8372

8473
vis.add_object(obst_list)
74+
occ_grid.add_object(obst_list)
75+
occ_grid.save_map()
8576
# Easy Goal = (50,22)
8677
# Hard Goal = (50,-10)
87-
planner = AStarPathPlanner((0, 0), (50, -10), obstacle_parameters, resolution=0.5, weight=5.0, obstacle_clearance = 1.5, visualize=True, x_lim=x_lim, y_lim=y_lim)
88-
path = planner.search()
89-
gif_path = abs_dir_path + relative_simulations + "path_planning/astar_path_planning/astar_search.gif"
90-
planner.visualize_search(path, gif_name=gif_path)
78+
planner = AStarPathPlanner((0, 0), (50, -10), map_path, weight=5.0, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path)
9179

92-
sparse_path = planner.make_sparse_path(path, num_points=20)
80+
# Load sparse path from json file
81+
with open(path_filename, 'r') as f:
82+
sparse_path = json.load(f)
9383

9484
# Extract x and y coordinates
9585
sparse_x = [point[0] for point in sparse_path]
9686
sparse_y = [point[1] for point in sparse_path]
9787

98-
print(sparse_x)
9988
# Use with CubicSplineCourse
10089
course = CubicSplineCourse(sparse_x, sparse_y, 20)
10190
vis.add_object(course)
@@ -106,6 +95,7 @@ def main():
10695
vehicle = FourWheelsVehicle(State(color=spec.color), spec,
10796
controller=pure_pursuit,
10897
show_zoom=False)
98+
10999
vis.add_object(vehicle)
110100

111101
# plot figure is not shown when executed as unit test
-679 KB
Loading

src/simulations/path_planning/astar_path_planning/map.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[[0.0, 0.0], [2.5, -2.5], [5.0, -5.0], [7.5, -7.5], [10.5, -10.0], [13.0, -10.0], [15.5, -10.0], [18.0, -10.0], [21.0, -10.0], [23.5, -10.0], [26.0, -10.0], [28.5, -10.0], [31.5, -10.0], [34.0, -10.0], [36.5, -12.0], [39.0, -12.0], [42.0, -12.0], [44.5, -10.5], [47.0, -10.0], [50.0, -10.0]]

0 commit comments

Comments
 (0)