20 from sr_utilities.hand_finder
import HandFinder
21 from std_msgs.msg
import Bool
22 from std_srvs.srv
import Empty
27 This class resets all the motor boards of the Shadow Hand E present in the system. 28 On reset, the motor board firmware causes a jiggle and zeroes the tendon strain gauges. 29 Once the hands have been successfully reset, this class publishes True on the topic /calibrated 33 rospy.wait_for_service(
"controller_manager/load_controller", timeout=120.0)
34 self.
pub_calibrated = rospy.Publisher(
'calibrated', Bool, queue_size=1, latch=
True)
37 reset_service_list = []
38 generated_reset_service_list = []
43 ns = rospy.get_namespace()
44 while not reset_service_list:
46 service_list = rosservice.get_service_list(namespace=ns)
47 reset_service_list = [srv
for srv
in service_list
if '/reset_motor_' in srv]
48 if not reset_service_list:
49 rospy.loginfo(
"Waiting for motor reset services")
54 joints = hand_finder.get_hand_joints()
55 mapping = hand_finder.get_hand_parameters().mapping
57 prefix = mapping[hand]
58 for joint
in joints[prefix]:
59 if not (joint[3:5].lower() ==
'th' or joint[3:5].lower() ==
'wr' or 60 (joint[6] !=
'1' and joint[6] !=
'2')):
61 joint = joint[:6] +
'0' 63 joint_reset_service = joint[:2] +
'/reset_motor_' + joint[3:].upper()
65 if joint_reset_service
not in generated_reset_service_list:
66 generated_reset_service_list.append(joint_reset_service)
67 for gen_srv
in generated_reset_service_list:
68 gen_srv_match_list = [srv
for srv
in reset_service_list
if gen_srv
in srv]
69 if not gen_srv_match_list:
70 rospy.logwarn(
"Expected service not found: %s", gen_srv)
72 return reset_service_list
77 rospy.wait_for_service(srv, timeout=4.0)
79 reset_motor = rospy.ServiceProxy(srv, Empty)
81 except rospy.ServiceException
as exc:
83 rospy.logerr(
"Motor reset failed: %s Exception: %s", srv, str(exc))
88 if rospy.is_shutdown():
91 rospy.init_node(
'calibration', anonymous=
True)
94 services = calibrate_class.generate_reset_services_list()
96 calibrate_class.pub_calibrated.publish(
False)
98 if not calibrate_class.calibrate(services):
101 calibrate_class.pub_calibrated.publish(
True)
103 print(
"Hand calibration complete")
106 if __name__ ==
'__main__':
def generate_reset_services_list(self)
def calibrate(self, services)