25
25
26
26
27
27
class RRTPlanner (PlannerBase ):
28
- """
28
+ r """
29
29
Rapidly exploring tree planner
30
30
31
31
:param map: occupancy grid
@@ -36,8 +36,6 @@ class RRTPlanner(PlannerBase):
36
36
:type curvature: float, optional
37
37
:param stepsize: spacing between points on the path, defaults to 0.2
38
38
:type stepsize: float, optional
39
- :param showsamples: shows vehicle polygons for all random samples, defaults to False
40
- :type showsamples: bool, optional
41
39
:param npoints: number of vertices in random tree, defaults to 50
42
40
:type npoints: int, optional
43
41
@@ -102,16 +100,13 @@ def __init__(
102
100
vehicle ,
103
101
curvature = 1.0 ,
104
102
stepsize = 0.2 ,
105
- showsamples = False ,
106
103
npoints = 50 ,
107
104
** kwargs ,
108
105
):
109
-
110
106
super ().__init__ (ndims = 2 , ** kwargs )
111
107
112
108
self .npoints = npoints
113
109
self .map = map
114
- self .showsamples = showsamples
115
110
116
111
self .g = DGraph (metric = "SE2" )
117
112
@@ -128,12 +123,18 @@ def __init__(
128
123
# self.goal_yaw_th = np.deg2rad(1.0)
129
124
# self.goal_xy_th = 0.5
130
125
131
- def plan (self , goal , animate = True , search_until_npoints = True ):
126
+ def plan (self , goal , showsamples = True , showvalid = True , animate = False ):
132
127
r"""
133
128
Plan paths to goal using RRT
134
129
135
130
:param goal: goal pose :math:`(x, y, \theta)`, defaults to previously set value
136
131
:type goal: array_like(3), optional
132
+ :param showsamples: display position part of configurations overlaid on the map, defaults to True
133
+ :type showsamples: bool, optional
134
+ :param showvalid: display valid configurations as vehicle polygons overlaid on the map, defaults to False
135
+ :type showvalid: bool, optional
136
+ :param animate: update the display as configurations are tested, defaults to False
137
+ :type animate: bool, optional
137
138
138
139
Compute a rapidly exploring random tree with its root at the ``goal``.
139
140
The tree will have ``npoints`` vertices spread uniformly randomly over
@@ -143,6 +144,11 @@ def plan(self, goal, animate=True, search_until_npoints=True):
143
144
vertex already in the graph. Each configuration on that path, with
144
145
spacing of ``stepsize``, is tested for obstacle intersection.
145
146
147
+ The configurations tested are displayed (translation only) if ``showsamples`` is
148
+ True. The valid configurations are displayed as vehicle polygones if ``showvalid``
149
+ is True. If ``animate`` is True these points are displayed during the search
150
+ process, otherwise a single figure is displayed at the end.
151
+
146
152
:seealso: :meth:`query`
147
153
"""
148
154
# TODO use validate
@@ -153,14 +159,18 @@ def plan(self, goal, animate=True, search_until_npoints=True):
153
159
v = self .g .add_vertex (coord = goal )
154
160
v .path = None
155
161
162
+ if showsamples or showvalid :
163
+ self .map .plot ()
164
+
156
165
self .progress_start (self .npoints )
157
166
count = 0
158
167
while count < self .npoints :
159
-
160
168
random_point = self .qrandom_free ()
161
169
162
- if self . showsamples :
170
+ if showsamples :
163
171
plt .plot (random_point [0 ], random_point [1 ], "ok" , markersize = 2 )
172
+ if animate :
173
+ plt .pause (0.02 )
164
174
165
175
vnearest , d = self .g .closest (random_point )
166
176
@@ -192,8 +202,13 @@ def plan(self, goal, animate=True, search_until_npoints=True):
192
202
self .g .add_edge (vnew , vnearest , cost = pstatus .length )
193
203
vnew .path = path
194
204
195
- self .vehicle .polygon (random_point ).plot (color = "b" , alpha = 0.1 )
196
- plt .show ()
205
+ if showvalid :
206
+ self .vehicle .polygon (random_point ).plot (color = "b" , alpha = 0.1 )
207
+ if animate :
208
+ plt .pause (0.02 )
209
+
210
+ if (showvalid or showsamples ) and not animate :
211
+ plt .show (block = False )
197
212
198
213
self .progress_end ()
199
214
@@ -307,7 +322,6 @@ def iscollision(self, q):
307
322
308
323
309
324
if __name__ == "__main__" :
310
-
311
325
from roboticstoolbox .mobile .Vehicle import Bicycle
312
326
313
327
# start and goal configuration
0 commit comments