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 PKG='applanix_test'
00044 
00045 import roslib; roslib.load_manifest(PKG)
00046 import rospy
00047 
00048 from applanix_msgs.msg import NavigationSolution
00049 from applanix_generated_msgs.msg import AllMsgs
00050 from diagnostic_msgs.msg import DiagnosticArray
00051 from sensor_msgs.msg import NavSatFix, Imu
00052 
00053 import rostest
00054 import unittest
00055 
00056 
00057 class MessageReceiver(object):
00058   def __init__(self, topic_name, topic_type):
00059     self.msgs = []
00060     rospy.Subscriber(topic_name, topic_type, self.cb)
00061 
00062   def cb(self, msg):
00063     self.msgs.append(msg)
00064 
00065 
00066 class TestSmoke(unittest.TestCase):
00067   receivers = {}
00068 
00069   def test_diagnostics(self):
00070     self.assertTrue(len(self.receivers['diag'].msgs) > 70)
00071     fields = {}
00072     for msg in self.receivers['diag'].msgs:
00073       for field in msg.status[0].values:
00074         fields[field.key] = field.value
00075     self.assertEqual(fields['IMU_STATUS'], '0')
00076     self.assertEqual(fields['PRIMARY_GNSS_IN_CA_MODE'], '1')
00077     self.assertEqual(fields['INERTIAL_NAVIGATOR_INITIALIZED'], '1')
00078     self.assertEqual(fields['FULL_NAVIGATION_SOLUTION'], '0')
00079 
00080   def test_navigation(self):
00081     self.assertTrue(len(self.receivers['nav'].msgs) > 70)
00082     msg = self.receivers['nav'].msgs[-1]
00083     self.assertAlmostEqual(msg.latitude, 44.2449408681)
00084     self.assertAlmostEqual(msg.longitude, -76.5096210157)
00085     self.assertAlmostEqual(msg.roll, 2.04550977266)
00086     self.assertAlmostEqual(msg.pitch, 1.3181307736)
00087     self.assertAlmostEqual(msg.heading, 20.812475085)
00088 
00089   def test_fix(self):
00090     self.assertTrue(len(self.receivers['fix'].msgs) > 70)
00091     msg = self.receivers['fix'].msgs[-1]
00092     self.assertAlmostEqual(msg.latitude, 44.2449408681)
00093     self.assertAlmostEqual(msg.longitude, -76.5096210157) 
00094 
00095   def test_imu(self):
00096     self.assertTrue(len(self.receivers['imu'].msgs) > 70)
00097     msg = self.receivers['imu'].msgs[-1]
00098     self.assertAlmostEqual(msg.angular_velocity.x, -0.000960592777497)
00099     self.assertAlmostEqual(msg.linear_acceleration.y, 0.0397075638175) 
00100 
00101   def test_config(self):
00102     """ Exists primarily to test the correct parsing of complex messages/groups, including
00103       nested arrays, etc. """
00104     msg = self.receivers['cfg'].msgs[-1]
00105     self.assertEqual(len(msg.primary_data_port.groups), 3)
00106     self.assertEqual(msg.primary_data_port.groups[1].group, 10)
00107     self.assertEqual(msg.com_port_setup.ports[0].baud, 7)
00108     self.assertEqual(msg.com_port_setup.ports[0].parity, 0)
00109     self.assertEqual(msg.com_port_setup.ports[0].data_stop, 2)
00110 
00111 
00112 if __name__ == '__main__':
00113   rospy.init_node('applanix_test', anonymous=True)
00114   TestSmoke.receivers['diag'] = MessageReceiver('/diagnostics', DiagnosticArray)
00115   TestSmoke.receivers['nav'] = MessageReceiver('nav', NavigationSolution)
00116   TestSmoke.receivers['fix'] = MessageReceiver('gps_fix', NavSatFix)
00117   TestSmoke.receivers['imu'] = MessageReceiver('imu_data', Imu)
00118   TestSmoke.receivers['cfg'] = MessageReceiver('config', AllMsgs)
00119   rospy.sleep(3.0)
00120 
00121   rostest.rosrun(PKG, 'test_smoke', TestSmoke)
00122 


applanix_test
Author(s): Mike Purvis
autogenerated on Thu Jan 2 2014 11:05:23