34 import moveit_commander
35 from moveit_msgs.srv
import GetPositionIK, GetPositionIKResponse
49 rospy.wait_for_service(
'set_tool_offset')
51 req = SetToolOffsetRequest()
55 req.rotation.z = offrz
56 req.rotation.y = offry
57 req.rotation.x = offrx
65 pos = map(
lambda x: x * 1000, [position.x, position.y, position.z])
66 deg = map(
lambda x: math.degrees(x), angle)
68 if self._api.position_to_joint(pos[0], pos[1], pos[2], deg[2], deg[1], deg[0], data) == 0:
69 result = map(
lambda k: data[
'DA'][k], [
'J1',
'J2',
'J3',
'J4',
'J5',
'J6'])
74 elif result[i] < -240:
78 elif result[5] < -360:
80 result = map(
lambda x: math.radians(x), result)
87 e = tf.transformations.euler_from_quaternion((quaternion.x, quaternion.y, quaternion.z, quaternion.w),
'rzyx')
98 rospy.loginfo(
'Wait for robot description')
100 if rospy.search_param(
'/robot_description')
is not None \
101 and rospy.search_param(
'/robot_description_semantic')
is not None:
104 print(
'-----------------')
105 self.
_rc = moveit_commander.RobotCommander()
106 print(
'-----------------')
107 rospy.loginfo(
'Preload group instance')
110 for group_name
in self._rc.get_group_names():
111 self._rc.get_group(group_name)
113 except RuntimeError
as e:
116 print(
'-----------------')
119 group = self._rc.get_group(group_name)
121 ee_link = group.get_end_effector_link()
123 tool_pos = map(
lambda x: x * 1000.0, pose[0])
124 tool_ori = map(
lambda x: math.degrees(x), tf.transformations.euler_from_quaternion(pose[1], axes=
'rzyx'))
126 tool_offset = tool_pos + tool_ori
133 ip = rospy.get_param(
'robot_ip_address',
'192.168.0.23')
137 default_joint_names = [
"Joint1",
"Joint2",
"Joint3",
"Joint4",
"Joint5",
"Joint6"]
138 self.
joint_names = rospy.get_param(
'controller_joint_names', default_joint_names)
149 tool_offset = self._tool_util.get_tool_offset(group_name)
153 self._rb.set_tool_offset(*tool_offset)
159 pos = req.ik_request.pose_stamped.pose.position
160 ori = req.ik_request.pose_stamped.pose.orientation
161 group_name = req.ik_request.group_name
167 res = GetPositionIKResponse()
168 res.solution.joint_state.header = req.ik_request.pose_stamped.header
171 joint = self._rb.solve_ik(pos, ori)
182 res.solution.joint_state.position = joint
183 res.error_code.val = res.error_code.SUCCESS
184 print(res.solution.joint_state.position)
186 res.error_code.val = res.error_code.NO_IK_SOLUTION
192 print(
"Ready to solve ik.")
195 if __name__ ==
"__main__":
196 rospy.init_node(
'ik_server')
def quaternion_to_euler(self, quaternion)
def set_tool_offset(self, offx=0, offy=0, offz=0, offrz=0, offry=0, offrx=0)
def handle_solve_ik(self, req)
def solve_ik(self, position, orientation)
def update_tool_offset(self, group_name)