Skip to content

Commit 67ab7f6

Browse files
committed
fixups for RandomPath
Python style doco workspace
1 parent 134075a commit 67ab7f6

File tree

1 file changed

+9
-53
lines changed

1 file changed

+9
-53
lines changed

roboticstoolbox/mobile/drivers.py

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,7 @@ def __init__(self, dthresh=0.05, seed=0, **kwargs):
176176
veh.control = driver
177177
178178
The waypoints are positioned inside a rectangular region defined by
179-
the vehicle that is specified by (see ``plotvol2``):
180-
181-
============== ======= =======
182-
``workspace`` x-range y-range
183-
============== ======= =======
184-
A (scalar) -A:A -A:A
185-
[A, B] A:B A:B
186-
[A, B, C, D] A:B C:D
187-
============== ======= =======
188-
179+
the `workspace`
189180
190181
.. note::
191182
- It is possible in some cases for the vehicle to move outside the desired
@@ -202,30 +193,14 @@ def __init__(self, dthresh=0.05, seed=0, **kwargs):
202193

203194
# TODO options to specify region, maybe accept a Map object?
204195

205-
if hasattr(workspace, "workspace"):
206-
# workspace can be defined by an object with a workspace attribute
207-
self._workspace = base.expand_dims(workspace.workspace)
208-
else:
209-
self._workspace = base.expand_dims(workspace)
196+
super().__init__(**kwargs)
210197

211-
self._speed = speed
212198
self._dthresh = dthresh * np.diff(self._workspace[0:2])
213199
self._goal_marker = None
214-
if goalmarkerstyle is None:
215-
self._goal_marker_style = {
216-
"marker": "D",
217-
"markersize": 6,
218-
"color": "r",
219-
"linestyle": "None",
220-
}
221-
else:
222-
self._goal_marker_style = goalmarkerstyle
223-
self._headinggain = headinggain
224200

225201
self._d_prev = np.inf
226202
self._random = np.random.default_rng(seed)
227203
self._seed = seed
228-
self.verbose = True
229204
self._goal = None
230205
self._dthresh = dthresh * max(
231206
self._workspace[1] - self._workspace[0],
@@ -235,10 +210,11 @@ def __init__(self, dthresh=0.05, seed=0, **kwargs):
235210
self._veh = None
236211

237212
def __str__(self):
238-
"""%RandomPath.char Convert to string
239-
%
240-
% s = R.char() is a string showing driver parameters and state in in
241-
% a compact human readable format."""
213+
"""Convert to string
214+
215+
:return: driver parameters and state in in a compact human readable format
216+
:rtype: str
217+
"""
242218

243219
s = "RandomPath driver object\n"
244220
s += (
@@ -248,19 +224,6 @@ def __str__(self):
248224
s += f" current goal={self._goal}"
249225
return s
250226

251-
@property
252-
def workspace(self):
253-
"""
254-
Size of robot driving workspace
255-
256-
:return: workspace bounds [xmin, xmax, ymin, ymax]
257-
:rtype: ndarray(4)
258-
259-
Returns the bounds of the workspace as specified by constructor
260-
option ``workspace``
261-
"""
262-
return self._workspace
263-
264227
def init(self, ax=None):
265228
"""
266229
Initialize random path driving agent
@@ -305,14 +268,7 @@ def demand(self):
305268
# self.choose_goal()
306269
self._d_prev = d
307270

308-
speed = self._speed
309-
310-
goal_heading = atan2(
311-
self._goal[1] - self._veh._x[1], self._goal[0] - self._veh._x[0]
312-
)
313-
delta_heading = base.angdiff(goal_heading, self._veh._x[2])
314-
315-
return np.r_[speed, self._headinggain * delta_heading]
271+
return self.driveto(self._goal)
316272

317273
## private method, invoked from demand() to compute a new waypoint
318274

@@ -332,7 +288,7 @@ def _new_goal(self):
332288
if np.linalg.norm(self._goal - self._veh._x[0:2]) > 2 * self._dthresh:
333289
break
334290

335-
if self._veh.verbose:
291+
if self._veh.verbose or self._verbose:
336292
print(f"set goal: {self._goal}")
337293

338294
# update the goal marker

0 commit comments

Comments
 (0)