7 from actionlib_msgs.msg
import GoalStatus
9 from control_msgs.msg
import FollowJointTrajectoryAction, FollowJointTrajectoryGoal
10 from cartesian_control_msgs.msg
import (
11 FollowCartesianTrajectoryAction,
12 FollowCartesianTrajectoryGoal,
13 FollowCartesianTrajectoryResult,
14 CartesianTrajectoryPoint)
15 from trajectory_msgs.msg
import JointTrajectoryPoint
16 from controller_manager_msgs.srv
import SwitchControllerRequest, SwitchController
18 PKG =
'cartesian_trajectory_controller' 19 NAME =
'test_controller' 24 super(IntegrationTest, self).
__init__(*args)
26 rospy.init_node(
'test_controller')
28 timeout = rospy.Duration(3)
31 "/joint_trajectory_controller/follow_joint_trajectory", FollowJointTrajectoryAction)
34 except rospy.exceptions.ROSException
as err:
35 self.fail(
"Could not reach controller action. Msg: {}".format(err))
38 'cartesian_trajectory_controller/follow_cartesian_trajectory', FollowCartesianTrajectoryAction)
41 except rospy.exceptions.ROSException
as err:
42 self.fail(
"Could not reach controller action. Msg: {}".format(err))
45 'cartesian_trajectory_publisher/follow_cartesian_trajectory', FollowCartesianTrajectoryAction)
47 self.fail(
"Could not reach trajectory publisher action.")
49 self.
switch = rospy.ServiceProxy(
'/controller_manager/switch_controller', SwitchController)
51 self.
switch.wait_for_service(timeout.to_sec())
52 except rospy.exceptions.ROSException
as err:
54 "Could not reach controller switch service. Msg: {}".format(err))
57 """ Test the basic functionality on a straight line """ 61 self.assertEqual(self.
cart_client.get_result().error_code,
62 FollowCartesianTrajectoryResult.SUCCESSFUL)
65 """ Test whether the preemption mechanism works correctly """ 76 """ Test whether invalid goals are rejected correctly """ 83 p1 = CartesianTrajectoryPoint()
84 p1.time_from_start = rospy.Duration(1.0)
85 p2 = CartesianTrajectoryPoint()
86 p2.time_from_start = rospy.Duration(0.9999)
87 goal = FollowCartesianTrajectoryGoal()
88 goal.trajectory.points.append(p1)
89 goal.trajectory.points.append(p2)
92 self.assertEqual(self.
cart_client.get_result().error_code,
93 FollowCartesianTrajectoryResult.INVALID_GOAL)
96 """ Test whether trajectory publishing works """ 101 srv = SwitchControllerRequest()
102 srv.stop_controllers = []
103 srv.start_controllers = [
'cartesian_trajectory_publisher']
104 srv.strictness = SwitchControllerRequest.BEST_EFFORT
110 srv = SwitchControllerRequest()
111 srv.stop_controllers = [
'cartesian_trajectory_publisher']
112 srv.start_controllers = []
113 srv.strictness = SwitchControllerRequest.BEST_EFFORT
117 FollowCartesianTrajectoryResult.SUCCESSFUL)
120 srv = SwitchControllerRequest()
121 srv.stop_controllers = [
'cartesian_trajectory_controller']
122 srv.start_controllers = [
'joint_trajectory_controller']
123 srv.strictness = SwitchControllerRequest.BEST_EFFORT
126 q_start = [0, -2.0, 2.26, -0.2513274122872, 1.57, 0.0]
127 start_joint_state = FollowJointTrajectoryGoal()
128 start_joint_state.trajectory.joint_names = [
136 start_joint_state.trajectory.points = [
137 JointTrajectoryPoint(positions=q_start, time_from_start=rospy.Duration(3.0))]
143 srv = SwitchControllerRequest()
144 srv.stop_controllers = [
'joint_trajectory_controller']
145 srv.start_controllers = [
'cartesian_trajectory_controller']
146 srv.strictness = SwitchControllerRequest.BEST_EFFORT
150 """ Follow a 20 cm square in the y-z plane within 10 sec """ 154 start = CartesianTrajectoryPoint()
155 start.pose.position.x = 0.354
156 start.pose.position.y = 0.180
157 start.pose.position.z = 0.390
158 start.pose.orientation.x = 0.502
159 start.pose.orientation.y = 0.502
160 start.pose.orientation.z = 0.498
161 start.pose.orientation.w = 0.498
165 p1 = copy.deepcopy(start)
166 p1.pose.position.y += 0.2
167 p1.time_from_start = rospy.Duration(1.0 / 4 * duration)
169 p2 = copy.deepcopy(p1)
170 p2.pose.position.z += 0.2
171 p2.time_from_start = rospy.Duration(2.0 / 4 * duration)
173 p3 = copy.deepcopy(p2)
174 p3.pose.position.y -= 0.2
175 p3.time_from_start = rospy.Duration(3.0 / 4 * duration)
177 p4 = copy.deepcopy(p3)
178 p4.pose.position.z -= 0.2
179 p4.time_from_start = rospy.Duration(4.0 / 4 * duration)
181 goal = FollowCartesianTrajectoryGoal()
182 goal.trajectory.points.append(p1)
183 goal.trajectory.points.append(p2)
184 goal.trajectory.points.append(p3)
185 goal.trajectory.points.append(p4)
187 action_client.send_goal(goal)
189 action_client.wait_for_result()
192 if __name__ ==
'__main__':
194 rostest.run(PKG, NAME, IntegrationTest, sys.argv)
def switch_to_cartesian_control(self)
def test_preemption(self)
def move_square(self, action_client, wait_for_result=True)
def test_normal_execution(self)
def test_invalid_goals(self)
def test_trajectory_publishing(self)