6 from control_msgs.msg
import (
7 FollowJointTrajectoryAction,
8 FollowJointTrajectoryGoal)
9 from trajectory_msgs.msg
import (
15 from sensor_msgs.msg
import JointState
16 from trajectory_msgs.msg
import JointTrajectory
23 rospy.init_node(
'test_fake_joint_driver_node')
26 rospy.Subscriber(
'joint_states',
29 'joint_states', JointState, timeout=10.0)
31 self.
pub = rospy.Publisher(
32 'joint_trajectory_controller/command',
37 'joint_trajectory_controller/follow_joint_trajectory',
38 FollowJointTrajectoryAction)
40 self.client.wait_for_server(timeout=rospy.Duration(10.0))
46 traj = JointTrajectory()
47 traj.header.stamp = rospy.Time(0)
48 traj.joint_names = [
'JOINT1',
'JOINT2',
'JOINT3']
50 point = JointTrajectoryPoint()
51 point.positions = [0.1*i, 0.2*i, 0.3*i]
52 point.time_from_start = rospy.Duration(i*0.1)
53 traj.points.append(point)
55 self.pub.publish(traj)
58 self.assertAlmostEqual(self.joint_states.position[0], 1.0)
59 self.assertAlmostEqual(self.joint_states.position[1], 2.0)
60 self.assertAlmostEqual(self.joint_states.position[2], 3.0)
63 goal = FollowJointTrajectoryGoal()
64 traj = goal.trajectory
65 traj.header.stamp = rospy.Time(0)
66 traj.joint_names = [
'JOINT1',
'JOINT2',
'JOINT3']
68 point = JointTrajectoryPoint()
69 point.positions = [0.1*i, 0.2*i, 0.3*i]
70 point.time_from_start = rospy.Duration(i*0.1)
71 traj.points.append(point)
73 self.client.send_goal_and_wait(goal)
76 self.assertAlmostEqual(self.joint_states.position[0], 1.0)
77 self.assertAlmostEqual(self.joint_states.position[1], 2.0)
78 self.assertAlmostEqual(self.joint_states.position[2], 3.0)
81 if __name__ ==
'__main__':
82 rostest.rosrun(
'fake_joint_driver',
83 'test_fake_joint_driver',
def cb_joint_states(self, msg)
def test_joint_trajectory_command(self)
def test_joint_trajectory_action(self)