Skip to content

Commit da75096

Browse files
authored
Merge pull request petercorke#121 from petercorke/micah-dev
Merging 3D graphics updates (display angles and bug fixes)
2 parents 6a26c04 + 42814d7 commit da75096

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

graphics/graphics_canvas.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
23
from graphics.common_functions import *
34
from graphics.graphics_grid import GraphicsGrid, create_line, create_segmented_line, create_marker
45
from enum import Enum
@@ -59,7 +60,7 @@ def __init__(self, height=360, width=640, title='', caption='', grid=True):
5960
# List of joint sliders per robot
6061
self.__teachpanel = [] # 3D, robot -> joint -> options
6162
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
6364
# Checkbox states
6465
self.__grid_visibility = grid
6566
self.__camera_lock = False
@@ -151,13 +152,19 @@ def add_robot(self, robot):
151152
self.__robots.append(robot)
152153
self.__selected_robot = len(self.__robots) - 1
153154

154-
num_options = 3
155+
num_options = 4
155156
self.__teachpanel.append([[0] * num_options] * robot.num_joints) # Add spot for current robot settings
156157

157158
# Add robot joint sliders
158159
i = 0
159160
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)]
161168
i += 1
162169

163170
# Refresh the caption
@@ -451,23 +458,30 @@ def __setup_joint_sliders(self):
451458
"""
452459
Display the Teachpanel mode of the UI
453460
"""
454-
i = 1
461+
if len(self.__teachpanel) == 0:
462+
self.scene.append_to_caption("No robots available\n")
463+
return
464+
i = 0
455465
for joint in self.__teachpanel[self.__selected_robot]:
456466
if joint[self.__idx_qlim_min] == joint[self.__idx_qlim_max]:
457467
# If a slider with (effectively) no values, skip it
468+
i += 1
458469
continue
459470
# Add a title
460471
self.scene.append_to_caption('Joint {0}:\t'.format(i))
461-
i += 1
462472
# Add the slider, with the correct joint variables
463473
s = slider(
464474
bind=self.__joint_slider,
465475
min=joint[self.__idx_qlim_min],
466476
max=joint[self.__idx_qlim_max],
467-
value=joint[self.__idx_theta]
477+
value=joint[self.__idx_theta],
478+
id=i
468479
)
469480
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)
470483
self.scene.append_to_caption('\n\n')
484+
i += 1
471485

472486
#######################################
473487
# UI CALLBACKS
@@ -593,10 +607,8 @@ def __joint_slider(self, s):
593607
:param s: The slider object that has been modified
594608
:type s: class:`slider`
595609
"""
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
600612

601613
# Get all angles for the robot
602614
angles = []
@@ -609,6 +621,12 @@ def __joint_slider(self, s):
609621
# Update joints
610622
self.__robots[self.__selected_robot].set_joint_poses(poses)
611623

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+
612630

613631
class GraphicsCanvas2D:
614632
"""
@@ -1023,15 +1041,15 @@ def __verify_plot_options(self, options_str):
10231041
return [default_line, default_marker, default_colour]
10241042

10251043
# 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):
10271045
# If char is '-' (only leading character in double length option)
10281046
if options_split[char] == '-' and len(options_split) > 1:
10291047
# 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] == '.':
10311049
# 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]
10331051
# Shuffle down the rest
1034-
for idx in range(char+2, len(options_split)):
1052+
for idx in range(char + 2, len(options_split)):
10351053
options_split[idx - 1] = options_split[idx]
10361054
# Remove duplicate extra
10371055
options_split.pop()

0 commit comments

Comments
 (0)