18 from copy
import deepcopy
19 from sr_robot_commander.sr_hand_commander
import SrHandCommander
26 joints = [
"rh_THJ1",
"rh_THJ2",
"rh_THJ3",
"rh_THJ4",
"rh_THJ5",
27 "rh_FFJ1",
"rh_FFJ2",
"rh_FFJ3",
"rh_FFJ4",
28 "rh_MFJ1",
"rh_MFJ2",
"rh_MFJ3",
"rh_MFJ4",
29 "rh_RFJ1",
"rh_RFJ2",
"rh_RFJ3",
"rh_RFJ4",
30 "rh_LFJ1",
"rh_LFJ2",
"rh_LFJ3",
"rh_LFJ4",
"rh_LFJ5",
34 start_pos = {
"rh_THJ1": 0,
"rh_THJ2": 0,
"rh_THJ3": 0,
"rh_THJ4": 0,
"rh_THJ5": 0,
35 "rh_FFJ1": 0,
"rh_FFJ2": 0,
"rh_FFJ3": 0,
"rh_FFJ4": 0,
36 "rh_MFJ1": 0,
"rh_MFJ2": 0,
"rh_MFJ3": 0,
"rh_MFJ4": 0,
37 "rh_RFJ1": 0,
"rh_RFJ2": 0,
"rh_RFJ3": 0,
"rh_RFJ4": 0,
38 "rh_LFJ1": 0,
"rh_LFJ2": 0,
"rh_LFJ3": 0,
"rh_LFJ4": 0,
"rh_LFJ5": 0,
39 "rh_WRJ1": 0,
"rh_WRJ2": 0}
42 flex_ff = {
"rh_FFJ1": 0,
"rh_FFJ2": 0,
"rh_FFJ3": 0,
"rh_FFJ4": 0}
44 ext_ff = {
"rh_FFJ1": 0,
"rh_FFJ2": 0,
"rh_FFJ3": 0,
"rh_FFJ4": 0}
46 flex_mf = {
"rh_MFJ1": 0,
"rh_MFJ2": 0,
"rh_MFJ3": 0,
"rh_MFJ4": 0}
47 ext_mf = {
"rh_MFJ1": 0,
"rh_MFJ2": 0,
"rh_MFJ3": 0,
"rh_MFJ4": 0}
49 flex_rf = {
"rh_RFJ1": 0,
"rh_RFJ2": 0,
"rh_RFJ3": 0,
"rh_RFJ4": 0}
50 ext_rf = {
"rh_RFJ1": 0,
"rh_RFJ2": 0,
"rh_RFJ3": 0,
"rh_RFJ4": 0}
52 flex_lf = {
"rh_LFJ1": 0,
"rh_LFJ2": 0,
"rh_LFJ3": 0,
"rh_LFJ4": 0,
"rh_LFJ5": 0}
53 ext_lf = {
"rh_LFJ1": 0,
"rh_LFJ2": 0,
"rh_LFJ3": 0,
"rh_LFJ4": 0,
"rh_LFJ5": 0}
55 flex_th = {
"rh_THJ1": 0,
"rh_THJ2": 0,
"rh_THJ3": 0,
"rh_THJ4": 0,
"rh_THJ5": 0}
56 ext_th = {
"rh_THJ1": 0,
"rh_THJ2": 0,
"rh_THJ3": 0,
"rh_THJ4": 0,
"rh_THJ5": 0}
62 finger = raw_input(
"select which finger to move (options: ff, mf, rf, lf, th default: ff): ")
65 flex = deepcopy(flex_ff)
66 extend = deepcopy(ext_ff)
69 flex = deepcopy(flex_mf)
70 extend = deepcopy(ext_mf)
73 flex = deepcopy(flex_rf)
74 extend = deepcopy(ext_rf)
77 flex = deepcopy(flex_lf)
78 extend = deepcopy(ext_lf)
81 flex = deepcopy(flex_th)
82 extend = deepcopy(ext_th)
84 rospy.loginfo(
"Default finger 'ff' will be used.")
86 flex = deepcopy(flex_ff)
87 extend = deepcopy(ext_ff)
89 correct_joint_number =
False 90 while not correct_joint_number:
91 correct_joint_number =
True 92 joint_number_str = raw_input(
"select joint number to move: ")
93 joint_number_int = int(joint_number_str)
94 if finger ==
"FF" or finger ==
"MF" or finger ==
"RF":
95 if joint_number_int
not in range(5):
96 rospy.logerr(
"The finger you selected doesn't have joint {}".format(joint_number_int))
97 correct_joint_number =
False 98 elif finger ==
"LF" or finger ==
"TH":
99 if joint_number_int
not in range(6):
100 rospy.logerr(
"The finger you selected doesn't have joint {}".format(joint_number_int))
101 correct_joint_number =
False 103 return finger, flex, extend, joint_number_str, joint_number_int
110 finger, flex, extend, joint_number_str, joint_number_int =
select_finger()
111 if joint_number_int == 0:
112 joint_1 =
"rh_" + finger +
"J1" 113 joint_2 =
"rh_" + finger +
"J2" 115 joint =
"rh_" + finger +
"J" + joint_number_str
116 flex_degrees = raw_input(
"Select flex position in degrees (default 180): ")
119 flex_degrees_float = float(flex_degrees)
120 if joint_number_int == 0:
121 flex[joint_1] = flex_degrees_float / 2.0
122 flex[joint_2] = flex_degrees_float / 2.0
124 flex[joint] = flex_degrees_float
126 if joint_number_int == 0:
132 rospy.logerr(
"You didn't give a valid value")
135 ext_degrees = raw_input(
"Select extension position in degrees (default 0): ")
138 ext_degrees_float = float(ext_degrees)
139 if joint_number_int == 0:
140 extend[joint_1] = ext_degrees_float / 2.0
141 extend[joint_2] = ext_degrees_float / 2.0
143 extend[joint] = ext_degrees_float
145 if joint_number_int == 0:
151 rospy.logerr(
"You didn't give a valid value")
154 time_raw = raw_input(
"Select the time for each movement in seconds (default 1.0): ")
157 time = float(time_raw)
161 rospy.logerr(
"You didn't give a valid value")
165 hand_commander.move_to_joint_value_target_unsafe(flex, time,
True, angle_degrees=
True)
167 hand_commander.move_to_joint_value_target_unsafe(extend, time,
True, angle_degrees=
True)
169 user_input = raw_input(
170 "Press return to run again, 'change' to change parameters or 'exit' to exit the program: ")
171 if user_input ==
'exit':
173 elif user_input ==
'change':
177 if __name__ ==
"__main__":
178 rospy.init_node(
"right_hand_demo", anonymous=
True)
179 hand_commander = SrHandCommander(name=
"right_hand")
182 rospy.loginfo(
"Demo finished!")