Skip to content

Commit e1d7bf2

Browse files
committed
update README
1 parent 35b2142 commit e1d7bf2

File tree

5 files changed

+128
-9
lines changed

5 files changed

+128
-9
lines changed

.idea/preferred-vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
52.1 KB
Loading
59.4 KB
Loading

PathPlanning/StateLatticePlanner/state_lattice_planner.py

Lines changed: 116 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def generate_path(states, k0):
6060

6161
def calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max):
6262
"""
63-
6463
calc uniform state
6564
6665
:param np: number of position sampling
@@ -70,32 +69,90 @@ def calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max):
7069
:param a_max: position sampling max angle
7170
:param p_min: heading sampling min angle
7271
:param p_max: heading sampling max angle
73-
:return:
72+
:return: states list
7473
"""
7574
states = []
7675

7776
for i in range(np):
7877
a = a_min + (a_max - a_min) * i / (np - 1)
79-
print(a)
8078
for j in range(nh):
8179
xf = d * math.cos(a)
8280
yf = d * math.sin(a)
83-
yawf = p_min + (p_max - p_min) * j / (nh - 1) + a
81+
if nh == 1:
82+
yawf = (p_max - p_min) / 2 + a
83+
else:
84+
yawf = p_min + (p_max - p_min) * j / (nh - 1) + a
85+
8486
states.append([xf, yf, yawf])
8587

8688
return states
8789

8890

91+
def calc_biased_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max):
92+
"""
93+
calc biased state
94+
95+
:param goal_angle: goal orientation for biased sampling
96+
:param ns: number of biased sampling
97+
:param nxy: number of position sampling
98+
:param nxy: number of position sampling
99+
:param nh: number of heading sampleing
100+
:param d: distance of terminal state
101+
:param a_min: position sampling min angle
102+
:param a_max: position sampling max angle
103+
:param p_min: heading sampling min angle
104+
:param p_max: heading sampling max angle
105+
:return: states list
106+
"""
107+
108+
cnav = []
109+
for i in range(ns - 1):
110+
asi = a_min + (a_max - a_min) * i / (ns - 1)
111+
cnavi = math.pi - abs(asi - goal_angle)
112+
cnav.append(cnavi)
113+
114+
cnav_sum = sum(cnav)
115+
cnav_max = max(cnav)
116+
117+
# normalize
118+
for i in range(ns - 1):
119+
cnav[i] = (cnav_max - cnav[i]) / (cnav_max * ns - cnav_sum)
120+
121+
csumnav = np.cumsum(cnav)
122+
di = []
123+
for i in range(nxy):
124+
for ii in range(ns - 1):
125+
if ii / ns >= i / (nxy - 1):
126+
di.append(csumnav[ii])
127+
break
128+
129+
states = []
130+
for i in di:
131+
a = a_min + (a_max - a_min) * i
132+
133+
for j in range(nh):
134+
xf = d * math.cos(a)
135+
yf = d * math.sin(a)
136+
if nh == 1:
137+
yawf = (p_max - p_min) / 2 + a
138+
else:
139+
yawf = p_min + (p_max - p_min) * j / (nh - 1) + a
140+
states.append([xf, yf, yawf])
141+
142+
return states
143+
144+
145+
89146
def uniform_terminal_state_sampling1():
90147
k0 = 0.0
91-
np = 5
148+
nxy = 5
92149
nh = 3
93150
d = 20
94151
a_min = - math.radians(45.0)
95152
a_max = math.radians(45.0)
96153
p_min = - math.radians(45.0)
97154
p_max = math.radians(45.0)
98-
states = calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max)
155+
states = calc_uniform_states(nxy, nh, d, a_min, a_max, p_min, p_max)
99156
result = generate_path(states, k0)
100157

101158
for table in result:
@@ -112,14 +169,14 @@ def uniform_terminal_state_sampling1():
112169

113170
def uniform_terminal_state_sampling2():
114171
k0 = 0.1
115-
np = 6
172+
nxy = 6
116173
nh = 3
117174
d = 20
118175
a_min = - math.radians(-10.0)
119176
a_max = math.radians(45.0)
120177
p_min = - math.radians(20.0)
121178
p_max = math.radians(20.0)
122-
states = calc_uniform_states(np, nh, d, a_min, a_max, p_min, p_max)
179+
states = calc_uniform_states(nxy, nh, d, a_min, a_max, p_min, p_max)
123180
result = generate_path(states, k0)
124181

125182
for table in result:
@@ -134,10 +191,60 @@ def uniform_terminal_state_sampling2():
134191
print("Done")
135192

136193

194+
def biased_terminal_state_sampling1():
195+
k0 = 0.0
196+
nxy = 30
197+
nh = 2
198+
d = 20
199+
a_min = math.radians(-45.0)
200+
a_max = math.radians(45.0)
201+
p_min = - math.radians(20.0)
202+
p_max = math.radians(20.0)
203+
ns = 100
204+
goal_angle = math.radians(0.0)
205+
states = calc_biased_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
206+
result = generate_path(states, k0)
207+
208+
for table in result:
209+
xc, yc, yawc = motion_model.generate_trajectory(
210+
table[3], table[4], table[5], k0)
211+
plt.plot(xc, yc, "-r")
212+
213+
plt.grid(True)
214+
plt.axis("equal")
215+
plt.show()
216+
217+
218+
def biased_terminal_state_sampling2():
219+
k0 = 0.0
220+
nxy = 30
221+
nh = 1
222+
d = 20
223+
a_min = math.radians(0.0)
224+
a_max = math.radians(45.0)
225+
p_min = - math.radians(20.0)
226+
p_max = math.radians(20.0)
227+
ns = 100
228+
goal_angle = math.radians(30.0)
229+
states = calc_biased_states(goal_angle, ns, nxy, nh, d, a_min, a_max, p_min, p_max)
230+
result = generate_path(states, k0)
231+
232+
for table in result:
233+
xc, yc, yawc = motion_model.generate_trajectory(
234+
table[3], table[4], table[5], k0)
235+
plt.plot(xc, yc, "-r")
236+
237+
plt.grid(True)
238+
plt.axis("equal")
239+
plt.show()
240+
241+
137242

138243
def main():
139244
# uniform_terminal_state_sampling1()
140-
uniform_terminal_state_sampling2()
245+
# uniform_terminal_state_sampling2()
246+
# biased_terminal_state_sampling1()
247+
biased_terminal_state_sampling2()
141248

142249

143250
if __name__ == '__main__':

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ This code uses the model predictive trajectory generator to solve boundary probl
4646

4747
![PythonRobotics/figure_1.png at master · AtsushiSakai/PythonRobotics](https://github.com/AtsushiSakai/PythonRobotics/blob/master/PathPlanning/StateLatticePlanner/Figure_2.png)
4848

49+
### Biased polar sampling results:
50+
51+
![PythonRobotics/figure_1.png at master · AtsushiSakai/PythonRobotics](https://github.com/AtsushiSakai/PythonRobotics/blob/master/PathPlanning/StateLatticePlanner/Figure_3.png)
52+
53+
![PythonRobotics/figure_1.png at master · AtsushiSakai/PythonRobotics](https://github.com/AtsushiSakai/PythonRobotics/blob/master/PathPlanning/StateLatticePlanner/Figure_4.png)
54+
4955

5056

5157
## RRT

0 commit comments

Comments
 (0)