19 from moveit_msgs.srv
import SaveRobotStateToWarehouse
as SaveState
20 from sensor_msgs.msg
import JointState
21 from moveit_msgs.msg
import RobotState
22 from sr_arm_commander
import SrArmCommander
23 from sr_hand_commander
import SrHandCommander
24 from sr_robot_commander
import SrRobotCommander
25 from sr_utilities.hand_finder
import HandFinder
26 from controller_manager_msgs.srv
import ListControllers
27 from control_msgs.msg
import JointTrajectoryControllerState
28 from threading
import Lock
32 def __init__(self, name, hand_or_arm="both", hand_h=False, save_target=False):
34 self.
_save = rospy.ServiceProxy(
35 'save_robot_state', SaveState)
41 if name
is None or name ==
'':
42 raise ValueError(
"Cannot save with empty name.")
44 if hand_or_arm ==
"arm":
46 if not self._commander.arm_found():
47 raise ValueError(
"'No arm found.'")
49 elif hand_or_arm ==
'hand':
55 except Exception
as e:
56 double_error.append(str(e))
60 if not self._arm_commander.arm_found():
61 double_error.append(
"'No arm found.'")
63 if len(double_error) != 0:
64 raise ValueError(
" ".join(double_error))
66 self.
_save_hand = (hand_or_arm ==
"hand" or hand_or_arm ==
"both")
67 self.
_save_arm = (hand_or_arm ==
"arm" or hand_or_arm ==
"both")
70 rospy.loginfo(
"Saving targets instead of current values")
74 prefix =
"H1" if hand_h
else "rh" 75 self.
_hand_subscriber = rospy.Subscriber(
"/" + prefix +
"_trajectory_controller/state",
76 JointTrajectoryControllerState, self.
_target_cb)
79 JointTrajectoryControllerState, self.
_target_cb)
87 rospy.loginfo(
"Getting current")
90 current_dict = self._commander.get_robot_state_bounded()
91 robot_name = self._commander.get_robot_name()
93 current_dict = self._commander.get_current_state_bounded()
94 robot_name = self._commander.get_robot_name()
96 rospy.logfatal(
"Unknown save type")
100 rospy.loginfo(
"Getting targets")
101 waiting_for_targets =
True 102 while waiting_for_targets
and not rospy.is_shutdown():
103 self._mutex.acquire()
104 waiting_for_targets =
False 105 for joint
in current_dict:
109 waiting_for_targets =
True 110 rospy.loginfo(
"Still waiting for %s target" % joint)
111 self._mutex.release()
112 if waiting_for_targets:
115 if rospy.is_shutdown():
118 rospy.loginfo(current_dict)
119 rs.joint_state = JointState()
120 rs.joint_state.name = current_dict.keys()
121 rs.joint_state.position = current_dict.values()
126 self._mutex.acquire()
127 for n, joint
in enumerate(data.joint_names):
129 self._mutex.release()
def __init__(self, name, hand_or_arm="both", hand_h=False, save_target=False)
def _target_cb(self, data)