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
@@ -454,23 +461,27 @@ def __setup_joint_sliders(self):
454
461
if len (self .__teachpanel ) == 0 :
455
462
self .scene .append_to_caption ("No robots available\n " )
456
463
return
457
- i = 1
464
+ i = 0
458
465
for joint in self .__teachpanel [self .__selected_robot ]:
459
466
if joint [self .__idx_qlim_min ] == joint [self .__idx_qlim_max ]:
460
467
# If a slider with (effectively) no values, skip it
468
+ i += 1
461
469
continue
462
470
# Add a title
463
471
self .scene .append_to_caption ('Joint {0}:\t ' .format (i ))
464
- i += 1
465
472
# Add the slider, with the correct joint variables
466
473
s = slider (
467
474
bind = self .__joint_slider ,
468
475
min = joint [self .__idx_qlim_min ],
469
476
max = joint [self .__idx_qlim_max ],
470
- value = joint [self .__idx_theta ]
477
+ value = joint [self .__idx_theta ],
478
+ id = i
471
479
)
472
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 )
473
483
self .scene .append_to_caption ('\n \n ' )
484
+ i += 1
474
485
475
486
#######################################
476
487
# UI CALLBACKS
@@ -596,10 +607,8 @@ def __joint_slider(self, s):
596
607
:param s: The slider object that has been modified
597
608
:type s: class:`slider`
598
609
"""
599
- # Save the values for updating later
600
- for slider_num in range (0 , len (self .__teachpanel_sliders )):
601
- self .__teachpanel [self .__selected_robot ][slider_num ][self .__idx_theta ] = \
602
- self .__teachpanel_sliders [slider_num ].value
610
+ # Save the value
611
+ self .__teachpanel [self .__selected_robot ][s .id ][self .__idx_theta ] = s .value
603
612
604
613
# Get all angles for the robot
605
614
angles = []
@@ -612,6 +621,12 @@ def __joint_slider(self, s):
612
621
# Update joints
613
622
self .__robots [self .__selected_robot ].set_joint_poses (poses )
614
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
+
615
630
616
631
class GraphicsCanvas2D :
617
632
"""
@@ -1026,15 +1041,15 @@ def __verify_plot_options(self, options_str):
1026
1041
return [default_line , default_marker , default_colour ]
1027
1042
1028
1043
# If line_style given, join the first two options if applicable (some types have 2 characters)
1029
- for char in range (0 , len (options_split )- 1 ):
1044
+ for char in range (0 , len (options_split ) - 1 ):
1030
1045
# If char is '-' (only leading character in double length option)
1031
1046
if options_split [char ] == '-' and len (options_split ) > 1 :
1032
1047
# If one of the leading characters is valid
1033
- if options_split [char + 1 ] == '-' or options_split [char + 1 ] == '.' :
1048
+ if options_split [char + 1 ] == '-' or options_split [char + 1 ] == '.' :
1034
1049
# Join the two into the first
1035
- options_split [char ] = options_split [char ] + options_split [char + 1 ]
1050
+ options_split [char ] = options_split [char ] + options_split [char + 1 ]
1036
1051
# Shuffle down the rest
1037
- for idx in range (char + 2 , len (options_split )):
1052
+ for idx in range (char + 2 , len (options_split )):
1038
1053
options_split [idx - 1 ] = options_split [idx ]
1039
1054
# Remove duplicate extra
1040
1055
options_split .pop ()
0 commit comments