40 import moveit_commander
41 from moveit_commander
import MoveGroupCommander, MoveItCommanderException, RobotCommander
43 from rospy
import ROSInitException
44 from control_msgs.msg
import FollowJointTrajectoryAction
45 from control_msgs.msg
import FollowJointTrajectoryGoal
46 from geometry_msgs.msg
import Pose
47 from trajectory_msgs.msg
import JointTrajectoryPoint
48 from tf.transformations
import quaternion_from_euler, euler_from_quaternion, compose_matrix, translation_from_matrix, euler_from_matrix
53 _MSG_ASK_ISSUEREPORT =
'Your report to ' + \
54 'https://github.com/start-jsk/rtmros_hironx/issues ' + \
55 'about the issue you are seeing is appreciated.' 60 atexit.register(
lambda : os._exit(0))
64 This class holds methods that are specific to Kawada Industries' dual-arm 65 robot called Hiro, via ROS. 67 @since: December 2014: Now this class is replacing the default programming interface 68 with HIRONX (hironx_client.py). 69 @since: July 2014: this class is only intended to be used through HIRONX 73 _MSG_NO_MOVEGROUP_FOUND = (
'\nMake sure you\'ve launched MoveGroup ' +
74 '(e.g. by launching ' +
75 'moveit_planning_execution.launch)')
79 @param jointgroups [str]: Deprecated. No need after version 1.1.4 onward. 83 rospy.get_master().getSystemState()
84 except socket.error
as e:
85 errormsg =
'No ROS Master found. Without it, you cannot use ROS from this script, but you can still use RTM without issues. ' + \
86 'To use ROS, do not forget to run rosbridge. How to do so? --> http://wiki.ros.org/rtmros_nextage/Tutorials/Operating%20Hiro%2C%20NEXTAGE%20OPEN' 87 raise ROSInitException(errormsg)
88 except Exception
as e:
89 errormsg =
'[ros_client] Unknown exception occurred, so do not create ros client...' 90 rospy.logerr(errormsg)
93 if not rospy.has_param(
'robot_description'):
94 rospy.logwarn(
'ROS Bridge is not started yet, Assuming you want just to use RTM')
99 rospy.init_node(
'hironx_ros_client')
105 if not rospy.has_param(
'robot_description_semantic'):
111 except RuntimeError
as e:
122 @raise RuntimeError: When MoveGroup is not running. 126 self.
MG_LARM = self.get_group(Constant.GRNAME_LEFT_ARM_MOVEGROUP)
127 self.
MG_RARM = self.get_group(Constant.GRNAME_RIGHT_ARM_MOVEGROUP)
129 self.
MG_HEAD = self.get_group(Constant.GRNAME_HEAD)
130 self.
MG_TORSO = self.get_group(Constant.GRNAME_TORSO)
132 self.
MG_LARM.set_planner_id(
"RRTConnectkConfigDefault")
133 self.
MG_RARM.set_planner_id(
"RRTConnectkConfigDefault")
134 self.
MG_BOTHARMS.set_planner_id(
"RRTConnectkConfigDefault")
135 self.
MG_HEAD.set_planner_id(
"RRTConnectkConfigDefault")
136 self.
MG_TORSO.set_planner_id(
"RRTConnectkConfigDefault")
137 self.
MG_UPPERBODY.set_planner_id(
"RRTConnectkConfigDefault")
143 except RuntimeError
as e:
148 This is only needed for accessing Actionlib clients directly, which 149 is no longer needed for this class now that it inherits 150 RobotCommander from MoveIt!. Still this line is kept for the methods 151 deprecated but remain for backward compatibility. 154 '/larm_controller/follow_joint_trajectory_action', FollowJointTrajectoryAction)
156 '/rarm_controller/follow_joint_trajectory_action', FollowJointTrajectoryAction)
158 '/head_controller/follow_joint_trajectory_action', FollowJointTrajectoryAction)
160 '/torso_controller/follow_joint_trajectory_action', FollowJointTrajectoryAction)
164 self.
_goal_larm.trajectory.joint_names.append(
"LARM_JOINT0")
165 self.
_goal_larm.trajectory.joint_names.append(
"LARM_JOINT1")
166 self.
_goal_larm.trajectory.joint_names.append(
"LARM_JOINT2")
167 self.
_goal_larm.trajectory.joint_names.append(
"LARM_JOINT3")
168 self.
_goal_larm.trajectory.joint_names.append(
"LARM_JOINT4")
169 self.
_goal_larm.trajectory.joint_names.append(
"LARM_JOINT5")
173 self.
_goal_rarm.trajectory.joint_names.append(
"RARM_JOINT0")
174 self.
_goal_rarm.trajectory.joint_names.append(
"RARM_JOINT1")
175 self.
_goal_rarm.trajectory.joint_names.append(
"RARM_JOINT2")
176 self.
_goal_rarm.trajectory.joint_names.append(
"RARM_JOINT3")
177 self.
_goal_rarm.trajectory.joint_names.append(
"RARM_JOINT4")
178 self.
_goal_rarm.trajectory.joint_names.append(
"RARM_JOINT5")
182 self.
_goal_head.trajectory.joint_names.append(
'HEAD_JOINT0')
183 self.
_goal_head.trajectory.joint_names.append(
'HEAD_JOINT1')
187 self.
_goal_torso.trajectory.joint_names.append(
'CHEST_JOINT0')
189 rospy.loginfo(
'Joint names; ' +
190 'Torso: {}\n\tHead: {}\n\tL-Arm: {}\n\tR-Arm: {}'.format(
196 def go_init(self, init_pose_type=0, task_duration=7.0):
198 Change the posture of the entire robot to the pre-defined init pose. 200 This method is equivalent to 201 hironx_ros_bridge.hironx_client.HIRONX.goInitial method (https://github.com/start-jsk/rtmros_hironx/blob/83c3ff0ad2aabd8525631b08276d33b09c98b2bf/hironx_ros_bridge/src/hironx_ros_bridge/hironx_client.py#L199), 202 with an addition of utilizing MoveIt!, which means e.g. if there is 203 possible perceived collision robots will take the path MoveIt! computes 204 with collision avoidance taken into account. 206 @type task_duration: float 207 @param init_pose_type: 208 0: default init pose (specified as _InitialPose) 209 1: factory init pose (specified as _InitialPose_Factory) 211 rospy.loginfo(
'*** go_init begins ***')
213 if 0 == init_pose_type:
214 posetype_str =
'init_rtm' 215 elif 1 == init_pose_type:
216 posetype_str =
'init_rtm_factory' 218 rospy.logerr(
"unsupporeted init_pose_type " + str(init_pose_type))
226 def goInitial(self, init_pose_type=0, task_duration=7.0):
228 This method internally calls self.go_init. 230 This method exists solely because of compatibility purpose with 231 hironx_ros_bridge.hironx_client.HIRONX.goInitial, which 232 holds a method "goInitial". 234 @param init_pose_type: 235 0: default init pose (specified as _InitialPose) 236 1: factory init pose (specified as _InitialPose_Factory) 238 return self.
go_init(init_pose_type, task_duration)
243 @deprecated: Use MoveitCommander.set_joint_value_target instead. 246 @param groupname: This should exist in self.groupnames. 247 @type positions_radian: [float] 248 @type duration: float 251 if groupname == Constant.GRNAME_TORSO:
254 elif groupname == Constant.GRNAME_HEAD:
257 elif groupname == Constant.GRNAME_LEFT_ARM:
260 elif groupname == Constant.GRNAME_RIGHT_ARM:
265 rospy.logerr(
'groupname {} not assigned'.format(groupname))
268 pt = JointTrajectoryPoint()
269 pt.positions = positions_radian
270 pt.time_from_start = rospy.Duration(duration)
271 goal.trajectory.points = [pt]
272 goal.trajectory.header.stamp = \
273 rospy.Time.now() + rospy.Duration(duration)
275 action_client.send_goal(goal)
278 'wait_for_result for the joint group {} = {}'.format(
279 groupname, action_client.wait_for_result()))
280 except rospy.ROSInterruptException
as e:
281 rospy.loginfo(e.str())
287 @param groupname: This should exist in self.groupnames. 288 @type positions_deg: [float] 289 @type duration: float 297 @TODO Needs to be replaced by something more common, or at least moved 298 somewhere more common. 300 @type list_degree: [float] 301 @param list_degree: A list length of the number of joints. 304 for deg
in list_degree:
305 rad = math.radians(deg)
307 rospy.logdebug(
'Position deg={} rad={}'.format(deg, rad))
310 def set_pose(self, joint_group, position, rpy=None, task_duration=7.0,
311 do_wait=True, ref_frame_name=None):
313 @deprecated: Use set_pose_target (from MoveGroupCommander) directly. 314 Accept pose defined by position and RPY in Cartesian format. 316 @type joint_group: str 317 @type position: [float] 318 @param position: x, y, z. 320 @param rpy: If None, keep the current orientation by using 321 MoveGroupCommander.set_position_target. See: 322 'http://moveit.ros.org/doxygen/' + 323 'classmoveit__commander_1_1move__group_1_1' + 324 'MoveGroupCommander.html#acfe2220fd85eeb0a971c51353e437753' 325 @param ref_frame_name: reference frame for target pose, i.e. "LARM_JOINT5_Link". 328 position = list(position)
336 except RuntimeError
as e:
342 if Constant.GRNAME_LEFT_ARM == joint_group:
344 elif Constant.GRNAME_RIGHT_ARM == joint_group:
347 rospy.logerr(
'joint_group must be either %s, %s or %s'%(Constant.GRNAME_LEFT_ARM,
348 Constant.GRNAME_RIGHT_ARM,
349 Constant.GRNAME_BOTH_ARMS))
354 ref_pose = movegr.get_current_pose(ref_frame_name).pose
355 ref_mat = compose_matrix(
356 translate = [ref_pose.position.x, ref_pose.position.y, ref_pose.position.z],
357 angles = list(euler_from_quaternion([ref_pose.orientation.x,ref_pose.orientation.y,ref_pose.orientation.z,ref_pose.orientation.w])))
358 target_mat = numpy.dot(ref_mat, compose_matrix(translate = position, angles = rpy
or [0, 0, 0]))
359 position = list(translation_from_matrix(target_mat))
360 rpy = list(euler_from_matrix(target_mat))
365 movegr.set_position_target(position)
366 except MoveItCommanderException
as e:
368 (movegr.go(do_wait)
or movegr.go(do_wait)
or 369 rospy.logerr(
'MoveGroup.go fails; jointgr={}'.format(joint_group)))
374 pose = copy.deepcopy(position)
376 rospy.loginfo(
'setpose jntgr={} mvgr={} pose={} posi={} rpy={}'.format(
377 joint_group, movegr, pose, position, rpy))
379 movegr.set_pose_target(pose)
380 except MoveItCommanderException
as e:
382 except Exception
as e:
385 (movegr.go(do_wait)
or movegr.go(do_wait)
or 386 rospy.logerr(
'MoveGroup.go fails; jointgr={}'.format(joint_group)))
def set_pose(self, joint_group, position, rpy=None, task_duration=7.0, do_wait=True, ref_frame_name=None)
def _to_rad_list(self, list_degree)
def go_offpose(self, task_duration=7.0)
def set_joint_angles_rad(self, groupname, positions_radian, duration=7.0, wait=False)
def goInitial(self, init_pose_type=0, task_duration=7.0)
def set_joint_angles_deg(self, groupname, positions_deg, duration=7.0, wait=False)
tuple _MSG_NO_MOVEGROUP_FOUND
def _init_moveit_commanders(self)
def __init__(self, jointgroups=None)
def _init_action_clients(self)
def go_init(self, init_pose_type=0, task_duration=7.0)
_movegr_botharms_ref_frame