Drivers
These classes define agents that can drive a mobile robot around a workspace, and are useful for testing localization algorithms.
Random Path
- class RandomPath(dthresh=0.05, seed=0, **kwargs)[source]
Bases:
VehicleDriverBaseDriving agent for a random path
- __init__(dthresh=0.05, seed=0, **kwargs)[source]
Driving agent for random path
- Parameters:
dthresh (
float) – distance threshold as a fraction of the larger workspace dimension, defaults to 0.05seed (
int|None) – random number seed, defaults to 0, None for a random seedkwargs (
Any) – arguments passed toVehicleDriverBase, in particularworkspacewhich is required
- Raises:
ValueError – no workspace specified
Returns a driver object that drives the attached vehicle to a sequence of random waypoints.
The driver is connected to the vehicle by:
veh = Bicycle(control=driver)
or:
veh = Bicycle() veh.control = driver
The waypoints are positioned inside a rectangular region defined by the
workspace, which must be given:driver = RandomPath(workspace=10)
Note
It is possible in some cases for the vehicle to move outside the desired region, for instance if moving to a waypoint near the edge, the limited turning circle may cause the vehicle to temporarily move outside.
The vehicle chooses a new waypoint when it is closer than
dthreshtimes the larger workspace dimension to the current waypoint.Uses its own random number generator so as to not influence the performance of other randomized algorithms such as path planning. Set
seed=Noneto have it randomly initialized from the operating system.
See also
BicycleUnicycleplotvol2()
- __str__()[source]
Convert to string
- Return type:
- Returns:
driver parameters and state in a compact human readable format
- init(ax=None)[source]
Initialize random path driving agent
- Parameters:
ax (
Axes|None) – axes in which to draw the current goal, defaults to None- Return type:
Called at the start of a simulation run. Ensures that the random number generator is reseeded so that the sequence of random waypoints is repeatable.
- demand()[source]
Compute speed and steering angle for the current random waypoint
- Return type:
- Returns:
speed and steering angle demand for
VehicleBase
This is the speed and steering angle that drives the vehicle toward the current waypoint. When the vehicle is within
dthreshtimes the larger workspace dimension of the waypoint, a new random waypoint is chosen.See also
VehicleBase
- __repr__()
Convert to string, same as
__str__()- Return type:
- Returns:
driver parameters and state in a compact human readable format
- driveto(goal)
Speed and steering demand to drive towards a goal point
- Parameters:
goal (
Union[List[float],Tuple[float,float],ndarray[Tuple[Literal[2]],dtype[floating]]]) – goal point (x, y)- Return type:
- Returns:
speed and steering angle demand
The speed demand is the constant
speed. The steering angle demand is the heading error to the goal, \(\Delta\theta\), scaled byheadinggain.If the goal marker is displayed, it is moved to the goal.
- property vehicle: VehicleBase | None
Set/get the vehicle under control
- Getter:
return the
VehicleBaseinstance, or None- Setter:
set the
VehicleBaseinstance
Note
The setter is invoked by
vehicle.control = driver- Setter accepts:
- property workspace: ndarray | None
Size of robot driving workspace
- Returns:
workspace bounds [xmin, xmax, ymin, ymax], or None
- Return type:
ndarray(4) or None
Returns the bounds of the workspace as specified by constructor option
workspaceor, if that was not given, the workspace of the vehicle that the driver is attached to. None if neither has one.
Pure Pursuit
- class PurePursuit(path, lookahead=1, path_style=None, **kwargs)[source]
Bases:
VehicleDriverBaseDriving agent for pure pursuit
- __init__(path, lookahead=1, path_style=None, **kwargs)[source]
Driving agent for pure pursuit
- Parameters:
path (
NDArray) – path as a set of waypoints, one column per pointlookahead (
float) – lookahead distance, defaults to 1path_style (
dict[str,Any] |None) – Matplotlib line style used to display the path, merged over the defaultPATH_STYLE(a wide, translucent red line)kwargs (
Any) – arguments passed toVehicleDriverBase
- Raises:
ValueError –
pathis not a 2xN array
Returns a driver object that drives the attached vehicle along the path using the pure pursuit algorithm: the vehicle steers toward the first point on the path that is at least
lookaheadaway from the vehicle, beyond the closest point.The driver is connected to the vehicle by:
veh = Bicycle(control=driver)
or:
veh = Bicycle() veh.control = driver
If the simulation is animated, the path is plotted using
path_styleand the current goal point, which changes at every time step, is shown usinggoal_style.See also
RandomPathVehicleBase
- __str__()[source]
Convert to string
- Return type:
- Returns:
driver parameters and state in a compact human readable format
- init(ax=None)[source]
Initialize pure pursuit driving agent
- Parameters:
ax (
Axes|None) – axes in which to draw the path and waypoints, defaults to None- Return type:
Called at the start of a simulation run. If
axis given, plot the path and create the goal marker.
- demand()[source]
Compute speed and steering angle to follow the path
- Return type:
- Returns:
speed and steering angle demand for
VehicleBase
The goal is the first point on the path, beyond the point closest to the vehicle, that is at least
lookaheadaway from the vehicle. If there is no such point the goal is the end of the path.
- __repr__()
Convert to string, same as
__str__()- Return type:
- Returns:
driver parameters and state in a compact human readable format
- driveto(goal)
Speed and steering demand to drive towards a goal point
- Parameters:
goal (
Union[List[float],Tuple[float,float],ndarray[Tuple[Literal[2]],dtype[floating]]]) – goal point (x, y)- Return type:
- Returns:
speed and steering angle demand
The speed demand is the constant
speed. The steering angle demand is the heading error to the goal, \(\Delta\theta\), scaled byheadinggain.If the goal marker is displayed, it is moved to the goal.
- property vehicle: VehicleBase | None
Set/get the vehicle under control
- Getter:
return the
VehicleBaseinstance, or None- Setter:
set the
VehicleBaseinstance
Note
The setter is invoked by
vehicle.control = driver- Setter accepts:
- property workspace: ndarray | None
Size of robot driving workspace
- Returns:
workspace bounds [xmin, xmax, ymin, ymax], or None
- Return type:
ndarray(4) or None
Returns the bounds of the workspace as specified by constructor option
workspaceor, if that was not given, the workspace of the vehicle that the driver is attached to. None if neither has one.
Superclass
- class VehicleDriverBase(workspace=None, speed=1, headinggain=0.3, goal_style=None, verbose=False, goalmarkerstyle=None)[source]
Bases:
ABCAbstract vehicle driver class
Abstract class for an agent that can drive a mobile robot.
See also
- __init__(workspace=None, speed=1, headinggain=0.3, goal_style=None, verbose=False, goalmarkerstyle=None)[source]
Abstract vehicle driver
- Parameters:
workspace (
Union[float,ndarray,Sequence[float],HasWorkspace,None]) – dimension of workspace, seespatialmath.base.graphics.expand_dims(), defaults to Nonespeed (
float) – forward speed, defaults to 1headinggain (
float) – gain of the proportional controller that steers the vehicle towards the current goal, defaults to 0.3goal_style (
dict[str,Any] |None) – Matplotlib line style of the marker used to display the current goal, merged over the defaultGOAL_STYLE(a red diamond)verbose (
bool) – display debug information, defaults to Falsegoalmarkerstyle (
dict[str,Any] |None) – deprecated, usegoal_style
Deprecated since version 1.5.0:
goalmarkerstyleis deprecated, usegoal_styleinstead.The workspace of the robot is a rectangular region defined by
workspacethat is specified by (seeplotvol2()):workspacex-range
y-range
A (scalar)
-A:A
-A:A
[A, B]
A:B
A:B
[A, B, C, D]
A:B
C:D
- abstractmethod demand()[source]
Compute speed and steering angle
- Return type:
- Returns:
speed and steering angle demand for
VehicleBase
When an instance of a
VehicleDriverBaseclass is attached as the control for an instance of aVehicleBaseclass, this method is called at each time step to provide the control input.Has access to the vehicle and its state through the
vehicle()property.
- abstractmethod init(ax=None)[source]
Initialize driving agent
Called at the start of a simulation run. Used to initialize state including random number generator state.
- property vehicle: VehicleBase | None
Set/get the vehicle under control
- Getter:
return the
VehicleBaseinstance, or None- Setter:
set the
VehicleBaseinstance
Note
The setter is invoked by
vehicle.control = driver- Setter accepts:
- __repr__()[source]
Convert to string, same as
__str__()- Return type:
- Returns:
driver parameters and state in a compact human readable format
- property workspace: ndarray | None
Size of robot driving workspace
- Returns:
workspace bounds [xmin, xmax, ymin, ymax], or None
- Return type:
ndarray(4) or None
Returns the bounds of the workspace as specified by constructor option
workspaceor, if that was not given, the workspace of the vehicle that the driver is attached to. None if neither has one.
- driveto(goal)[source]
Speed and steering demand to drive towards a goal point
- Parameters:
goal (
Union[List[float],Tuple[float,float],ndarray[Tuple[Literal[2]],dtype[floating]]]) – goal point (x, y)- Return type:
- Returns:
speed and steering angle demand
The speed demand is the constant
speed. The steering angle demand is the heading error to the goal, \(\Delta\theta\), scaled byheadinggain.If the goal marker is displayed, it is moved to the goal.