test_block_laser_clipping.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4 Test plugin gazebo_ros_block_laser using gazebo_ros_block_laser_clipping.world.
5 """
6 
7 import math
8 import rospy
9 from sensor_msgs.msg import PointCloud
10 
11 import unittest
12 
13 class TestBlockLaserClippingPlugin(unittest.TestCase):
14  MIN_RANGE = 0.4
15  MAX_RANGE = 1.0
16 
17  def _ranges(self):
18  msg = rospy.wait_for_message('test_block_laser', PointCloud)
19  for point in msg.points:
20  yield math.sqrt(point.x**2 + point.y**2 + point.z**2)
21 
23  # Make sure there are points at all depths
24  BIN_SIZE = 0.01
25  num_bins = int((self.MAX_RANGE - self.MIN_RANGE) / BIN_SIZE)
26  bins = [b * BIN_SIZE + self.MIN_RANGE for b in range(num_bins)]
27  bin_counts = dict(zip(bins, [0] * len(bins)))
28 
29  for r in self._ranges():
30  closest_bin = None
31  closest_dist = float('inf')
32  for b in bins:
33  dist = abs(r - b)
34  if abs(r - b) < closest_dist:
35  closest_dist = dist
36  closest_bin = b
37  bin_counts[closest_bin] += 1
38 
39  self.assertTrue(0 not in bin_counts.values(), msg=repr(bin_counts))
40 
42  ALLOWED_ERROR = 0.00001
43  for r in self._ranges():
44  self.assertGreater(r, self.MIN_RANGE - ALLOWED_ERROR)
45  self.assertLess(r, self.MAX_RANGE + ALLOWED_ERROR)
46 
47 
48 if __name__ == '__main__':
49  import rostest
50  PKG_NAME = 'gazebo_plugins'
51  TEST_NAME = PKG_NAME + 'block_laser_clipping'
52  rospy.init_node(TEST_NAME)
53  rostest.rosrun(PKG_NAME, TEST_NAME, TestBlockLaserClippingPlugin)
test_block_laser_clipping.TestBlockLaserClippingPlugin.test_between_min_max
def test_between_min_max(self)
Definition: test_block_laser_clipping.py:41
test_block_laser_clipping.TestBlockLaserClippingPlugin.MIN_RANGE
float MIN_RANGE
Definition: test_block_laser_clipping.py:14
test_block_laser_clipping.TestBlockLaserClippingPlugin._ranges
def _ranges(self)
Definition: test_block_laser_clipping.py:17
test_block_laser_clipping.TestBlockLaserClippingPlugin
Definition: test_block_laser_clipping.py:13
test_block_laser_clipping.TestBlockLaserClippingPlugin.test_points_at_all_depths
def test_points_at_all_depths(self)
Definition: test_block_laser_clipping.py:22
test_block_laser_clipping.TestBlockLaserClippingPlugin.MAX_RANGE
float MAX_RANGE
Definition: test_block_laser_clipping.py:15


gazebo_plugins
Author(s): John Hsu
autogenerated on Thu Sep 5 2024 02:49:55