Skip to content

Commit a07cbd3

Browse files
authored
Merge pull request #38 from Palamanickam0806/rrt_path_planning
rrt path planning algorithm
2 parents 2984e1f + 0616ae3 commit a07cbd3

8 files changed

Lines changed: 541 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7098,3 +7098,4 @@ __pycache__
70987098
.venv/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl
70997099
.venv/share/python-wheels/webencodings-0.5.1-py2.py3-none-any.whl
71007100
.venv/share/python-wheels/wheel-0.34.2-py2.py3-none-any.whl
7101+
.vscode/

src/components/plan/rrt/rrt_path_planner.py

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

src/simulations/path_planning/rrt_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.653604726991527, -0.3069193482143218], [9.308085271322161, -0.621448790726503], [13.399959986759717, 0.7869486899441993], [18.216905792229884, 0.22190827834104482], [21.35044077424777, -2.302664336350134], [24.67774179300573, -4.601488021668669], [29.584184813919446, -4.389205021123191], [33.6923759578744, -3.740362509028831], [36.09416006667666, -1.0473590046996233], [33.92497913721241, 2.2270499885152284], [35.843000517065626, 6.007109716507263], [35.67058203354173, 9.98031077869816], [39.067352218559435, 12.412638156746326], [42.8433452245675, 12.3976922443666], [46.090624978894844, 9.213270986173129], [48.10511036141835, 4.9405372754510815], [48.16924620001407, 0.3902405031486628], [48.821109642260396, -4.461920188781559], [50, -10]]
1.76 MB
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
astar_path_planning.py
3+
4+
Author: Shantanu Parab
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")
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_path_planner import RrtPathPlanner
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_path_planning/rrt_navigate.gif"
56+
map_path = abs_dir_path + relative_simulations + "path_planning/rrt_path_planning/map.json"
57+
path_filename = abs_dir_path + relative_simulations + "path_planning/rrt_path_planning/path.json"
58+
search_gif_path = abs_dir_path + relative_simulations + "path_planning/rrt_path_planning/rrt_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 = RrtPathPlanner((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()
11.1 MB
Loading

test/test_rrt_path_planning.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Test of A* path planning and navigation simulation
3+
4+
Author: Shisato Yano
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_path_planning")
12+
import rrt_path_planning
13+
14+
15+
def test_simulation():
16+
rrt_path_planning.show_plot = False
17+
18+
rrt_path_planning.main()

0 commit comments

Comments
 (0)