From 3f98ea4df8bf9f98ecac1d6b13fac703e23fe523 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Wed, 16 Dec 2015 06:20:34 -0800 Subject: [PATCH] Changed return value for GP2D12 IR sensor from max_range to NaN when raw values are out of range --- .../src/ros_arduino_python/arduino_sensors.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py index f28e313..8ea69bb 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py @@ -210,20 +210,21 @@ class GP2D12(IRSensor): def read_value(self): value = self.controller.analog_read(self.pin) + # The GP2D12 cannot provide a meaning result closer than 3 cm. if value <= 3.0: - return self.msg.max_range + return float('NaN') try: distance = (6787.0 / (float(value) - 3.0)) - 4.0 except: - return self.msg.max_range + return float('NaN') # Convert to meters distance /= 100.0 # If we get a spurious reading, set it to the max_range - if distance > self.msg.max_range: distance = self.msg.max_range - if distance < self.msg.min_range: distance = self.msg.max_range + if distance > self.msg.max_range: distance = float('NaN') + if distance < self.msg.min_range: distance = float('NaN') return distance