@@ -47,8 +47,6 @@ def __init__(self):
47
47
self .obstacle_cost_gain = 1.0
48
48
self .robot_radius = 1.0 # [m] for collision check
49
49
50
-
51
-
52
50
def motion (x , u , dt ):
53
51
"""
54
52
motion model
@@ -138,24 +136,14 @@ def calc_obstacle_cost(traj, ob, config):
138
136
"""
139
137
calc obstacle cost inf: collision
140
138
"""
141
-
142
- skip_n = 2 # for speed up
143
- minr = float ("inf" )
144
-
145
- for ii in range (0 , len (traj [:, 1 ]), skip_n ):
146
- for i in range (len (ob [:, 0 ])):
147
- ox = ob [i , 0 ]
148
- oy = ob [i , 1 ]
149
- dx = traj [ii , 0 ] - ox
150
- dy = traj [ii , 1 ] - oy
151
-
152
- r = math .sqrt (dx ** 2 + dy ** 2 )
153
- if r <= config .robot_radius :
154
- return float ("Inf" ) # collision
155
-
156
- if minr >= r :
157
- minr = r
158
-
139
+ ox = ob [:, 0 ]
140
+ oy = ob [:, 1 ]
141
+ dx = traj [:, 0 ] - ox [:, None ]
142
+ dy = traj [:, 1 ] - oy [:, None ]
143
+ r = np .sqrt (np .square (dx ) + np .square (dy ))
144
+ if (r <= config .robot_radius ).any ():
145
+ return float ("Inf" )
146
+ minr = np .min (r )
159
147
return 1.0 / minr # OK
160
148
161
149
@@ -178,7 +166,7 @@ def plot_arrow(x, y, yaw, length=0.5, width=0.1): # pragma: no cover
178
166
plt .plot (x , y )
179
167
180
168
181
- def main (gx = 10 , gy = 10 ):
169
+ def main (gx = 10.0 , gy = 10.0 ):
182
170
print (__file__ + " start!!" )
183
171
# initial state [x(m), y(m), yaw(rad), v(m/s), omega(rad/s)]
184
172
x = np .array ([0.0 , 0.0 , math .pi / 8.0 , 0.0 , 0.0 ])
@@ -194,7 +182,12 @@ def main(gx=10, gy=10):
194
182
[5.0 , 9.0 ],
195
183
[8.0 , 9.0 ],
196
184
[7.0 , 9.0 ],
197
- [12.0 , 12.0 ]
185
+ [8.0 , 10.0 ],
186
+ [9.0 , 11.0 ],
187
+ [12.0 , 13.0 ],
188
+ [12.0 , 12.0 ],
189
+ [15.0 , 15.0 ],
190
+ [13.0 , 13.0 ]
198
191
])
199
192
200
193
# input [forward speed, yawrate]
@@ -204,7 +197,6 @@ def main(gx=10, gy=10):
204
197
205
198
while True :
206
199
u , ptraj = dwa_control (x , u , config , goal , ob )
207
-
208
200
x = motion (x , u , config .dt ) # simulate robot
209
201
traj = np .vstack ((traj , x )) # store state history
210
202
0 commit comments