2
2
3
3
Mobile robot motion planning sample with Dynamic Window Approach
4
4
5
- author: Atsushi Sakai (@Atsushi_twi)
5
+ author: Atsushi Sakai (@Atsushi_twi), Goktug Karakasli
6
6
7
7
"""
8
8
9
+ from enum import Enum
9
10
import math
10
11
11
12
import matplotlib .pyplot as plt
@@ -25,6 +26,9 @@ def dwa_control(x, config, goal, ob):
25
26
26
27
return u , trajectory
27
28
29
+ class RobotType (Enum ):
30
+ circle = 0
31
+ rectangle = 1
28
32
29
33
class Config :
30
34
"""
@@ -45,13 +49,13 @@ def __init__(self):
45
49
self .to_goal_cost_gain = 0.15
46
50
self .speed_cost_gain = 1.0
47
51
self .obstacle_cost_gain = 1.0
48
- self .robot_type = ' circle' # circle or rectangle
52
+ self .robot_type = RobotType . circle
49
53
50
- # if robot_type == circle
54
+ # if robot_type == RobotType. circle
51
55
# Also used to check if goal is reached in both types
52
56
self .robot_radius = 1.0 # [m] for collision check
53
57
54
- # if robot_type == rectangle
58
+ # if robot_type == RobotType. rectangle
55
59
self .robot_width = 0.5 # [m] for collision check
56
60
self .robot_length = 1.2 # [m] for collision check
57
61
@@ -150,7 +154,7 @@ def calc_obstacle_cost(trajectory, ob, config):
150
154
dy = trajectory [:, 1 ] - oy [:, None ]
151
155
r = np .sqrt (np .square (dx ) + np .square (dy ))
152
156
153
- if config .robot_type == ' rectangle' :
157
+ if config .robot_type == RobotType . rectangle :
154
158
yaw = trajectory [:, 2 ]
155
159
rot = np .array ([[np .cos (yaw ), - np .sin (yaw )], [np .sin (yaw ), np .cos (yaw )]])
156
160
local_ob = ob [:, None ] - trajectory [:, 0 :2 ]
@@ -164,7 +168,7 @@ def calc_obstacle_cost(trajectory, ob, config):
164
168
if (np .logical_and (np .logical_and (upper_check , right_check ),
165
169
np .logical_and (bottom_check , left_check ))).any ():
166
170
return float ("Inf" )
167
- elif config .robot_type == ' circle' :
171
+ elif config .robot_type == RobotType . circle :
168
172
if (r <= config .robot_radius ).any ():
169
173
return float ("Inf" )
170
174
@@ -192,7 +196,7 @@ def plot_arrow(x, y, yaw, length=0.5, width=0.1): # pragma: no cover
192
196
193
197
194
198
def plot_robot (x , y , yaw , config ): # pragma: no cover
195
- if config .robot_type == ' rectangle' :
199
+ if config .robot_type == RobotType . rectangle :
196
200
outline = np .array ([[- config .robot_length / 2 , config .robot_length / 2 ,
197
201
(config .robot_length / 2 ), - config .robot_length / 2 ,
198
202
- config .robot_length / 2 ],
@@ -206,15 +210,15 @@ def plot_robot(x, y, yaw, config): # pragma: no cover
206
210
outline [1 , :] += y
207
211
plt .plot (np .array (outline [0 , :]).flatten (),
208
212
np .array (outline [1 , :]).flatten (), "-k" )
209
- elif config .robot_type == ' circle' :
213
+ elif config .robot_type == RobotType . circle :
210
214
circle = plt .Circle ((x , y ), config .robot_radius , color = "b" )
211
215
plt .gcf ().gca ().add_artist (circle )
212
216
out_x , out_y = (np .array ([x , y ]) +
213
217
np .array ([np .cos (yaw ), np .sin (yaw )]) * config .robot_radius )
214
218
plt .plot ([x , out_x ], [y , out_y ], "-k" )
215
219
216
220
217
- def main (gx = 10.0 , gy = 10.0 , robot_type = ' circle' ):
221
+ def main (gx = 10.0 , gy = 10.0 , robot_type = RobotType . circle ):
218
222
print (__file__ + " start!!" )
219
223
# initial state [x(m), y(m), yaw(rad), v(m/s), omega(rad/s)]
220
224
x = np .array ([0.0 , 0.0 , math .pi / 8.0 , 0.0 , 0.0 ])
0 commit comments