Skip to content

Commit ffed6ca

Browse files
committed
Merge pull request #33 from sloretz/fix_dont_clip_intensity
Allows ranger intensities to be greater than 256
2 parents 881fffe + 0d02e7d commit ffed6ca

File tree

6 files changed

+155
-1
lines changed

6 files changed

+155
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ install(DIRECTORY world
6262
if(CATKIN_ENABLE_TESTING)
6363
find_package(rostest REQUIRED)
6464
add_rostest(test/hztest.xml)
65+
add_rostest(test/intensity_test.xml)
6566
endif()

src/stageros.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ StageNode::WorldCallback()
457457
for(unsigned int i = 0; i < sensor.ranges.size(); i++)
458458
{
459459
msg.ranges[i] = sensor.ranges[i];
460-
msg.intensities[i] = (uint8_t)sensor.intensities[i];
460+
msg.intensities[i] = sensor.intensities[i];
461461
}
462462

463463
if (robotmodel->lasermodels.size() > 1)

test/intensity_test.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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)

test/intensity_test.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<launch>
2+
<param name="/use_sim_time" value="true"/>
3+
<node pkg="stage_ros" name="stageros" type="stageros" args="-g $(find stage_ros)/world/intense.world"/>
4+
5+
<test test-name="intensity_check" pkg="stage_ros" type="intensity_test.py" name="scan_intensity_test">
6+
<param name="scan_topic" value="base_scan" />
7+
</test>
8+
</launch>

world/erratic-inc.world

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# A simple robot for inclusion in other world files
2+
3+
define topurg ranger
4+
(
5+
sensor
6+
(
7+
range [ 0.0 30.0 ]
8+
fov 270.25
9+
samples 1081
10+
)
11+
# generic model properties
12+
color "black"
13+
size [ 0.05 0.05 0.1 ]
14+
)
15+
16+
define erratic position
17+
(
18+
size [ 0.35 0.35 0.25 ]
19+
origin [ -0.05 0 0 0 ]
20+
gui_nose 1
21+
drive "diff"
22+
topurg
23+
(
24+
pose [ 0 0 0 0 ]
25+
)
26+
)

world/intense.world

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# A world containing objects with varying ranger insensity values
2+
3+
include "erratic-inc.world"
4+
5+
resolution 0.02
6+
interval_sim 100
7+
8+
define block model
9+
(
10+
size [0.5 0.5 0.5]
11+
gui_nose 0
12+
)
13+
14+
erratic
15+
(
16+
pose [ 0 0 0 0 ]
17+
name "era"
18+
color "blue"
19+
)
20+
21+
# Insert blocks with different intensity values
22+
block
23+
(
24+
pose [ 1.0 -3 0 0 ]
25+
ranger_return 0
26+
color "gray0"
27+
)
28+
block
29+
(
30+
pose [ 1.0 -2 0 0 ]
31+
ranger_return 50
32+
color "gray5"
33+
)
34+
block
35+
(
36+
pose [ 1.0 -1 0 0 ]
37+
ranger_return 100
38+
color "gray10"
39+
)
40+
block
41+
(
42+
pose [ 1.0 0 0 0 ]
43+
ranger_return 250
44+
color "gray25"
45+
)
46+
block
47+
(
48+
pose [ 1.0 1 0 0 ]
49+
ranger_return 4000
50+
color "gray40"
51+
)
52+
block
53+
(
54+
pose [ 1.0 2 0 0 ]
55+
ranger_return 80000
56+
color "gray80"
57+
)
58+
block
59+
(
60+
pose [ 1.0 3 0 0 ]
61+
ranger_return 1000000
62+
color "gray100"
63+
)

0 commit comments

Comments
 (0)