@@ -74,12 +74,12 @@ def launch(self, name=None, limits=None):
74
74
self .ax .set_ylabel (labels [1 ])
75
75
76
76
self .ax .autoscale (enable = True , axis = 'both' , tight = False )
77
- self .ax .axis ('equal' )
78
77
79
78
if limits is not None :
80
79
self .ax .set_xlim ([limits [0 ], limits [1 ]])
81
80
self .ax .set_ylim ([limits [2 ], limits [3 ]])
82
81
82
+ self .ax .axis ('equal' )
83
83
84
84
plt .ion ()
85
85
plt .show ()
@@ -159,12 +159,12 @@ def add(
159
159
160
160
super ().add ()
161
161
162
- if isinstance (ob , rp .DHRobot ) or isinstance ( ob , rp . ERobot ):
162
+ if isinstance (ob , rp .ERobot2 ):
163
163
self .robots .append (
164
164
RobotPlot2 (
165
165
ob , self .ax , readonly , display ,
166
166
eeframe , name ))
167
- self .robots [len (self .robots ) - 1 ].draw2 ()
167
+ self .robots [len (self .robots ) - 1 ].draw ()
168
168
169
169
170
170
elif isinstance (ob , EllipsePlot ):
@@ -217,7 +217,7 @@ def _update_robots(self):
217
217
def _draw_robots (self ):
218
218
219
219
for i in range (len (self .robots )):
220
- self .robots [i ].draw2 ()
220
+ self .robots [i ].draw ()
221
221
222
222
def _draw_ellipses (self ):
223
223
@@ -227,24 +227,36 @@ def _draw_ellipses(self):
227
227
# def _plot_handler(self, sig, frame):
228
228
# plt.pause(0.001)
229
229
230
- def _add_teach_panel (self , robot ):
230
+ def _add_teach_panel (self , robot , q ):
231
+ """
232
+ Add a teach panel
233
+
234
+ :param robot: Robot being taught
235
+ :type robot: ERobot class
236
+ :param q: inital joint angles in radians
237
+ :type q: array_like(n)
238
+ """
231
239
fig = self .fig
232
240
233
241
# Add text to the plots
234
- def text_trans (text ): # pragma: no cover
235
- T = robot .fkine ()
242
+ def text_trans (text , q ): # pragma: no cover
243
+ # update displayed robot pose value
244
+ T = robot .fkine (q , end = robot .ee_links [0 ])
236
245
t = np .round (T .t , 3 )
237
- r = np .round (T .rpy (), 3 )
246
+ r = np .round (T .theta (), 3 )
238
247
text [0 ].set_text ("x: {0}" .format (t [0 ]))
239
248
text [1 ].set_text ("y: {0}" .format (t [1 ]))
240
- text [2 ].set_text ("yaw: {0}" .format (r [ 2 ] ))
249
+ text [2 ].set_text ("yaw: {0}" .format (r ))
241
250
242
251
# Update the self state in mpl and the text
243
252
def update (val , text , robot ): # pragma: no cover
244
- for i in range (robot .n ):
245
- robot .q [i ] = self .sjoint [i ].val * np .pi / 180
253
+ for j in range (robot .n ):
254
+ if robot .isrevolute (j ):
255
+ robot .q [j ] = self .sjoint [j ].val * np .pi / 180
256
+ else :
257
+ robot .q [j ] = self .sjoint [j ].val
246
258
247
- text_trans (text )
259
+ text_trans (text , robot . q )
248
260
249
261
# Step the environment
250
262
self .step (0 )
@@ -260,19 +272,23 @@ def update(val, text, robot): # pragma: no cover
260
272
self .axjoint = []
261
273
self .sjoint = []
262
274
263
- qlim = np .copy (robot .qlim ) * 180 / np .pi
264
-
265
- if np .all (qlim == 0 ): # pragma nocover
266
- qlim [0 , :] = - 180
267
- qlim [1 , :] = 180
275
+ qlim = robot .todegrees (robot .qlim )
268
276
269
277
# Set the pose text
270
- T = robot .fkine ()
278
+ # if multiple EE, display only the first one
279
+ T = robot .fkine (q , end = robot .ee_links [0 ])
271
280
t = np .round (T .t , 3 )
272
- r = np .round (T .rpy (), 3 )
281
+ r = np .round (T .theta (), 3 )
273
282
283
+ # TODO maybe put EE name in here, possible issue with DH robot
284
+ # TODO maybe display pose of all EEs, layout hassles though
285
+
286
+ if robot .nbranches == 0 :
287
+ header = "End-effector Pose"
288
+ else :
289
+ header = "End-effector #0 Pose"
274
290
fig .text (
275
- 0.02 , 1 - ym + 0.25 , "End-effector Pose" ,
291
+ 0.02 , 1 - ym + 0.25 , header ,
276
292
fontsize = 9 , weight = "bold" , color = "#4f4f4f" )
277
293
text .append (fig .text (
278
294
0.03 , 1 - ym + 0.20 , "x: {0}" .format (t [0 ]),
@@ -281,20 +297,30 @@ def update(val, text, robot): # pragma: no cover
281
297
0.03 , 1 - ym + 0.16 , "y: {0}" .format (t [1 ]),
282
298
fontsize = 9 , color = "#2b2b2b" ))
283
299
text .append (fig .text (
284
- 0.15 , 1 - ym + 0.20 , "yaw: {0}" .format (r [ 0 ] ),
300
+ 0.15 , 1 - ym + 0.20 , "yaw: {0}" .format (r ),
285
301
fontsize = 9 , color = "#2b2b2b" ))
286
302
fig .text (
287
303
0.02 , 1 - ym + 0.06 , "Joint angles" ,
288
304
fontsize = 9 , weight = "bold" , color = "#4f4f4f" )
289
305
290
- for i in range (robot .n ):
291
- ymin = (1 - ym ) - i * yh
306
+ for j in range (robot .n ):
307
+ # for each joint
308
+ ymin = (1 - ym ) - j * yh
292
309
self .axjoint .append (
293
310
fig .add_axes ([x1 , ymin , x2 , 0.03 ], facecolor = '#dbdbdb' ))
294
311
295
- self .sjoint .append (
296
- Slider (
297
- self .axjoint [i ], 'q' + str (i ),
298
- qlim [0 , i ], qlim [1 , i ], robot .q [i ] * 180 / np .pi , "% .1f°" ))
312
+ if robot .isrevolute (j ):
313
+ slider = Slider (
314
+ self .axjoint [j ], 'q' + str (j ),
315
+ qlim [0 , j ], qlim [1 , j ], q [j ] * 180 / np .pi , "% .1f°" )
316
+ else :
317
+ slider = Slider (
318
+ self .axjoint [j ], 'q' + str (j ),
319
+ qlim [0 , j ], qlim [1 , j ], q [j ], "% .1f" )
299
320
300
- self .sjoint [i ].on_changed (lambda x : update (x , text , robot ))
321
+ slider .on_changed (lambda x : update (x , text , robot ))
322
+ self .sjoint .append (slider )
323
+
324
+
325
+ robot .q = q
326
+ self .step ()
0 commit comments