4 from control_msgs.msg
import (
5 FollowJointTrajectoryAction,
6 FollowJointTrajectoryGoal,
10 from trajectory_msgs.msg
import (
14 from jog_msgs.msg
import JogJoint
17 from sensor_msgs.msg
import JointState
25 rospy.init_node(
'test_jog_joint_node')
33 self.
delta = rospy.get_param(
'~delta', 0.01)
35 self.
joint_state_ = rospy.wait_for_message(
'joint_states', JointState, timeout=10.0)
36 rospy.Subscriber(
'joint_states', JointState, self.
cb_joint_states, queue_size=10)
38 self.
pub = rospy.Publisher(
'jog_joint', JogJoint, queue_size=50)
44 self.client.wait_for_server()
49 goal = FollowJointTrajectoryGoal()
50 goal.trajectory.header.stamp = rospy.Time.now()
51 goal_time_tolerance = rospy.Time(0.1)
52 goal.goal_time_tolerance = rospy.Time(0.1)
54 point = JointTrajectoryPoint()
56 point.time_from_start = rospy.Duration(1.0)
57 goal.trajectory.points.append(point)
60 self.client.send_goal(goal)
61 self.assertTrue(self.client.wait_for_result(timeout=rospy.Duration(5.0)))
68 '''Test to jog a jog command''' 71 jog.header.stamp = rospy.Time.now()
73 jog.deltas = [self.
delta]*len(jog.joint_names)
78 index = joint_state.name.index(joint)
79 self.assertAlmostEqual(
80 joint_state.position[index] + self.
delta, self.joint_state_.position[index], delta=0.0001)
83 '''Test to jog continuous 10 jog commands''' 87 jog.header.stamp = rospy.Time.now()
89 jog.deltas = [self.
delta]*len(jog.joint_names)
94 index = joint_state.name.index(joint)
95 self.assertAlmostEqual(
96 joint_state.position[index] + 10*self.
delta, self.joint_state_.position[index], delta=0.0001)
99 '''Test to jog same amount for forward and backward''' 103 jog.header.stamp = rospy.Time.now()
105 jog.deltas = [self.
delta]*len(jog.joint_names)
106 self.pub.publish(jog)
109 jog.header.stamp = rospy.Time.now()
111 jog.deltas = [-self.
delta]*len(jog.joint_names)
112 self.pub.publish(jog)
116 index = joint_state.name.index(joint)
117 self.assertAlmostEqual(
118 joint_state.position[index],
119 self.joint_state_.position[index],
123 '''Test to publish empty jonit_names/positions jog command''' 126 jog.header.stamp = rospy.Time.now()
127 self.pub.publish(jog)
131 index = joint_state.name.index(joint)
132 self.assertAlmostEqual(
133 joint_state.position[index],
134 self.joint_state_.position[index],
137 if __name__ ==
'__main__':
138 rostest.rosrun(
'jog_joint',
'test_jog_joint_node', TestJogJointNode)
def test_empty_jog_for_all_joint(self)
def cb_joint_states(self, msg)
def test_one_jog_for_all_joint(self)
def test_loop_jogs_for_all_joint(self)
def test_ten_jogs_for_all_joint(self)