basic_data_smoke.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 #     _____
00004 #    /  _  \
00005 #   / _/ \  \
00006 #  / / \_/   \
00007 # /  \_/  _   \  ___  _    ___   ___   ____   ____   ___   _____  _   _
00008 # \  / \_/ \  / /  _\| |  | __| / _ \ | ┌┐ \ | ┌┐ \ / _ \ |_   _|| | | |
00009 #  \ \_/ \_/ /  | |  | |  | └─┐| |_| || └┘ / | └┘_/| |_| |  | |  | └─┘ |
00010 #   \  \_/  /   | |_ | |_ | ┌─┘|  _  || |\ \ | |   |  _  |  | |  | ┌─┐ |
00011 #    \_____/    \___/|___||___||_| |_||_| \_\|_|   |_| |_|  |_|  |_| |_|
00012 #            ROBOTICS™
00013 #
00014 #
00015 #  Copyright © 2012 Clearpath Robotics, Inc. 
00016 #  All Rights Reserved
00017 #  
00018 # Redistribution and use in source and binary forms, with or without
00019 # modification, are permitted provided that the following conditions are met:
00020 #     * Redistributions of source code must retain the above copyright
00021 #       notice, this list of conditions and the following disclaimer.
00022 #     * Redistributions in binary form must reproduce the above copyright
00023 #       notice, this list of conditions and the following disclaimer in the
00024 #       documentation and/or other materials provided with the distribution.
00025 #     * Neither the name of Clearpath Robotics, Inc. nor the
00026 #       names of its contributors may be used to endorse or promote products
00027 #       derived from this software without specific prior written permission.
00028 # 
00029 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00030 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00031 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00032 # DISCLAIMED. IN NO EVENT SHALL CLEARPATH ROBOTICS, INC. BE LIABLE FOR ANY
00033 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 #
00040 # Please send comments, questions, or patches to skynet@clearpathrobotics.com
00041 #
00042 
00043 import rospy
00044 
00045 from applanix_msgs.msg import NavigationSolution
00046 from applanix_msgs.msg import AllMsgs
00047 from diagnostic_msgs.msg import DiagnosticArray
00048 from sensor_msgs.msg import NavSatFix, Imu
00049 
00050 import rostest
00051 import unittest
00052 
00053 
00054 class MessageReceiver(object):
00055   def __init__(self, topic_name, topic_type):
00056     self.msgs = []
00057     rospy.Subscriber(topic_name, topic_type, self.cb)
00058 
00059   def cb(self, msg):
00060     self.msgs.append(msg)
00061 
00062 
00063 class TestSmoke(unittest.TestCase):
00064   receivers = {}
00065 
00066   def test_diagnostics(self):
00067     self.assertGreater(len(self.receivers['diag'].msgs), 70)
00068     fields = {}
00069     for msg in self.receivers['diag'].msgs:
00070       for field in msg.status[0].values:
00071         fields[field.key] = field.value
00072     self.assertEqual(fields['IMU_STATUS'], '0')
00073     self.assertEqual(fields['PRIMARY_GNSS_IN_CA_MODE'], '1')
00074     self.assertEqual(fields['INERTIAL_NAVIGATOR_INITIALIZED'], '1')
00075     self.assertEqual(fields['FULL_NAVIGATION_SOLUTION'], '0')
00076 
00077   def test_navigation(self):
00078     self.assertGreater(len(self.receivers['nav'].msgs), 70)
00079     msg = self.receivers['nav'].msgs[-1]
00080     self.assertAlmostEqual(msg.latitude, 44.2449408681)
00081     self.assertAlmostEqual(msg.longitude, -76.5096210157)
00082     self.assertAlmostEqual(msg.roll, 2.04550977266)
00083     self.assertAlmostEqual(msg.pitch, 1.3181307736)
00084     self.assertAlmostEqual(msg.heading, 20.812475085)
00085 
00086   def test_fix(self):
00087     self.assertGreater(len(self.receivers['fix'].msgs), 70)
00088     msg = self.receivers['fix'].msgs[-1]
00089     self.assertAlmostEqual(msg.latitude, 44.2449408681)
00090     self.assertAlmostEqual(msg.longitude, -76.5096210157) 
00091 
00092   def test_imu(self):
00093     self.assertGreater(len(self.receivers['imu'].msgs), 70)
00094     msg = self.receivers['imu'].msgs[-1]
00095     self.assertAlmostEqual(msg.angular_velocity.x, -0.000960592777497)
00096     self.assertAlmostEqual(msg.linear_acceleration.y, 0.0397075638175) 
00097 
00098   def test_config(self):
00099     """ Exists primarily to test the correct parsing of complex messages/groups, including
00100       nested arrays, etc. """
00101     msg = self.receivers['cfg'].msgs[-1]
00102     self.assertEqual(len(msg.primary_data_port.groups), 3)
00103     self.assertEqual(msg.primary_data_port.groups[1].group, 10)
00104     self.assertEqual(msg.com_port_setup.ports[0].baud, 7)
00105     self.assertEqual(msg.com_port_setup.ports[0].parity, 0)
00106     self.assertEqual(msg.com_port_setup.ports[0].data_stop, 2)
00107 
00108 
00109 if __name__ == '__main__':
00110   rospy.init_node('applanix_test', anonymous=True)
00111   TestSmoke.receivers['diag'] = MessageReceiver('/diagnostics', DiagnosticArray)
00112   TestSmoke.receivers['nav'] = MessageReceiver('nav', NavigationSolution)
00113   TestSmoke.receivers['fix'] = MessageReceiver('gps_fix', NavSatFix)
00114   TestSmoke.receivers['imu'] = MessageReceiver('imu_data', Imu)
00115   TestSmoke.receivers['cfg'] = MessageReceiver('config', AllMsgs)
00116   rospy.sleep(3.0)
00117 
00118   rostest.rosrun('applanix_bridge', 'test_smoke', TestSmoke)
00119 


applanix_bridge
Author(s): Mike Purvis
autogenerated on Thu Aug 27 2015 12:15:53