Skip to content

Commit 97c25e0

Browse files
authored
Merge pull request #43 from guilyx/feature/rrt-starr
Feature: RRT* Path Planning
2 parents 5333ab0 + 7ece5bc commit 97c25e0

8 files changed

Lines changed: 647 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Python sample codes and documents about Autonomous vehicle control algorithm. Th
2727
* [Hybrid A*](#hybrid-a)
2828
* [Dijkstra](#dijkstra)
2929
* [RRT](#rrt)
30+
* [RRT*](#rrt-star)
3031
* [Informed RRT*](#informed-rrt)
3132
* [Path Tracking](#path-tracking)
3233
* [Pure pursuit Path Tracking](#pure-pursuit-path-tracking)
@@ -129,6 +130,11 @@ Planning
129130
![](src/simulations/path_planning/rrt_path_planning/rrt_search.gif)
130131
Navigation
131132
![](src/simulations/path_planning/rrt_path_planning/rrt_navigate.gif)
133+
#### RRT*
134+
Planning
135+
![](src/simulations/path_planning/rrt_star_path_planning/rrt_star_search.gif)
136+
Navigation
137+
![](src/simulations/path_planning/rrt_star_path_planning/rrt_star_navigate.gif)
132138
#### Informed RRT*
133139
Planning
134140
![](src/simulations/path_planning/informed_rrt_star_path_planning/informed_rrt_star_search.gif)

src/components/plan/rrt_star/rrt_star_path_planner.py

Lines changed: 507 additions & 0 deletions
Large diffs are not rendered by default.

src/simulations/path_planning/rrt_star_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], [4.75087218654987, 0.07895810741711168], [9.582869356011766, -1.0506567611604611], [14.114352936818678, 0.6439502740755565], [18.67372261735205, -0.006304262910310179], [21.34144317754782, -2.3197552417594336], [25.846605971495077, -4.388931138778045], [29.950736447698546, -4.04278169288967], [33.86200715713186, -2.499180139597338], [34.4037782089103, 2.249546008168026], [35.537387898648554, 7.175364663221906], [36.955413401808045, 12.982359157562843], [41.1508007268567, 15.033334469141959], [45.32268614027619, 15.769149518629249], [45.605148069872165, 10.080477147028189], [48.10681315024125, 6.434419004985622], [50.769896921715016, 2.5701130714834957], [50.34038694284904, -1.4179024281044705], [50.0881233442712, -5.288258291790932], [50, -10]]
1.95 MB
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
rrt_star_path_planning.py
3+
4+
Author: Auto-generated
5+
"""
6+
7+
# import path setting
8+
import numpy as np
9+
import sys
10+
from pathlib import Path
11+
12+
abs_dir_path = str(Path(__file__).absolute().parent)
13+
relative_path = "/../../../components/"
14+
relative_simulations = "/../../../simulations/"
15+
16+
17+
sys.path.append(abs_dir_path + relative_path + "visualization")
18+
sys.path.append(abs_dir_path + relative_path + "state")
19+
sys.path.append(abs_dir_path + relative_path + "vehicle")
20+
sys.path.append(abs_dir_path + relative_path + "obstacle")
21+
sys.path.append(abs_dir_path + relative_path + "mapping/grid")
22+
sys.path.append(abs_dir_path + relative_path + "course/cubic_spline_course")
23+
sys.path.append(abs_dir_path + relative_path + "control/pure_pursuit")
24+
sys.path.append(abs_dir_path + relative_path + "plan/rrt_star")
25+
26+
27+
# import component modules
28+
from global_xy_visualizer import GlobalXYVisualizer
29+
from min_max import MinMax
30+
from time_parameters import TimeParameters
31+
from vehicle_specification import VehicleSpecification
32+
from state import State
33+
from four_wheels_vehicle import FourWheelsVehicle
34+
from obstacle import Obstacle
35+
from obstacle_list import ObstacleList
36+
from cubic_spline_course import CubicSplineCourse
37+
from pure_pursuit_controller import PurePursuitController
38+
from rrt_star_path_planner import RrtStarPathPlanner
39+
from binary_occupancy_grid import BinaryOccupancyGrid
40+
import json
41+
42+
43+
# flag to show plot figure
44+
# when executed as unit test, this flag is set as false
45+
show_plot = True
46+
47+
48+
def main():
49+
"""
50+
Main process function
51+
"""
52+
53+
# set simulation parameters
54+
x_lim, y_lim = MinMax(-5, 55), MinMax(-20, 25)
55+
navigation_gif_path = abs_dir_path + relative_simulations + "path_planning/rrt_star_path_planning/rrt_star_navigate.gif"
56+
map_path = abs_dir_path + relative_simulations + "path_planning/rrt_star_path_planning/map.json"
57+
path_filename = abs_dir_path + relative_simulations + "path_planning/rrt_star_path_planning/path.json"
58+
search_gif_path = abs_dir_path + relative_simulations + "path_planning/rrt_star_path_planning/rrt_star_search.gif"
59+
60+
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)
63+
64+
obst_list = ObstacleList()
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))
72+
73+
vis.add_object(obst_list)
74+
occ_grid.add_object(obst_list)
75+
occ_grid.save_map()
76+
# Easy Goal = (50,22)
77+
# Hard Goal = (50,-10)
78+
planner = RrtStarPathPlanner((0, 0), (50, -10), map_path, x_lim=x_lim, y_lim=y_lim, path_filename=path_filename, gif_name=search_gif_path,
79+
max_iterations=5000, step_size=0.5, goal_sample_rate=0.05)
80+
81+
# Load sparse path from json file
82+
with open(path_filename, 'r') as f:
83+
sparse_path = json.load(f)
84+
85+
# Extract x and y coordinates
86+
sparse_x = [point[0] for point in sparse_path]
87+
sparse_y = [point[1] for point in sparse_path]
88+
89+
# Use with CubicSplineCourse
90+
course = CubicSplineCourse(sparse_x, sparse_y, 20)
91+
vis.add_object(course)
92+
93+
# create vehicle instance
94+
spec = VehicleSpecification()
95+
pure_pursuit = PurePursuitController(spec, course)
96+
vehicle = FourWheelsVehicle(State(color=spec.color), spec,
97+
controller=pure_pursuit,
98+
show_zoom=False)
99+
100+
vis.add_object(vehicle)
101+
102+
# plot figure is not shown when executed as unit test
103+
if not show_plot: vis.not_show_plot()
104+
105+
# show plot figure
106+
vis.draw()
107+
108+
109+
# execute main process
110+
if __name__ == "__main__":
111+
main()
7.77 MB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Test of RRT* path planning and navigation simulation
3+
4+
Author: Auto-generated
5+
"""
6+
7+
from pathlib import Path
8+
import sys
9+
import pytest
10+
11+
sys.path.append(
12+
str(Path(__file__).absolute().parent)
13+
+ "/../src/simulations/path_planning/rrt_star_path_planning"
14+
)
15+
import rrt_star_path_planning
16+
17+
18+
def test_simulation():
19+
rrt_star_path_planning.show_plot = False
20+
21+
rrt_star_path_planning.main()

0 commit comments

Comments
 (0)