Skip to content

Commit a54074c

Browse files
authored
Merge pull request #44 from guilyx/feature/bidir-rrt-star
Feature: Bidirectional RRT* Path Planning
2 parents e08db27 + 8d569b6 commit a54074c

File tree

8 files changed

+618
-0
lines changed

8 files changed

+618
-0
lines changed

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+
* [Bidirectional RRT*](#bidirectional-rrt)
3031
* [RRT*](#rrt-star)
3132
* [Informed RRT*](#informed-rrt)
3233
* [Path Tracking](#path-tracking)
@@ -131,6 +132,11 @@ Planning
131132
![](src/simulations/path_planning/rrt_path_planning/rrt_search.gif)
132133
Navigation
133134
![](src/simulations/path_planning/rrt_path_planning/rrt_navigate.gif)
135+
#### Bidirectional RRT*
136+
Planning
137+
![](src/simulations/path_planning/rrt_star_bidirectional_path_planning/rrt_star_bidirectional_search.gif)
138+
Navigation
139+
![](src/simulations/path_planning/rrt_star_bidirectional_path_planning/rrt_star_bidirectional_navigate.gif)
134140
#### RRT*
135141
Planning
136142
![](src/simulations/path_planning/rrt_star_path_planning/rrt_star_search.gif)

src/components/plan/rrt_star_bidirectional/rrt_star_bidirectional_path_planner.py

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

src/simulations/path_planning/rrt_star_bidirectional_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], [3.306675098631942, -0.42947535541010623], [7.266890562011799, 0.7147543450073774], [11.45225925964133, 2.0049339764105047], [15.736776709072611, 1.820070331204639], [19.775857525204184, 2.8949775462759386], [23.628310262708975, 4.727371914446149], [26.68249838720731, 7.440849834320994], [30.129719004771033, 7.025608977845063], [32.249532731013176, 10.252281275576141], [34.708565711401114, 11.561115630367935], [38.42381732000173, 12.119439651270069], [42.328816945798835, 12.051681155695906], [45.12052411757108, 9.787285018594513], [43.63043184179346, 6.038420987999425], [44.44838919898779, 3.0431468916922384], [45.577856385209074, -1.0057366238705423], [46.87286792250144, -4.321069039069234], [46.48665294279576, -8.045120952334871], [50, -10]]
2.62 MB
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
rrt_star_bidirectional_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_bidirectional")
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_bidirectional_path_planner import RrtStarBidirectionalPathPlanner
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_bidirectional_path_planning/rrt_star_bidirectional_navigate.gif"
56+
map_path = abs_dir_path + relative_simulations + "path_planning/rrt_star_bidirectional_path_planning/map.json"
57+
path_filename = abs_dir_path + relative_simulations + "path_planning/rrt_star_bidirectional_path_planning/path.json"
58+
search_gif_path = abs_dir_path + relative_simulations + "path_planning/rrt_star_bidirectional_path_planning/rrt_star_bidirectional_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 = RrtStarBidirectionalPathPlanner((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()
3.54 MB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Test of Bidirectional 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(str(Path(__file__).absolute().parent) + "/../src/simulations/path_planning/rrt_star_bidirectional_path_planning")
12+
import rrt_star_bidirectional_path_planning
13+
14+
15+
def test_simulation():
16+
rrt_star_bidirectional_path_planning.show_plot = False
17+
18+
rrt_star_bidirectional_path_planning.main()

0 commit comments

Comments
 (0)