test_joy_twist.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD)
3 #
4 # @author Tony Baltovski <tbaltovski@clearpathrobotics.com>
5 # @copyright (c) 2015, Clearpath Robotics, Inc., All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8 # the following conditions are met:
9 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 # following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
12 # following disclaimer in the documentation and/or other materials provided with the distribution.
13 # * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or
14 # promote products derived from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
17 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 
25 import sys
26 import unittest
27 import time
28 import rostest
29 import rospy
30 import geometry_msgs.msg
31 import sensor_msgs.msg
32 
33 
34 class TestJoyTwist(unittest.TestCase):
35 
36  def setUp(self):
37  rospy.init_node('test_joy_twist_node', anonymous=True)
38  self.pub = rospy.Publisher('joy', sensor_msgs.msg.Joy)
39  rospy.Subscriber('cmd_vel', geometry_msgs.msg.Twist, callback=self.callback)
40 
41  while (not rospy.has_param("~publish_joy")) and (not rospy.get_param("~expect_cmd_vel")):
42  time.sleep(0.1)
43 
44  self.expect_cmd_vel = rospy.get_param("~expect_cmd_vel")
45  self.joy_msg = rospy.get_param("~publish_joy")
46  self.received_cmd_vel = None
47 
48  def test_expected(self):
49  pub_joy = sensor_msgs.msg.Joy()
50  pub_joy.axes.extend(self.joy_msg['axes'])
51  pub_joy.buttons.extend(self.joy_msg['buttons'])
52  while self.received_cmd_vel is None:
53  self.pub.publish(pub_joy)
54  time.sleep(0.1)
55 
56  self.assertAlmostEqual(self.received_cmd_vel.linear.x, self.expect_cmd_vel['linear']['x'])
57  self.assertAlmostEqual(self.received_cmd_vel.linear.y, self.expect_cmd_vel['linear']['y'])
58  self.assertAlmostEqual(self.received_cmd_vel.linear.z, self.expect_cmd_vel['linear']['z'])
59  self.assertAlmostEqual(self.received_cmd_vel.angular.x, self.expect_cmd_vel['angular']['x'])
60  self.assertAlmostEqual(self.received_cmd_vel.angular.y, self.expect_cmd_vel['angular']['y'])
61  self.assertAlmostEqual(self.received_cmd_vel.angular.z, self.expect_cmd_vel['angular']['z'])
62 
63  def callback(self, msg):
64  self.received_cmd_vel = geometry_msgs.msg.Twist()
65  self.received_cmd_vel = msg
66 
67 
68 if __name__ == '__main__':
69  rostest.rosrun('teleop_twist_joy', 'test_joy_twist', TestJoyTwist)


teleop_twist_joy
Author(s): Mike Purvis
autogenerated on Thu Nov 26 2020 04:02:55