test_fake_joint_driver.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3 import math
4 import sys
5 import actionlib
6 from control_msgs.msg import (
7  FollowJointTrajectoryAction,
8  FollowJointTrajectoryGoal)
9 from trajectory_msgs.msg import (
10  JointTrajectory,
11  JointTrajectoryPoint)
12 import rospy
13 import rostest
14 import rosnode
15 from sensor_msgs.msg import JointState
16 from trajectory_msgs.msg import JointTrajectory
17 import time
18 import unittest
19 
20 class TestFakeJointDriver(unittest.TestCase):
21  @classmethod
22  def setUpClass(cls):
23  rospy.init_node('test_fake_joint_driver_node')
24 
25  def setUp(self):
26  rospy.Subscriber('joint_states',
27  JointState, self.cb_joint_states, queue_size=10)
28  self.joint_states = rospy.wait_for_message(
29  'joint_states', JointState, timeout=10.0)
30 
31  self.pub = rospy.Publisher(
32  'joint_trajectory_controller/command',
33  JointTrajectory,
34  queue_size=10)
35 
37  'joint_trajectory_controller/follow_joint_trajectory',
38  FollowJointTrajectoryAction)
39 
40  self.client.wait_for_server(timeout=rospy.Duration(10.0))
41 
42  def cb_joint_states(self, msg):
43  self.joint_states = msg
44 
46  traj = JointTrajectory()
47  traj.header.stamp = rospy.Time(0)
48  traj.joint_names = ['JOINT1', 'JOINT2', 'JOINT3']
49  for i in range(11):
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)
54 
55  self.pub.publish(traj)
56  rospy.sleep(1.1)
57 
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)
61 
63  goal = FollowJointTrajectoryGoal()
64  traj = goal.trajectory
65  traj.header.stamp = rospy.Time(0)
66  traj.joint_names = ['JOINT1', 'JOINT2', 'JOINT3']
67  for i in range(11):
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)
72 
73  self.client.send_goal_and_wait(goal)
74  rospy.sleep(0.1)
75 
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)
79 
80 
81 if __name__ == '__main__':
82  rostest.rosrun('fake_joint_driver',
83  'test_fake_joint_driver',
84  TestFakeJointDriver)


fake_joint_driver
Author(s): Ryosuke Tajima
autogenerated on Thu Dec 19 2019 03:31:40