Fixed bug in GP2D12 distance function

This commit is contained in:
Patrick Goebel 2012-12-15 18:37:17 -08:00
parent 3b2742b444
commit 5416fccb43
5 changed files with 24 additions and 17 deletions

View File

@ -66,17 +66,12 @@ class Sensor(object):
except:
return
# The Arduino returns ranges in cm so convert to meters
# For range sensors, assign the value to the range message field
if self.message_type == MessageType.RANGE:
try:
self.value /= 100.0
self.msg.range = self.value
except:
return
else:
self.msg.value = self.value
# At a timestamp and publish the message
self.msg.header.stamp = rospy.Time.now()
self.pub.publish(self.msg)
@ -171,14 +166,18 @@ class Ping(SonarSensor):
def __init__(self,*args, **kwargs):
super(Ping, self).__init__(*args, **kwargs)
#self.controller.pin_mode(self.pin, INPUT)
self.msg.field_of_view = 0.785398163
self.msg.min_range = 0.02
self.msg.max_range = 3.0
def read_value(self):
return self.controller.ping(self.pin)
# The Arduino Ping code returns the distance in centimeters
cm = self.controller.ping(self.pin)
# Convert it to meters for ROS
distance = cm / 100.0
return distance
class GP2D12(IRSensor):
@ -191,12 +190,21 @@ class GP2D12(IRSensor):
def read_value(self):
value = self.controller.analog_read(self.pin)
if value <= 3.0:
return self.msg.max_range
try:
distance = (6787 / (value - 3)) - 4
distance = (6787.0 / (float(value) - 3.0)) - 4.0
except:
distance = 80
if distance > 80: distance = 80
if distance < 10: distance = 10
return self.msg.max_range
# 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
return distance

View File

@ -2,6 +2,7 @@
"""
A base controller class for the Arduino microcontroller
Borrowed heavily from Mike Feguson's ArbotiX base_controller.py code.
Created for the Pi Robot Project: http://www.pirobot.org

View File

@ -6,9 +6,7 @@
<url>http://ros.org/wiki/ros_arduino_bridge</url>
<depend stack="ros" />
<depend stack="ros_comm" /> <!-- std_srvs, rospy, roscpp -->
<depend stack="common" /> <!-- actionlib -->
<depend stack="common_msgs" /> <!-- nav_msgs, geometry_msgs, sensor_msgs, diagnostic_msgs -->
<depend stack="control" /> <!-- control_msgs -->
<depend stack="geometry" /> <!-- tf -->
</stack>