1616 close_localhost_session
1717
1818
19- class VPython (Connector ):
19+ class VPython (Connector ): # pragma nocover
2020 """
2121 Graphical backend using VPython
2222
2323 VPython is a Python API that connects to a JavaScript/WebGL 3D graphics
24- engine in a browser tab. It supports many 3D graphical primitives including
25- meshes, boxes, ellipsoids and lines. It can not render in full color.
24+ engine in a browser tab. It supports many 3D graphical primitives
25+ including meshes, boxes, ellipsoids and lines. It can not render in
26+ full color.
2627
2728 Example:
2829
@@ -41,7 +42,7 @@ class VPython(Connector):
4142 :references:
4243
4344 - https://vpython.org
44-
45+
4546 """
4647 # TODO be able to add ellipsoids (vellipse, fellipse)
4748 # TODO be able add lines (for end-effector paths)
@@ -55,12 +56,15 @@ def __init__(self):
5556
5657 # Init vars
5758 self .canvases = []
58- self .canvas_settings = [] # 2D array of [is_3d, height, width, title, caption, grid] per canvas
59+ # 2D array of [is_3d, height, width, title, caption, grid] per canvas
60+ self .canvas_settings = []
5961 self .robots = []
6062
6163 self ._create_empty_session ()
6264
63- def launch (self , is_3d = True , height = 500 , width = 888 , title = '' , caption = '' , grid = True ):
65+ def launch (
66+ self , is_3d = True , height = 500 , width = 888 ,
67+ title = '' , caption = '' , grid = True ):
6468 """
6569 Launch a graphical backend in a browser tab
6670
@@ -71,13 +75,16 @@ def launch(self, is_3d=True, height=500, width=888, title='', caption='', grid=T
7175
7276 super ().launch ()
7377
74- self .canvas_settings .append ([is_3d , height , width , title , caption , grid ])
78+ self .canvas_settings .append (
79+ [is_3d , height , width , title , caption , grid ])
7580
7681 # Create the canvas with the given information
7782 if is_3d :
78- self .canvases .append (GraphicsCanvas3D (height , width , title , caption , grid ))
83+ self .canvases .append (
84+ GraphicsCanvas3D (height , width , title , caption , grid ))
7985 else :
80- self .canvases .append (GraphicsCanvas2D (height , width , title , caption , grid ))
86+ self .canvases .append (
87+ GraphicsCanvas2D (height , width , title , caption , grid ))
8188
8289 def step (self , id , q = None , fig_num = 0 ):
8390 """
@@ -88,41 +95,44 @@ def step(self, id, q=None, fig_num=0):
8895 :type id: :class:`~roboticstoolbox.robot.DHRobot.DHRobot`,
8996 :class:`roboticstoolbox.backend.VPython.graphics_robot.GraphicalRobot`
9097 :param q: The joint angles/configuration of the robot (Optional, if not
91- supplied will use the stored q values).
92- :type q: float ndarray(n)
93- :param fig_num: The canvas index to delete the robot from, defaults to the
94- initial one
95- :type fig_num: int, optional
98+ supplied will use the stored q values).
99+ :type q: float ndarray(n)
100+ :param fig_num: The canvas index to delete the robot from, defaults to
101+ the initial one
102+ :type fig_num: int, optional
96103 :raises ValueError: Figure number must be between 0 and total number of
97- canvases
104+ canvases
98105 :raises TypeError: Input must be a DHLink or GraphicalRobot
99106
100107 ``env.step(args)`` triggers an update of the 3D scene in the browser
101108 window referenced by ``env``.
102109
103- .. note::
110+ .. note::
104111
105112 - Each robot in the scene is updated based on
106113 their control type (position, velocity, acceleration, or torque).
107114 - Upon acting, the other three of the four control types will be
108- updated in the internal state of the robot object.
109- - The control type is defined by the robot object, and not all robot
110- objects support all control types.
115+ updated in the internal state of the robot object.
116+ - The control type is defined by the robot object, and not all
117+ robot objects support all control types.
111118 - Execution is blocked for the specified interval
112119
113120 """
114121
115122 super ().step ()
116123
117124 if fig_num < 0 or fig_num >= len (self .canvases ):
118- raise ValueError ("Figure number must be between 0 and total number of canvases" )
125+ raise ValueError (
126+ "Figure number must be between 0 and total number of canvases" )
119127
120128 # If DHRobot given
121129 if isinstance (id , r .Robot ):
122130 robot = None
123131 # Find first occurrence of it that is in the correct canvas
124132 for i in range (len (self .robots )):
125- if self .robots [i ].robot is id and self .canvases [fig_num ].is_robot_in_canvas (self .robots [i ]):
133+ if self .robots [i ].robot is id and \
134+ self .canvases [fig_num ].is_robot_in_canvas (
135+ self .robots [i ]):
126136 robot = self .robots [i ]
127137 break
128138 if robot is None :
@@ -138,7 +148,9 @@ def step(self, id, q=None, fig_num=0):
138148 id .set_joint_poses (poses )
139149 # Else
140150 else :
141- raise TypeError ("Input must be a Robot (or subclass) or GraphicalRobot, given {0}" .format (type (id )))
151+ raise TypeError (
152+ "Input must be a Robot (or subclass) or "
153+ "GraphicalRobot, given {0}" .format (type (id )))
142154
143155 def reset (self ):
144156 """
@@ -168,9 +180,13 @@ def reset(self):
168180 for settings in self .canvas_settings :
169181 # Create the canvas with the given information
170182 if settings [0 ]:
171- self .canvases .append (GraphicsCanvas3D (settings [1 ], settings [2 ], settings [3 ], settings [4 ], settings [5 ]))
183+ self .canvases .append (GraphicsCanvas3D (
184+ settings [1 ], settings [2 ], settings [3 ],
185+ settings [4 ], settings [5 ]))
172186 else :
173- self .canvases .append (GraphicsCanvas2D (settings [1 ], settings [2 ], settings [3 ], settings [4 ], settings [5 ]))
187+ self .canvases .append (GraphicsCanvas2D (
188+ settings [1 ], settings [2 ], settings [3 ],
189+ settings [4 ], settings [5 ]))
174190
175191 def restart (self ):
176192 """
@@ -184,16 +200,6 @@ def restart(self):
184200
185201 super ().restart ()
186202
187- # self.close()
188- # self._create_empty_session()
189- # for settings in self.canvas_settings:
190- # # Create the canvas with the given information
191- # if settings[0]:
192- # self.canvases.append(GraphicsCanvas3D(settings[1], settings[2], settings[3], settings[4], settings[5]))
193- # else:
194- # self.canvases.append(GraphicsCanvas2D(settings[1], settings[2], settings[3], settings[4], settings[5]))
195-
196- # Program on close terminates execution, so just run reset
197203 self .reset ()
198204
199205 def close (self ):
@@ -222,21 +228,23 @@ def add(self, fig_num, name, dhrobot):
222228 """
223229 Add a robot to the graphical scene
224230
225- :param fig_num: The canvas number to place the robot in
231+ :param fig_num: The canvas number to place the robot in
226232 :type fig_num: int
227- :param name: The name of the robot
228- :type name: `str`
229- :param dhrobot: The ``DHRobot`` object (if applicable)
230- :type dhrobot: class:`~roboticstoolbox.robot.DHRobot.DHRobot`, None
231- :raises ValueError: Figure number must be between 0 and number of figures created
233+ :param name: The name of the robot
234+ :type name: `str`
235+ :param dhrobot: The ``DHRobot`` object (if applicable)
236+ :type dhrobot: class:`~roboticstoolbox.robot.DHRobot.DHRobot`, None
237+ :raises ValueError: Figure number must be between 0 and number of
238+ figures created
232239 :return: object id within visualizer
233240 :rtype: int
234241
235- ``id = env.add(robot)`` adds the ``robot`` to the graphical environment.
242+ ``id = env.add(robot)`` adds the ``robot`` to the graphical
243+ environment.
236244
237245 .. note::
238246
239- - ``robot`` must be of an appropriate class.
247+ - ``robot`` must be of an appropriate class.
240248 - Adds the robot object to a list of robots which will be updated
241249 when the ``step()`` method is called.
242250
@@ -251,42 +259,48 @@ def add(self, fig_num, name, dhrobot):
251259
252260 # Sanity check input
253261 if fig_num < 0 or fig_num > len (self .canvases ) - 1 :
254- raise ValueError ("Figure number must be between 0 and number of figures created" )
262+ raise ValueError (
263+ "Figure number must be between 0 and number "
264+ "of figures created" )
255265
256266 # Add robot to canvas
257- self .robots .append (GraphicalRobot (self .canvases [fig_num ], name , dhrobot ))
267+ self .robots .append (
268+ GraphicalRobot (self .canvases [fig_num ], name , dhrobot ))
258269 # self.canvases[fig_num].add_robot(self.robots[len(self.robots)-1])
259270
260271 def remove (self , id , fig_num = 0 ):
261272 """
262273 Remove a robot to the graphical scene
263274
264- :param id: The id of the robot to remove. Can be either the DHLink or
275+ :param id: The id of the robot to remove. Can be either the DHLink or
265276 GraphicalRobot
266277 :type id: class:`~roboticstoolbox.robot.DHRobot.DHRobot`,
267278 class:`roboticstoolbox.backend.VPython.graphics_robot.GraphicalRobot`
268279 :param fig_num: The canvas index to delete the robot from, defaults to
269280 the initial one
270281 :type fig_num: int, optional
271- :raises ValueError: Figure number must be between 0 and total number
282+ :raises ValueError: Figure number must be between 0 and total number
272283 of canvases
273284 :raises TypeError: Input must be a DHLink or GraphicalRobot
274285
275- ``env.remove(robot)`` removes the ``robot`` from the graphical environment.
286+ ``env.remove(robot)`` removes the ``robot`` from the graphical
287+ environment.
276288
277289 """
278290
279291 super ().remove ()
280292
281293 if fig_num < 0 or fig_num >= len (self .canvases ):
282- raise ValueError ("Figure number must be between 0 and total number of canvases" )
294+ raise ValueError (
295+ "Figure number must be between 0 and total number of canvases" )
283296
284297 # If DHLink given
285298 if isinstance (id , DHLink ):
286299 robot = None
287300 # Find first occurrence of it that is in the correct canvas
288301 for i in range (len (self .robots )):
289- if self .robots [i ].seriallink .equal (id ) and self .canvases [fig_num ].is_robot_in (self .robots [i ]):
302+ if self .robots [i ].seriallink .equal (id ) and \
303+ self .canvases [fig_num ].is_robot_in (self .robots [i ]):
290304 robot = self .robots [i ]
291305 break
292306 if robot is None :
0 commit comments