Skip to content

Commit ce50256

Browse files
committed
release potentialfieldplanning
1 parent f3b4d05 commit ce50256

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed
Loading

PathPlanning/PotentialFieldPlanning/potential_field_planning.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
author: Atsushi Sakai (@Atsushi_twi)
66
7+
Ref:
8+
https://www.cs.cmu.edu/~motionplanning/lecture/Chap4-Potential-Field_howie.pdf
9+
710
"""
811

912
import numpy as np
@@ -12,7 +15,7 @@
1215
# Parameters
1316
KP = 5.0 # attractive potential gain
1417
ETA = 100.0 # repulsive potential gain
15-
AREA_WIDTH = 70.0 # potential area width [m]
18+
AREA_WIDTH = 30.0 # potential area width [m]
1619

1720
show_animation = True
1821

@@ -84,11 +87,19 @@ def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
8487

8588
# calc potential field
8689
pmap, minx, miny = calc_potential_field(gx, gy, ox, oy, reso, rr)
90+
draw_heatmap(pmap)
8791

8892
# search path
8993
d = np.hypot(sx - gx, sy - gy)
9094
ix = round((sx - minx) / reso)
9195
iy = round((sy - miny) / reso)
96+
gix = round((gx - minx) / reso)
97+
giy = round((gy - miny) / reso)
98+
99+
if show_animation:
100+
plt.plot(ix, iy, "*k")
101+
plt.plot(gix, giy, "*m")
102+
92103
rx, ry = [sx], [sy]
93104
motion = get_motion_model()
94105
while d >= reso:
@@ -110,20 +121,25 @@ def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
110121
xp = ix * reso + minx
111122
yp = iy * reso + miny
112123
d = np.hypot(gx - xp, gy - yp)
124+
rx.append(xp)
125+
ry.append(yp)
113126

114127
if show_animation:
115-
plt.plot(rx, ry, "-r")
128+
plt.plot(ix, iy, ".r")
116129
plt.pause(0.01)
117130

118-
rx.append(xp)
119-
ry.append(yp)
120-
121131
print("Goal!!")
122132

123133
return rx, ry
124134

125135

136+
def draw_heatmap(data):
137+
data = np.array(data).T
138+
plt.pcolor(data, vmax=100.0, cmap=plt.cm.Blues)
139+
140+
126141
def main():
142+
print("potential_field_planning start")
127143

128144
sx = 0.0 # start x position [m]
129145
sy = 10.0 # start y positon [m]
@@ -136,9 +152,6 @@ def main():
136152
oy = [25.0, 15.0, 26.0, 25.0] # obstacle y position list [m]
137153

138154
if show_animation:
139-
plt.plot(ox, oy, "ok")
140-
plt.plot(sx, sy, "*c")
141-
plt.plot(gx, gy, "*c")
142155
plt.grid(True)
143156
plt.axis("equal")
144157

@@ -147,7 +160,6 @@ def main():
147160
sx, sy, gx, gy, ox, oy, grid_size, robot_radius)
148161

149162
if show_animation:
150-
plt.plot(rx, ry, "-r")
151163
plt.show()
152164

153165

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ It's heuristic is 2D Euclid distance.
105105

106106
## Model Predictive Trajectory Generator
107107

108-
This script is a path planning code with model predictive trajectory generator.
108+
This is a path optimization sample on model predictive trajectory generator.
109+
110+
This algorithm is used for state lattice planner.
109111

110112
### Path optimization sample
111113

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from unittest import TestCase
2+
3+
from PathPlanning.PotentialFieldPlanning import potential_field_planning as m
4+
5+
print(__file__)
6+
7+
8+
class Test(TestCase):
9+
10+
def test1(self):
11+
m.show_animation = False
12+
m.main()

0 commit comments

Comments
 (0)