Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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