Skip to content

Backends

Peter Corke edited this page Sep 15, 2026 · 11 revisions

The Toolbox supports a number of backends to display a robot animation or to control a physical robot.

Available backends

By default, only the PyPlot backend is included in the Toolbox install. Swift requires the swift optional extra (pip install roboticstoolbox-python[swift]).

PyPlot (matplotlib)

This backend displays the robot as a noodle using matplotlib graphics. matplotlib is the most ubiquitous graphics library for Python and runs on all platforms.

>>> import roboticstoolbox as rtb
>>> p560 = rtb.models.DH.Puma560()
>>> qt = rtb.tools.trajectory.jtraj(p560.qz, p560.qr, 50)
>>> p560.plot(qt.q)

Puma robot animation

Options exist to:

  • attach a velocity or force ellipsoid,
  • display link frames and joint axes,
  • save the animation to a file as an animated GIF

Swift

Swift displays in a web browser tab using three.js. At the moment it only works with models defined using URDF and can use STL or Collada meshes.

>>> import roboticstoolbox as rtb
>>> p560 = rtb.models.URDF.Puma560()
>>> qt = rtb.tools.trajectory.jtraj(p560.qz, p560.qr, 50)
>>> p560.plot(qt.q)

See docs/source/intro.rst for a worked Panda example and a rendered screenshot.

Installation

pip install roboticstoolbox-python[swift], or follow the instructions on the Swift home page to install the bleeding-edge version from GitHub.

CoppeliaSim (nee VREP)

CoppeliaSim is a mature and capable cross-platform robot simulation environment with a free licence to use for education. There is currently no Connector backend for it in roboticstoolbox/backends/ — see issue #675 if you'd like to write one against the Connector API below.

Using the backend

The simplest way is using plot with a backend option as shown above. The alternative is to create a backend environment

from roboticstoolbox.backends.BACKEND import BACKEND
env = BACKEND()

# where BACKEND is PyPlot or Swift

env.launch()  # start the backend
env.add(robot)  # add a robot to the backend

for ...:
    robot.q = some value
    env.step()

Backend API

The backend supports a simple API defined in backends/Connector.py

  • launch() launch the external program with an empty or specific scene as defined by args

  • step(dt) requests the external program to make a time step of defined time updating the state of the environment, including all robots, as defined by the robot's actions.

  • id = add(object) adds an object to the external environment. If object is a robot, it must be of an appropriate class. This adds the object to a list of which will act upon the step() method being called. This method returns the id of the object.

  • remove(id) removes the specified object from the external environment.

  • reset() triggers the external program to reset to the original state defined by launch

  • restart() request the external program to close and relaunch to the state defined by launch

  • close() requests that the external program to gracefully close

  • hold() requests that the external program stays open, will prevent Python from exiting the script. Is blocking

TODO

Backend API cleanup ideas (common superclass for addable objects, promoting teach out of underscore-function status, a cross-backend getframe()) are tracked in issue #676 rather than here.

Clone this wiki locally