Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Backends

micah-huth edited this page Apr 16, 2021 · 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. At the moment it only works with models defined using DH notation and requires STL meshes.

>>> import roboticstoolbox as rtb
>>> p560 = rtb.models.DH.Puma560()
>>> env = p560.plot(qt.q, backend='vpython')

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

Swift displays in a web browser table 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)

TODO ADD CODE EXAMPLE AND IMAGE/ANIMATION

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, VPython or Swift

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

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

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

  • getframe() return a PIL image for current frame if possible

TODO

  • tidy up objects that can be added, they should have a common superclass with abstract methods that addables must have
  • teach panel, this is still an underscore function.
  • getframe method. Can we make this work for VPython and Swift? We have too many different ways of recording movies, need to unify
Clone this wiki locally
Morty Proxy This is a proxified and sanitized view of the page, visit original site.