test_joy_twist.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD)
00003 #
00004 # @author    Tony Baltovski <tbaltovski@clearpathrobotics.com>
00005 # @copyright (c) 2015, Clearpath Robotics, Inc., All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that
00008 # the following conditions are met:
00009 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the
00010 #   following disclaimer.
00011 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
00012 #   following disclaimer in the documentation and/or other materials provided with the distribution.
00013 # * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or
00014 #   promote products derived from this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00017 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00018 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00019 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00020 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00021 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00022 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 # POSSIBILITY OF SUCH DAMAGE.
00024 
00025 import sys
00026 import unittest
00027 import time
00028 import rostest
00029 import rospy
00030 import geometry_msgs.msg
00031 import sensor_msgs.msg
00032 
00033 
00034 class TestJoyTwist(unittest.TestCase):
00035 
00036     def setUp(self):
00037         rospy.init_node('test_joy_twist_node', anonymous=True)
00038         self.pub = rospy.Publisher('joy', sensor_msgs.msg.Joy)
00039         rospy.Subscriber('cmd_vel', geometry_msgs.msg.Twist, callback=self.callback)
00040 
00041         while (not rospy.has_param("~publish_joy")) and (not rospy.get_param("~expect_cmd_vel")):
00042             time.sleep(0.1)
00043 
00044         self.expect_cmd_vel = rospy.get_param("~expect_cmd_vel")
00045         self.joy_msg = rospy.get_param("~publish_joy")
00046         self.received_cmd_vel = None
00047 
00048     def test_expected(self):
00049         pub_joy = sensor_msgs.msg.Joy()
00050         pub_joy.axes.extend(self.joy_msg['axes'])
00051         pub_joy.buttons.extend(self.joy_msg['buttons'])
00052         while self.received_cmd_vel is None:
00053             self.pub.publish(pub_joy)
00054             time.sleep(0.1)
00055 
00056         self.assertAlmostEqual(self.received_cmd_vel.linear.x, self.expect_cmd_vel['linear']['x'])
00057         self.assertAlmostEqual(self.received_cmd_vel.linear.y, self.expect_cmd_vel['linear']['y'])
00058         self.assertAlmostEqual(self.received_cmd_vel.linear.z, self.expect_cmd_vel['linear']['z'])
00059         self.assertAlmostEqual(self.received_cmd_vel.angular.x, self.expect_cmd_vel['angular']['x'])
00060         self.assertAlmostEqual(self.received_cmd_vel.angular.y, self.expect_cmd_vel['angular']['y'])
00061         self.assertAlmostEqual(self.received_cmd_vel.angular.z, self.expect_cmd_vel['angular']['z'])
00062 
00063     def callback(self, msg):
00064         self.received_cmd_vel = geometry_msgs.msg.Twist()
00065         self.received_cmd_vel = msg
00066 
00067 
00068 if __name__ == '__main__':
00069     rostest.rosrun('teleop_twist_joy', 'test_joy_twist', TestJoyTwist)


teleop_twist_joy
Author(s): Mike Purvis
autogenerated on Sat Sep 3 2016 03:35:45