26
26
27
27
28
28
class PyPlot (Connector ):
29
+ """
30
+ Graphical backend using matplotlib
31
+
32
+ matplotlib is a common and highly portable graphics library for Python,
33
+ but has relatively limited 3D capability.
34
+
35
+ Example:
36
+
37
+ .. code-block:: python
38
+ :linenos:
39
+
40
+ import roboticstoolbox as rtb
41
+
42
+ robot = rtb.models.DH.Panda() # create a robot
43
+
44
+ pyplot = rtb.backend.PyPlot() # create a PyPlot backend
45
+ pyplot.add(robot) # add the robot to the backend
46
+ robot.q = robot.qz # set the robot configuration
47
+ pyplot.step() # update the backend and graphical view
48
+
49
+ .. note:: PyPlot is the default backend, and ``robot.plot(q)`` effectively
50
+ performs lines 7-8 above.
51
+
52
+ """
29
53
30
54
def __init__ (self ):
31
55
@@ -34,10 +58,12 @@ def __init__(self):
34
58
self .ellipses = []
35
59
36
60
def launch (self , name = None , limits = None ):
37
- '''
38
- env = launch() launchs a blank 3D matplotlib figure
61
+ """
62
+ Launch a graphical interface
39
63
40
- '''
64
+ ```env = launch()``` creates a blank 3D matplotlib figure and returns
65
+ a reference to the backend.
66
+ """
41
67
42
68
super ().launch ()
43
69
@@ -82,19 +108,26 @@ def launch(self, name=None, limits=None):
82
108
# TODO still need to finish this, and get Jupyter animation working
83
109
84
110
def step (self , dt = 50 ):
85
- '''
86
- state = step(args) triggers the external program to make a time step
87
- of defined time updating the state of the environment as defined by
88
- the robot's actions.
111
+ """
112
+ Update the graphical scene
89
113
90
- The will go through each robot in the list and make them act based on
91
- their control type (position, velocity, acceleration, or torque). Upon
92
- acting, the other three of the four control types will be updated in
93
- the internal state of the robot object. The control type is defined
94
- by the robot object, and not all robot objects support all control
95
- types.
114
+ :param dt: time step in milliseconds, defaults to 50
115
+ :type dt: int, optional
116
+
117
+ ``env.step(args)`` triggers an update of the 3D scene in the matplotlib
118
+ window referenced by ``env``.
96
119
97
- '''
120
+ .. note::
121
+
122
+ - Each robot in the scene is updated based on
123
+ their control type (position, velocity, acceleration, or torque).
124
+ - Upon acting, the other three of the four control types will be
125
+ updated in the internal state of the robot object.
126
+ - The control type is defined by the robot object, and not all robot
127
+ objects support all control types.
128
+ - Execution is blocked for the specified interval
129
+
130
+ """
98
131
99
132
super ().step ()
100
133
@@ -111,28 +144,36 @@ def step(self, dt=50):
111
144
self ._update_robots ()
112
145
113
146
def reset (self ):
114
- '''
115
- state = reset() triggers the external program to reset to the
116
- original state defined by launch
147
+ """
148
+ Reset the graphical scene
117
149
118
- '''
150
+ ``env.reset()`` triggers a reset of the 3D scene in the matplotlib
151
+ window referenced by ``env``. It is restored to the original state
152
+ defined by ``launch()``.
153
+ """
154
+ # TODO what does this actually do for matplotlib??
119
155
120
156
super ().reset ()
121
157
122
158
def restart (self ):
123
- '''
124
- state = restart() triggers the external program to close and relaunch
125
- to thestate defined by launch
159
+ """
160
+ Restart the graphics display
161
+
162
+ ``env.restart()`` triggers a restart of the matplotlib view referenced
163
+ by ``env``. It is closed and relaunched to the original state defined by
164
+ ``launch()``.
126
165
127
- '''
166
+ """
167
+ # TODO what does this actually do for matplotlib??
128
168
129
169
super ().restart ()
130
170
131
171
def close (self ):
132
- '''
133
- close() closes the plot
134
-
135
- '''
172
+ """
173
+ ``env.close()`` gracefully closes the matplotlib window
174
+ referenced by ``env``.
175
+ """
176
+ # TODO what does this actually do for matplotlib??
136
177
137
178
super ().close ()
138
179
@@ -146,12 +187,37 @@ def close(self):
146
187
def add (
147
188
self , ob , readonly = False , display = True ,
148
189
jointaxes = True , eeframe = True , shadow = True , name = True ):
149
- '''
150
- id = add(robot) adds the robot to the external environment. robot must
151
- be of an appropriate class. This adds a robot object to a list of
152
- robots which will act upon the step() method being called.
153
-
154
- '''
190
+ """
191
+ Add a robot to the graphical scene
192
+
193
+ :param ob: [description]
194
+ :type ob: [type]
195
+ :param readonly: [description], defaults to False
196
+ :type readonly: bool, optional
197
+ :param display: [description], defaults to True
198
+ :type display: bool, optional
199
+ :param jointaxes: [description], defaults to True
200
+ :type jointaxes: bool, optional
201
+ :param eeframe: [description], defaults to True
202
+ :type eeframe: bool, optional
203
+ :param shadow: [description], defaults to True
204
+ :type shadow: bool, optional
205
+ :param name: [description], defaults to True
206
+ :type name: bool, optional
207
+
208
+ ``id = env.add(robot)`` adds the ``robot`` to the graphical environment.
209
+
210
+ .. note::
211
+
212
+ - ``robot`` must be of an appropriate class.
213
+ - Adds the robot object to a list of robots which will be updated
214
+ when the ``step()`` method is called.
215
+
216
+ """
217
+ # TODO please fill in the options
218
+ # TODO it seems that add has different args for every backend, are
219
+ # any common ones? If yes, they should be in the superclass and we
220
+ # pass kwargs to that
155
221
156
222
super ().add ()
157
223
@@ -170,10 +236,23 @@ def add(
170
236
self ._set_axes_equal ()
171
237
172
238
def remove (self ):
173
- '''
174
- id = remove(robot) removes the robot to the external environment.
175
-
176
- '''
239
+ """
240
+ Remove a robot to the graphical scene
241
+
242
+ :param id: The id of the robot to remove. Can be either the DHLink or
243
+ GraphicalRobot
244
+ :type id: class:`~roboticstoolbox.robot.DHRobot.DHRobot`,
245
+ class:`roboticstoolbox.backend.VPython.graphics_robot.GraphicalRobot`
246
+ :param fig_num: The canvas index to delete the robot from, defaults to
247
+ the initial one
248
+ :type fig_num: int, optional
249
+ :raises ValueError: Figure number must be between 0 and total number
250
+ of canvases
251
+ :raises TypeError: Input must be a DHLink or GraphicalRobot
252
+
253
+ ``env.remove(robot)`` removes the ``robot`` from the graphical environment.
254
+ """
255
+ # TODO should be an id to remove?
177
256
178
257
super ().remove ()
179
258
@@ -232,13 +311,13 @@ def _plot_handler(self, sig, frame):
232
311
pass
233
312
234
313
def _set_axes_equal (self ):
235
- '''
314
+ """
236
315
Make axes of 3D plot have equal scale so that spheres appear as
237
316
spheres, cubes as cubes, etc.. This is one possible solution to
238
317
Matplotlib's ax.set_aspect('equal') and ax.axis('equal') not
239
318
working for 3D.
240
319
241
- '''
320
+ """
242
321
243
322
if self .limits is not None :
244
323
return
0 commit comments