1
- from vpython import canvas , color , arrow , compound , keysdown , rate , norm , sqrt , cos , button , menu , checkbox , slider
1
+ from vpython import canvas , color , arrow , compound , keysdown , rate , norm , sqrt , cos , button , menu , checkbox , slider , \
2
+ wtext , degrees
2
3
from graphics .common_functions import *
3
4
from graphics .graphics_grid import GraphicsGrid , create_line , create_segmented_line , create_marker
4
5
from enum import Enum
@@ -59,7 +60,7 @@ def __init__(self, height=360, width=640, title='', caption='', grid=True):
59
60
# List of joint sliders per robot
60
61
self .__teachpanel = [] # 3D, robot -> joint -> options
61
62
self .__teachpanel_sliders = []
62
- self .__idx_qlim_min , self .__idx_qlim_max , self .__idx_theta = 0 , 1 , 2
63
+ self .__idx_qlim_min , self .__idx_qlim_max , self .__idx_theta , self . __idx_text = 0 , 1 , 2 , 3
63
64
# Checkbox states
64
65
self .__grid_visibility = grid
65
66
self .__camera_lock = False
@@ -151,13 +152,19 @@ def add_robot(self, robot):
151
152
self .__robots .append (robot )
152
153
self .__selected_robot = len (self .__robots ) - 1
153
154
154
- num_options = 3
155
+ num_options = 4
155
156
self .__teachpanel .append ([[0 ] * num_options ] * robot .num_joints ) # Add spot for current robot settings
156
157
157
158
# Add robot joint sliders
158
159
i = 0
159
160
for joint in robot .joints :
160
- self .__teachpanel [self .__selected_robot ][i ] = [joint .qlim [0 ], joint .qlim [1 ], joint .theta ]
161
+ if joint .qlim [0 ] == joint .qlim [1 ]:
162
+ self .__teachpanel [self .__selected_robot ][i ] = [joint .qlim [0 ], joint .qlim [1 ],
163
+ joint .theta , None ]
164
+ else :
165
+ string = "{:.2f} rad ({:.2f} deg)" .format (joint .theta , degrees (joint .theta ))
166
+ self .__teachpanel [self .__selected_robot ][i ] = [joint .qlim [0 ], joint .qlim [1 ],
167
+ joint .theta , wtext (text = string )]
161
168
i += 1
162
169
163
170
# Refresh the caption
@@ -451,23 +458,30 @@ def __setup_joint_sliders(self):
451
458
"""
452
459
Display the Teachpanel mode of the UI
453
460
"""
454
- i = 1
461
+ if len (self .__teachpanel ) == 0 :
462
+ self .scene .append_to_caption ("No robots available\n " )
463
+ return
464
+ i = 0
455
465
for joint in self .__teachpanel [self .__selected_robot ]:
456
466
if joint [self .__idx_qlim_min ] == joint [self .__idx_qlim_max ]:
457
467
# If a slider with (effectively) no values, skip it
468
+ i += 1
458
469
continue
459
470
# Add a title
460
471
self .scene .append_to_caption ('Joint {0}:\t ' .format (i ))
461
- i += 1
462
472
# Add the slider, with the correct joint variables
463
473
s = slider (
464
474
bind = self .__joint_slider ,
465
475
min = joint [self .__idx_qlim_min ],
466
476
max = joint [self .__idx_qlim_max ],
467
- value = joint [self .__idx_theta ]
477
+ value = joint [self .__idx_theta ],
478
+ id = i
468
479
)
469
480
self .__teachpanel_sliders .append (s )
481
+ string = "{:.2f} rad ({:.2f} deg)" .format (joint [self .__idx_theta ], degrees (joint [self .__idx_theta ]))
482
+ joint [self .__idx_text ] = wtext (text = string )
470
483
self .scene .append_to_caption ('\n \n ' )
484
+ i += 1
471
485
472
486
#######################################
473
487
# UI CALLBACKS
@@ -593,10 +607,8 @@ def __joint_slider(self, s):
593
607
:param s: The slider object that has been modified
594
608
:type s: class:`slider`
595
609
"""
596
- # Save the values for updating later
597
- for slider_num in range (0 , len (self .__teachpanel_sliders )):
598
- self .__teachpanel [self .__selected_robot ][slider_num ][self .__idx_theta ] = \
599
- self .__teachpanel_sliders [slider_num ].value
610
+ # Save the value
611
+ self .__teachpanel [self .__selected_robot ][s .id ][self .__idx_theta ] = s .value
600
612
601
613
# Get all angles for the robot
602
614
angles = []
@@ -609,6 +621,12 @@ def __joint_slider(self, s):
609
621
# Update joints
610
622
self .__robots [self .__selected_robot ].set_joint_poses (poses )
611
623
624
+ for joint in self .__teachpanel [self .__selected_robot ]:
625
+ if joint [self .__idx_text ] is None :
626
+ continue
627
+ string = "{:.2f} rad ({:.2f} deg)" .format (joint [self .__idx_theta ], degrees (joint [self .__idx_theta ]))
628
+ joint [self .__idx_text ].text = string
629
+
612
630
613
631
class GraphicsCanvas2D :
614
632
"""
@@ -1023,15 +1041,15 @@ def __verify_plot_options(self, options_str):
1023
1041
return [default_line , default_marker , default_colour ]
1024
1042
1025
1043
# If line_style given, join the first two options if applicable (some types have 2 characters)
1026
- for char in range (0 , len (options_split )- 1 ):
1044
+ for char in range (0 , len (options_split ) - 1 ):
1027
1045
# If char is '-' (only leading character in double length option)
1028
1046
if options_split [char ] == '-' and len (options_split ) > 1 :
1029
1047
# If one of the leading characters is valid
1030
- if options_split [char + 1 ] == '-' or options_split [char + 1 ] == '.' :
1048
+ if options_split [char + 1 ] == '-' or options_split [char + 1 ] == '.' :
1031
1049
# Join the two into the first
1032
- options_split [char ] = options_split [char ] + options_split [char + 1 ]
1050
+ options_split [char ] = options_split [char ] + options_split [char + 1 ]
1033
1051
# Shuffle down the rest
1034
- for idx in range (char + 2 , len (options_split )):
1052
+ for idx in range (char + 2 , len (options_split )):
1035
1053
options_split [idx - 1 ] = options_split [idx ]
1036
1054
# Remove duplicate extra
1037
1055
options_split .pop ()
0 commit comments