Mobile robot animations

These classes create a graphical object that can be animated to show vehicle position or pose. They are all subclasses of VehicleAnimation.

Simple marker

class roboticstoolbox.mobile.VehicleMarker(**kwargs)[source]

Bases: roboticstoolbox.mobile.Animations.VehicleAnimationBase

__init__(**kwargs)[source]

Create graphical animation of vehicle as a Matplotlib marker

Parameters

kwargs – additional arguments passed to matplotlib plot.

Returns

animation object

Return type

VehicleAnimation

Creates an object that can be passed to a Vehicle subclass to depict the moving robot as a simple matplotlib marker during simulation.

For example, a blue filled square, is:

a = VehicleMarker(marker='s', markerfacecolor='b')
veh = Bicycle(driver=RandomPath(10), animation=a)
veh.run()

Note

A marker can only indicate vehicle position, not orientation.

Seealso

Vehicle()

add(ax=None, **kwargs)

Add vehicle animation to the current plot

Parameters

ax (Axes, optional) – Axis to add to, defaults to current axis

A reference to the animation object is kept, and it will be deleted from the plot when the VehicleAnimation object is garbage collected.

plot(q, **kwargs)

Add vehicle to the current plot

Parameters

q (ndarray(2) or ndarray(3)) – vehicle configuration

Returns

reference to Matplotlib object

A reference to the animation object is kept, and it will be deleted from the plot when the VehicleAnimation object is garbage collected.

update(q)

Update the vehicle animation

Parameters

q (ndarray(2) or ndarray(3)) – vehicle configuration

The graphical depiction of the vehicle position or pose is updated.

For AnimationMarker only position can be depicted so the third element of q, if given, is ignored.

Polygon shape

class roboticstoolbox.mobile.VehiclePolygon(shape='car', scale=1, **kwargs)[source]

Bases: roboticstoolbox.mobile.Animations.VehicleAnimationBase

__init__(shape='car', scale=1, **kwargs)[source]

Create graphical animation of vehicle as a polygon

Parameters
  • shape (ndarray(2,n) or str) – polygon shape as vertices or a predefined shape, defaults to ‘car’

  • scale (float) – Length of the vehicle on the plot, defaults to 1

  • kwargs – additional arguments passed to matplotlib patch such as color (face+edge), alpha, facecolor, edgecolor, linewidth etc.

Raises
  • ValueError – unknown shape name

  • TypeError – bad shape argument

Returns

animation object

Return type

VehicleAnimation

Creates an object that can be passed to a Vehicle subclass to depict the moving robot as a polygon during simulation.

For example, a red filled car-shaped polygon is:

a = VehiclePolygon('car', color='r')
veh = Bicycle()
veh.run(animation=a)

shape can be:

  • "car" a rectangle with chamfered front corners

  • "triangle" a triangle

  • an Nx2 NumPy array of vertices, does not have to be closed.

The polygon is scaled to an image with a length of scale in the units of the plot.

Seealso

Vehicle()

add(ax=None, **kwargs)

Add vehicle animation to the current plot

Parameters

ax (Axes, optional) – Axis to add to, defaults to current axis

A reference to the animation object is kept, and it will be deleted from the plot when the VehicleAnimation object is garbage collected.

plot(q, **kwargs)

Add vehicle to the current plot

Parameters

q (ndarray(2) or ndarray(3)) – vehicle configuration

Returns

reference to Matplotlib object

A reference to the animation object is kept, and it will be deleted from the plot when the VehicleAnimation object is garbage collected.

update(q)

Update the vehicle animation

Parameters

q (ndarray(2) or ndarray(3)) – vehicle configuration

The graphical depiction of the vehicle position or pose is updated.

For AnimationMarker only position can be depicted so the third element of q, if given, is ignored.

Image icon

class roboticstoolbox.mobile.VehicleIcon(filename, origin=None, scale=1, rotation=0)[source]

Bases: roboticstoolbox.mobile.Animations.VehicleAnimationBase

__init__(filename, origin=None, scale=1, rotation=0)[source]

Create graphical animation of vehicle as an icon

Parameters
  • filename (str) – Standard icon name or a path to an image

  • origin (2-tuple) – Origin of the vehicle coordinate frame, defaults to centre

  • scale (float) – Length of the vehicle on the plot, defaults to 1

  • rotation (float) – Vehicle icon heading in degrees, defaults to 0

Raises

ValueError – Icon file not found

Returns

animation object

Return type

VehicleAnimation

Creates an object that can be passed to a Vehicle subclass to depict the moving robot as a polygon during simulation.

For example, the image of a red car is:

a = VehicleIcon('redcar', scale=2)
veh = Bicycle()
veh.run(animation=a)

filename can be:

  • "greycar" a grey and white car (top view)

  • "redcar" a red car (top view)

  • "piano" a piano (top view)

  • path to an image file, including extension

_images/greycar.png _images/redcar.png ../../rtb-data/rtbdata/data/piano.png

The car is scaled to an image with a length of scale in the units of the plot.

The vehicle rotates about its origin which is expressed in terms of normalized coordinates in the range 0 to 1. By default it is in the middle of the icon image, (0.2, 0.5) moves it toward the back of the vehicle, (0.8, 0.5) moves it toward the front of the vehicle.

Note

  • The standard icons are kept in roboticstoolbox/data

  • By default the image is assumed to contain a car parallel to the x-axis and facing right. If the vehicle is facing upward set rotation to 90.

Seealso

Vehicle()

add(ax=None, **kwargs)

Add vehicle animation to the current plot

Parameters

ax (Axes, optional) – Axis to add to, defaults to current axis

A reference to the animation object is kept, and it will be deleted from the plot when the VehicleAnimation object is garbage collected.

plot(q, **kwargs)

Add vehicle to the current plot

Parameters

q (ndarray(2) or ndarray(3)) – vehicle configuration

Returns

reference to Matplotlib object

A reference to the animation object is kept, and it will be deleted from the plot when the VehicleAnimation object is garbage collected.

update(q)

Update the vehicle animation

Parameters

q (ndarray(2) or ndarray(3)) – vehicle configuration

The graphical depiction of the vehicle position or pose is updated.

For AnimationMarker only position can be depicted so the third element of q, if given, is ignored.