PyPlot (matplotlib)
- class roboticstoolbox.backends.PyPlot.PyPlot[source]
Bases:
Connector
Graphical backend using matplotlib
matplotlib is a common and highly portable graphics library for Python, but has relatively limited 3D capability.
Example:
1import roboticstoolbox as rtb 2 3robot = rtb.models.DH.Panda() # create a robot 4 5pyplot = rtb.backends.PyPlot() # create a PyPlot backend 6pyplot.add(robot) # add the robot to the backend 7robot.q = robot.qz # set the robot configuration 8pyplot.step() # update the backend and graphical view
Note
PyPlot is the default backend, and
robot.plot(q)
effectively performs lines 7-8 above.- launch(name=None, fig=None, limits=None, **kwargs)[source]
Launch a graphical interface
`env = launch()`
creates a blank 3D matplotlib figure and returns a reference to the backend.
- step(dt=0.05)[source]
Update the graphical scene
- Parameters:
dt (int, optional) – time step in seconds, defaults to 50 (0.05 s)
env.step(args)
triggers an update of the 3D scene in the matplotlib window referenced byenv
.Note
Each robot in the scene is updated based on their control type (position, velocity, acceleration, or torque).
Upon acting, the other three of the four control types will be updated in the internal state of the robot object.
The control type is defined by the robot object, and not all robot objects support all control types.
Execution is blocked for the specified interval
- reset()[source]
Reset the graphical scene
env.reset()
triggers a reset of the 3D scene in the matplotlib window referenced byenv
. It is restored to the original state defined bylaunch()
.
- restart()[source]
Restart the graphics display
env.restart()
triggers a restart of the matplotlib view referenced byenv
. It is closed and relaunched to the original state defined bylaunch()
.
- add(ob, readonly=False, display=True, jointaxes=True, jointlabels=False, eeframe=True, shadow=True, name=True, options=None)[source]
Add a robot to the graphical scene
- Parameters:
ob (DHRobot or EllipsePlot) – The object to add to the plot (robot or ellipse)
readonly (bool, optional) – Do not update the state of the object (i.e. display not simulate), defaults to False
display (bool, optional) – Display the object, defaults to True
jointaxes (bool, optional) – Show the joint axes of the robot with arrows, defaults to True
eeframe (bool, optional) – Show the end-effector frame of the robot, defaults to True
shadow (bool, optional) – Display a shadow of the robot on the x-y gound plane, defaults to True
name (bool, optional) – Display the name of the robot, defaults to True
id = env.add(robot)
adds therobot
to the graphicalenvironment.
Note
robot
must be of an appropriate class.Adds the robot object to a list of robots which will be updated when the
step()
method is called.
- remove(id)[source]
Remove a robot or shape from the graphical scene
- Parameters:
- Raises:
ValueError – Figure number must be between 0 and total number of canvases
TypeError – Input must be a DHLink or GraphicalRobot
env.remove(robot)
removes therobot
from the graphicalenvironment.
- class roboticstoolbox.backends.PyPlot.PyPlot2[source]
Bases:
Connector
- launch(name=None, limits=None, **kwargs)[source]
env = launch() launchs a blank 2D matplotlib figure
- step(dt=0.05)[source]
state = step(args) triggers the external program to make a time step of defined time updating the state of the environment as defined by the robot’s actions.
The will go through each robot in the list and make them act based on their control type (position, velocity, acceleration, or torque). Upon acting, the other three of the four control types will be updated in the internal state of the robot object. The control type is defined by the robot object, and not all robot objects support all control types.
- reset()[source]
state = reset() triggers the external program to reset to the original state defined by launch
- restart()[source]
state = restart() triggers the external program to close and relaunch to thestate defined by launch