36 PKG =
'khi_robot_test' 37 import roslib; roslib.load_manifest(PKG)
44 import moveit_commander
45 import geometry_msgs.msg
47 from rospkg
import RosPack, ResourceNotFound
49 if rospy.has_param(
'/test_group_name'):
50 gn =
'/' + rospy.get_param(
'/test_group_name')
53 service = gn+
'/khi_robot_command_service' 54 planner =
'RRTConnectkConfigDefault' 60 group = gn+
'/manipulator' 72 self.
arm_name = rospy.get_param(gn+
'/khi_robot_param/robot')
73 limits = rospy.get_param(gn+
'/'+self.
arm_name+
'/joint_limits')
78 self.
base_pos_list = [ -90*math.pi/180, 0, 0, 0, 90*math.pi/180, 0, 0, 0 ]
79 for jt
in range(self.
max_jt):
81 self.min_pos_list.append(limits[
'lower_joint'+str(jt+1)][
'min_position'])
82 self.max_pos_list.append(limits[
'lower_joint'+str(jt+1)][
'max_position'])
83 self.max_acc_list.append(limits[
'lower_joint'+str(jt+1)][
'max_acceleration'])
84 self.max_vel_list.append(limits[
'lower_joint'+str(jt+1)][
'max_velocity'])
86 self.min_pos_list.append(limits[
'upper_joint'+str(jt-3)][
'min_position'])
87 self.max_pos_list.append(limits[
'upper_joint'+str(jt-3)][
'max_position'])
88 self.max_acc_list.append(limits[
'upper_joint'+str(jt-3)][
'max_acceleration'])
89 self.max_vel_list.append(limits[
'upper_joint'+str(jt-3)][
'max_velocity'])
93 self.
group =
'manipulator' 94 self.
base_pos_list = [ 90*math.pi/180, 0, 90*math.pi/180, 0, 90*math.pi/180, 0 ]
95 for jt
in range(self.
max_jt):
96 self.min_pos_list.append(limits[
'joint'+str(jt+1)][
'min_position'])
97 self.max_pos_list.append(limits[
'joint'+str(jt+1)][
'max_position'])
98 self.max_vel_list.append(limits[
'joint'+str(jt+1)][
'max_velocity'])
99 self.max_acc_list.append(limits[
'joint'+str(jt+1)][
'max_acceleration'])
103 if self.arm_name.startswith(
'RS'):
106 jt_list[2] = -130*math.pi/180
110 jt_list[2] = 130*math.pi/180
112 elif self.arm_name.startswith(
'WD'):
115 jt_list[0] = -170*math.pi/180
119 jt_list[4] = 220*math.pi/180
121 jt_list[0] = 170*math.pi/180
127 rospy.wait_for_service(service)
129 khi_robot_command_service = rospy.ServiceProxy(service,KhiRobotCmd)
130 resp1 = khi_robot_command_service(type_arg, cmd_arg)
132 except rospy.ServiceException
as e:
133 rospy.loginfo(
'Service call failed: %s', e)
140 for cnt
in range(timeout):
143 if major > 1
or ( major == 1
and minor >= 1 ):
144 (flag, trajectory, plannint_time, error_code) = mgc.plan()
146 rospy.loginfo(
'JT%d-%d: cannot be planned %d times', jt+1, num+1, cnt+1)
148 ret = mgc.execute(trajectory)
150 rospy.loginfo(
'JT%d-%d: cannot be executed %d times', jt+1, num+1, cnt+1)
156 rospy.loginfo(
'JT%d-%d: cannot be planned %d times', jt+1, num+1, cnt+1)
158 ret = mgc.execute(plan)
160 rospy.loginfo(
'JT%d-%d: cannot be executed %d times', jt+1, num+1, cnt+1)
165 rospy.loginfo(
'timeout')
172 manifest = rp.get_manifest(packagename)
173 return tuple(map(int,manifest.version.split(
'.')))
174 except ResourceNotFound:
198 rc = moveit_commander.RobotCommander()
201 mgc = moveit_commander.MoveGroupCommander(khi_robot.group)
204 mgc.set_planner_id(planner)
205 mgc.set_goal_joint_tolerance(accuracy_jt)
210 if ret.cmd_ret ==
'ERROR':
215 self.assertEqual(
'ACTIVE', ret.cmd_ret)
218 for jt
in range(khi_robot.max_jt):
219 if khi_robot.arm_name ==
'WD002N':
228 mgc.set_max_velocity_scaling_factor(min_vel)
229 mgc.set_max_acceleration_scaling_factor(min_acc)
230 jt_list = khi_robot.get_pos_list(ano, jt,
'min')
231 rospy.loginfo(
'JT%d : base', jt+1)
232 mgc.set_joint_value_target(jt_list)
236 mgc.set_max_velocity_scaling_factor(max_vel)
237 mgc.set_max_acceleration_scaling_factor(max_acc)
240 for num
in range(cyc_num):
242 jt_list = khi_robot.get_pos_list(ano, jt,
'max')
243 rospy.loginfo(
'JT%d-%d: max ', jt+1, num+1)
244 mgc.set_joint_value_target(jt_list)
246 self.assertTrue(retcode)
248 rospy.loginfo(
'JT%d-%d: max faild.', jt+1, num+1)
250 now_jt_list = mgc.get_current_joint_values()
251 self.assertAlmostEqual(jt_list[jt], now_jt_list[jt], delta = accuracy_jt*2)
254 jt_list = khi_robot.get_pos_list(ano, jt,
'min')
255 rospy.loginfo(
'JT%d-%d: min', jt+1, num+1)
256 mgc.set_joint_value_target(jt_list)
258 self.assertTrue(retcode)
260 rospy.loginfo(
'JT%d-%d: min faild.', jt+1, num+1)
262 now_jt_list = mgc.get_current_joint_values()
263 self.assertAlmostEqual(jt_list[jt], now_jt_list[jt], delta = accuracy_jt*2)
267 self.assertEqual(
'ACTIVE', ret.cmd_ret)
268 if ret.cmd_ret !=
'ACTIVE':
269 rospy.loginfo(
'JT%d-%d: not active', jt+1, num+1)
274 self.assertEqual(
'ACTIVE', ret.cmd_ret)
275 if ret.cmd_ret !=
'ACTIVE':
282 self.assertEqual(
'ACTIVE', ret.cmd_ret)
287 self.assertEqual(
'HOLDED', ret.cmd_ret)
292 self.assertEqual(
'ACTIVE', ret.cmd_ret)
294 if __name__ ==
'__main__':
297 rospy.init_node(
"test_khi_robot_control_node")
298 rostest.rosrun(PKG,
'test_khi_robot_control', TestKhiRobotControl)
def get_package_version(packagename)
def get_pos_list(self, ano, jt, type)
def plan_and_execute(mgc, jt, num, timeout)
def cmdhandler_client(type_arg, cmd_arg)
def test_position_velocity(self)