Skip to content

Commit 1df9765

Browse files
committed
add some simulation results.
1 parent ca8f853 commit 1df9765

File tree

3 files changed

+67
-45
lines changed

3 files changed

+67
-45
lines changed
58.1 KB
Loading

PathPlanning/StateLatticePlanner/state_lattice_planner.py

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
"""
2-
State lattice planner
2+
State lattice planner with model predictive trajectory generator
33
44
author: Atsushi Sakai
55
"""
66
from matplotlib import pyplot as plt
77
import numpy as np
88
import math
9+
import pandas as pd
910
import model_predictive_trajectory_generator as planner
1011
import motion_model
11-
import pandas as pd
12-
13-
14-
def calc_states_list():
15-
maxyaw = math.radians(-30.0)
16-
17-
x = np.arange(1.0, 30.0, 5.0)
18-
y = np.arange(0.0, 20.0, 2.0)
19-
yaw = np.arange(-maxyaw, maxyaw, maxyaw)
20-
21-
states = []
22-
for iyaw in yaw:
23-
for iy in y:
24-
for ix in x:
25-
states.append([ix, iy, iyaw])
26-
# print(len(states))
27-
28-
return states
2912

3013

3114
def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookuptable):
@@ -42,19 +25,16 @@ def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookuptable):
4225
minid = i
4326
mind = d
4427

45-
4628
return lookuptable[minid]
4729

4830

4931
def get_lookup_table():
50-
5132
data = pd.read_csv("lookuptable.csv")
5233

5334
return np.array(data)
5435

5536

5637
def generate_path(states, k0):
57-
5838
# x, y, yaw, s, km, kf
5939
lookup_table = get_lookup_table()
6040
result = []
@@ -78,47 +58,73 @@ def generate_path(states, k0):
7858
return result
7959

8060

61+
def calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max):
62+
"""
8163
82-
def calc_uniform_states():
83-
np = 5
84-
nh = 3
85-
d = 20
86-
a_min = - math.radians(45.0)
87-
a_max = math.radians(45.0)
88-
p_min = - math.radians(45.0)
89-
p_max = math.radians(45.0)
90-
x0 = 0.0
91-
y0 = 0.0
92-
yaw0 = 0.0
64+
calc uniform state
9365
66+
:param np: number of position sampling
67+
:param nh: number of heading sampleing
68+
:param d: distance of terminal state
69+
:param a_min: position sampling min angle
70+
:param a_max: position sampling max angle
71+
:param p_min: heading sampling min angle
72+
:param p_max: heading sampling max angle
73+
:return:
74+
"""
9475
states = []
9576

9677
for i in range(np):
78+
a = a_min + (a_max - a_min) * i / (np - 1)
79+
print(a)
9780
for j in range(nh):
98-
n = i * nh + j
99-
a = a_min + (a_max - a_min) * i / (np - 1)
100-
xf = x0 + d * math.cos(a + yaw0)
101-
yf = y0 + d * math.sin(a + yaw0)
102-
yawf = yaw0+p_min+(p_max-p_min)*j/(nh-1)+a
81+
xf = d * math.cos(a)
82+
yf = d * math.sin(a)
83+
yawf = p_min + (p_max - p_min) * j / (nh - 1) + a
10384
states.append([xf, yf, yawf])
10485

105-
# print(states)
106-
# print(len(states))
107-
10886
return states
10987

11088

111-
def uniform_terminal_state_sampling():
89+
def uniform_terminal_state_sampling1():
11290
k0 = 0.0
113-
states = calc_uniform_states()
91+
np = 5
92+
nh = 3
93+
d = 20
94+
a_min = - math.radians(45.0)
95+
a_max = math.radians(45.0)
96+
p_min = - math.radians(45.0)
97+
p_max = math.radians(45.0)
98+
states = calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max)
11499
result = generate_path(states, k0)
115100

116101
for table in result:
117102
xc, yc, yawc = motion_model.generate_trajectory(
118103
table[3], table[4], table[5], k0)
119104
plt.plot(xc, yc, "-r")
105+
106+
plt.grid(True)
107+
plt.axis("equal")
108+
plt.show()
109+
110+
print("Done")
111+
112+
113+
def uniform_terminal_state_sampling2():
114+
k0 = 0.1
115+
np = 6
116+
nh = 3
117+
d = 20
118+
a_min = - math.radians(-10.0)
119+
a_max = math.radians(45.0)
120+
p_min = - math.radians(20.0)
121+
p_max = math.radians(20.0)
122+
states = calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max)
123+
result = generate_path(states, k0)
124+
125+
for table in result:
120126
xc, yc, yawc = motion_model.generate_trajectory(
121-
table[3], -table[4], -table[5], k0)
127+
table[3], table[4], table[5], k0)
122128
plt.plot(xc, yc, "-r")
123129

124130
plt.grid(True)
@@ -130,7 +136,8 @@ def uniform_terminal_state_sampling():
130136

131137

132138
def main():
133-
uniform_terminal_state_sampling()
139+
# uniform_terminal_state_sampling1()
140+
uniform_terminal_state_sampling2()
134141

135142

136143
if __name__ == '__main__':

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ Lookup table generation sample:
3131
see:
3232
- [Optimal rough terrain trajectory generation for wheeled mobile robots](http://journals.sagepub.com/doi/pdf/10.1177/0278364906075328)
3333

34+
# State Lattice Planning
35+
36+
This script is a path planning code with state lattice planning.
37+
38+
This code uses the model predictive trajectory generator to solve boundary problem.
39+
40+
41+
Uniform polar sampling results:
42+
43+
![PythonRobotics/figure_1.png at master · AtsushiSakai/PythonRobotics](https://github.com/AtsushiSakai/PythonRobotics/blob/master/PathPlanning/StateLatticePlanner/Figure_1.png)
44+
45+
![PythonRobotics/figure_1.png at master · AtsushiSakai/PythonRobotics](https://github.com/AtsushiSakai/PythonRobotics/blob/master/PathPlanning/StateLatticePlanner/Figure_2.png)
46+
47+
48+
3449
## RRT
3550

3651
Rapidly Randamized Tree Path planning sample.

0 commit comments

Comments
 (0)