56 joint_names = [
"shoulder_pan",
65 l_arm_tucked = [0.06024, 1.248526, 1.789070, -1.683386, -1.7343417, -0.0962141, -0.0864407]
66 r_arm_tucked = [-0.023593, 1.1072800, -1.5566882, -2.124408, -1.4175, -1.8417, 0.21436]
67 l_arm_untucked = [ 0.4, 1.0, 0.0, -2.05, 0.0, -0.1, 0.0]
68 r_arm_untucked = [-0.4, 1.0, 0.0, -2.05, 0.0, -0.1, 0.0]
69 r_arm_approach = [0.039, 1.1072, 0.0, -2.067, -1.231, -1.998, 0.369]
70 r_arm_up_traj = [[-0.4, 0.0, 0.0, -2.05, 0.0, -0.1, 0.0]]
73 l_arm_tuck_traj = [l_arm_tucked]
74 r_arm_tuck_traj = [r_arm_approach,
78 l_arm_untuck_traj = [l_arm_untucked]
79 r_arm_untuck_traj = [r_arm_approach,
83 l_arm_clear_traj = [l_arm_untucked]
84 r_arm_clear_traj = [r_arm_untucked]
100 r_action_name = rospy.get_param(
'~r_joint_trajectory_action',
'r_arm_controller/joint_trajectory_action')
101 l_action_name = rospy.get_param(
'~l_joint_trajectory_action',
'l_arm_controller/joint_trajectory_action')
106 rospy.Subscriber(
'l_arm_controller/state', JointTrajectoryControllerState ,self.
stateCb)
107 rospy.Subscriber(
'r_arm_controller/state', JointTrajectoryControllerState ,self.
stateCb)
110 if not self.left_joint_client.wait_for_server(rospy.Duration(30)):
111 rospy.logerr(
"pr2_tuck_arms: left_joint_client action server did not come up within timelimit")
112 if not self.right_joint_client.wait_for_server(rospy.Duration(30)):
113 rospy.logerr(
"pr2_tuck_arms: right_joint_client action server did not come up within timelimit")
123 if rospy.is_shutdown():
127 result = TuckArmsResult()
128 result.tuck_left =
True 129 result.tuck_right =
True 132 if goal.tuck_right
and goal.tuck_left:
133 rospy.loginfo(
'Tucking both arms...')
138 elif goal.tuck_left
and not goal.tuck_right:
139 rospy.loginfo(
'Tucking left arm and untucking right arm...')
144 if goal.tuck_right
and not goal.tuck_left:
145 rospy.loginfo(
'Tucking right arm and untucking left arm...')
150 if not goal.tuck_right
and not goal.tuck_left:
151 rospy.loginfo(
"Untucking both arms...")
157 result.tuck_right = goal.tuck_right
158 result.tuck_left = goal.tuck_left
159 self.action_server.set_succeeded(result)
161 rospy.logerr(
"Tuck or untuck arms FAILED: Right value: %d. Left value: %d" % (result.tuck_left, result.tuck_right))
164 self.action_server.set_aborted(result)
170 self.
go(
'r', r_arm_up_traj) 172 self.
go(
'l', l_arm_clear_traj)
173 self.
go(
'l', l_arm_tuck_traj)
174 self.
go(
'r', r_arm_clear_traj) 179 self.
go(
'r', r_arm_up_traj) 181 self.
go(
'l', l_arm_untuck_traj)
183 self.
go(
'l', l_arm_clear_traj)
188 self.
go(
'r', r_arm_tuck_traj) 193 self.
go(
'r', r_arm_untuck_traj) 195 self.
go(
'r', r_arm_clear_traj) 197 def go(self, side, positions, wait = True):
198 goal = JointTrajectoryGoal()
199 goal.trajectory.joint_names = [side+
"_"+name+
"_joint" for name
in joint_names]
200 goal.trajectory.points = []
201 for p, count
in zip(positions, range(0,len(positions)+1)):
202 goal.trajectory.points.append(JointTrajectoryPoint( positions = p,
205 time_from_start = rospy.Duration((count+1) * self.
move_duration)))
206 goal.trajectory.header.stamp = rospy.get_rostime() + rospy.Duration(0.01)
208 if not {
'l': self.
left_joint_client,
'r': self.right_joint_client}[side].send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0)): 211 {
'l': self.
left_joint_client,
'r': self.right_joint_client}[side].send_goal(goal) 216 while angle > math.pi:
218 while angle < -math.pi:
228 for name_state, name_desi, value_state, value_l_tucked, value_l_untucked, value_r_tucked, value_r_untucked
in zip(msg.joint_names, joint_names, msg.actual.positions , l_arm_tucked, l_arm_untucked, r_arm_tucked, r_arm_untucked):
229 value_state = self.
angleWrap(value_state)
231 if 'l_'+name_desi+
'_joint' == name_state:
233 l_sum_tucked = l_sum_tucked + math.fabs(value_state - value_l_tucked)
234 l_sum_untucked = l_sum_untucked + math.fabs(value_state - value_l_untucked)
235 if 'r_'+name_desi+
'_joint' == name_state:
237 r_sum_tucked = r_sum_tucked + math.fabs(value_state - value_r_tucked)
238 r_sum_untucked = r_sum_untucked + math.fabs(value_state - value_r_untucked)
240 if l_sum_tucked > 0
and l_sum_tucked < 0.1:
242 elif l_sum_untucked > 0
and l_sum_untucked < 0.3:
244 elif l_sum_tucked >= 0.1
and l_sum_untucked >= 0.3:
247 if r_sum_tucked > 0
and r_sum_tucked < 0.1:
249 elif r_sum_untucked > 0
and r_sum_untucked < 0.3:
251 elif r_sum_tucked >= 0.1
and r_sum_untucked >= 0.3:
256 action_name =
'tuck_arms' 257 rospy.init_node(action_name)
264 if __name__ ==
'__main__':
def angleWrap(self, angle)
def executeCB(self, goal)
def go(self, side, positions, wait=True)
def __init__(self, node_name)