|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import unittest |
| 4 | +import rospy |
| 5 | +import time |
| 6 | +import Queue as queue |
| 7 | +from sensor_msgs.msg import LaserScan |
| 8 | + |
| 9 | +PKG = "stage_ros" |
| 10 | + |
| 11 | + |
| 12 | +class RangerIntensityTests(unittest.TestCase): |
| 13 | + def setUp(self): |
| 14 | + """Called before every test. Set up a LaserScan subscriber |
| 15 | + """ |
| 16 | + rospy.init_node('ranger_intensity_test', anonymous=True) |
| 17 | + self._scan_q = queue.Queue() |
| 18 | + self._scan_topic = rospy.get_param("scan_topic", "base_scan") |
| 19 | + self._subscriber = rospy.Subscriber(self._scan_topic, |
| 20 | + LaserScan, self._scan_callback) |
| 21 | + |
| 22 | + def tearDown(self): |
| 23 | + """Called after every test. Cancel the scan subscription |
| 24 | + """ |
| 25 | + self._subscriber.unregister() |
| 26 | + self._scan_q = None |
| 27 | + self._subscriber = None |
| 28 | + |
| 29 | + def _scan_callback(self, scan_msg): |
| 30 | + """Called every time a scan is received |
| 31 | + """ |
| 32 | + self._scan_q.put(scan_msg) |
| 33 | + |
| 34 | + def _wait_for_scan(self, timeout=1.0): |
| 35 | + """Wait for a laser scan to be received |
| 36 | + """ |
| 37 | + # Use wall clock time for timeout |
| 38 | + end_time = time.time() + timeout |
| 39 | + while time.time() < end_time: |
| 40 | + try: |
| 41 | + return self._scan_q.get(True, 0.1) |
| 42 | + except queue.Empty: |
| 43 | + pass |
| 44 | + return None |
| 45 | + |
| 46 | + def test_intensity_greater_than_256(self): |
| 47 | + """Make sure stage_ros returns intensity values higher than 256 |
| 48 | + """ |
| 49 | + scan = self._wait_for_scan() |
| 50 | + self.assertIsNotNone(scan) |
| 51 | + self.assertGreater(max(scan.intensities), 256.9) |
| 52 | + |
| 53 | + |
| 54 | +if __name__ == '__main__': |
| 55 | + import rosunit |
| 56 | + rosunit.unitrun(PKG, 'test_intensity', RangerIntensityTests) |
0 commit comments