calibrate_hand_finder.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2014 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 2 of the License, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 import sys
19 import rospy
20 from ros_ethercat_model.calibrate_class import Calibrate
21 from sr_utilities.hand_finder import HandFinder
22 
23 
24 class CalibrateWithHand(Calibrate):
25 
26  @staticmethod
28  controllers = []
29  hand_finder = HandFinder()
30  joints = hand_finder.get_hand_joints()
31  mapping = hand_finder.get_hand_parameters().mapping
32  for hand in mapping:
33  prefix = mapping[hand]
34  for joint in joints[prefix]:
35  if joint[3:5].lower() == 'th' or joint[3:5].lower() == 'wr' or (joint[6] != '1' and joint[6] != '2'):
36  joint_controller = 'cal_sh_' + joint.lower()
37  else:
38  joint = joint[:6] + '0'
39  joint_controller = 'cal_sh_' + joint.lower()
40  if joint_controller not in controllers:
41  controllers.append(joint_controller)
42  return controllers
43 
44 
45 def main():
46  if rospy.is_shutdown():
47  return
48 
49  rospy.init_node('calibration', anonymous=True)
50 
51  calibrate_class = CalibrateWithHand()
52  controllers = calibrate_class.generate_controllers()
53 
54  calibrate_class.pub_calibrated.publish(False)
55  # Don't calibrate the IMU unless ordered to by user
56  cal_imu = rospy.get_param('calibrate_imu', False)
57 
58  if cal_imu:
59  imustatus = calibrate_class.calibrate_imu()
60  else:
61  imustatus = True
62 
63  if not calibrate_class.calibrate(controllers):
64  sys.exit(3)
65 
66  calibrate_class.pub_calibrated.publish(True)
67 
68  if not imustatus:
69  print("Mechanism calibration complete, but IMU calibration failed")
70  else:
71  print("Calibration complete")
72 
73  rospy.spin()
74 
75 if __name__ == '__main__':
76  main()


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:49