Skip to content

Backends

micah-huth edited this page Nov 20, 2020 · 9 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. The others require additional installation steps.

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

VPython

This backend displays the robot in 3D in a browser window using Javascript and vpython.

VPython Puma robot

>>> import roboticstoolbox as rtb
>>> env = rtb.backends.VPython()
>>> env.launch()
>>> p560 = rtb.models.DH.Puma560()
>>> env.add(0, 'Puma560', p560)
>>> qt = rp.tools.trajectory.jtraj(puma.qz, puma.qr, 50)
>>> for q in qt.q:
>>>     time.sleep(1/50)  # Optional: Slow down the visual update rate
>>>     env.step(puma, q=q)

VPython Puma robot animation

If you wish to record the scene, it is recommended to slow the robot down and record in a slow rate. Trying to record in high fps can lag and jumble the resulting video.

>>> env.record_start(5)  # Record at 5 fps
>>> for q in qt.q:
>>>     time.sleep(1/5)
>>>     env.step(puma, q=q)
>>> env.record_stop('vpython_video.mp4', save_fps=25)  # Save the resulting file at 25 fps

Swift

This backend displays the robot in a desktop Electron window using three.js.

TODO ADD CODE EXAMPLE AND IMAGE/ANIMATION

Installation

Follow the instructions on the Swift home page.

CopelliaSim (nee VREP)

CopelliaSim is a mature and capable cross-platform robot simulation environment with a free licence to use for education.

TODO ADD CODE EXAMPLE AND IMAGE/ANIMATION

Installation

ADD DETAILS FOR COPSIM, CONFIGURATION

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() 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.

  • add() adds a robot to the external environment. robot must be of an appropriate class. This adds a robot object to a list of robots which will act upon the step() method being called.

  • remove() remove(robot) removes the robot to the external environment.

  • reset() ''' state = 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