4
4
5
5
author: Atsushi Sakai (@Atsushi_twi)
6
6
7
+ Ref:
8
+ https://www.cs.cmu.edu/~motionplanning/lecture/Chap4-Potential-Field_howie.pdf
9
+
7
10
"""
8
11
9
12
import numpy as np
12
15
# Parameters
13
16
KP = 5.0 # attractive potential gain
14
17
ETA = 100.0 # repulsive potential gain
15
- AREA_WIDTH = 70 .0 # potential area width [m]
18
+ AREA_WIDTH = 30 .0 # potential area width [m]
16
19
17
20
show_animation = True
18
21
@@ -84,11 +87,19 @@ def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
84
87
85
88
# calc potential field
86
89
pmap , minx , miny = calc_potential_field (gx , gy , ox , oy , reso , rr )
90
+ draw_heatmap (pmap )
87
91
88
92
# search path
89
93
d = np .hypot (sx - gx , sy - gy )
90
94
ix = round ((sx - minx ) / reso )
91
95
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
+
92
103
rx , ry = [sx ], [sy ]
93
104
motion = get_motion_model ()
94
105
while d >= reso :
@@ -110,20 +121,25 @@ def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
110
121
xp = ix * reso + minx
111
122
yp = iy * reso + miny
112
123
d = np .hypot (gx - xp , gy - yp )
124
+ rx .append (xp )
125
+ ry .append (yp )
113
126
114
127
if show_animation :
115
- plt .plot (rx , ry , "- r" )
128
+ plt .plot (ix , iy , ". r" )
116
129
plt .pause (0.01 )
117
130
118
- rx .append (xp )
119
- ry .append (yp )
120
-
121
131
print ("Goal!!" )
122
132
123
133
return rx , ry
124
134
125
135
136
+ def draw_heatmap (data ):
137
+ data = np .array (data ).T
138
+ plt .pcolor (data , vmax = 100.0 , cmap = plt .cm .Blues )
139
+
140
+
126
141
def main ():
142
+ print ("potential_field_planning start" )
127
143
128
144
sx = 0.0 # start x position [m]
129
145
sy = 10.0 # start y positon [m]
@@ -136,9 +152,6 @@ def main():
136
152
oy = [25.0 , 15.0 , 26.0 , 25.0 ] # obstacle y position list [m]
137
153
138
154
if show_animation :
139
- plt .plot (ox , oy , "ok" )
140
- plt .plot (sx , sy , "*c" )
141
- plt .plot (gx , gy , "*c" )
142
155
plt .grid (True )
143
156
plt .axis ("equal" )
144
157
@@ -147,7 +160,6 @@ def main():
147
160
sx , sy , gx , gy , ox , oy , grid_size , robot_radius )
148
161
149
162
if show_animation :
150
- plt .plot (rx , ry , "-r" )
151
163
plt .show ()
152
164
153
165
0 commit comments