mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-05 20:14:07 +05:30
Fixed bug in Range sensor message type
This commit is contained in:
parent
2de2028192
commit
fcb662907e
@ -40,11 +40,10 @@ class MessageType:
|
||||
BOOL = 5
|
||||
|
||||
class Sensor(object):
|
||||
def __init__(self, device, name, pin=None, type=None, rate=0, direction="input", frame_id="base_link", **kwargs):
|
||||
def __init__(self, device, name, pin=None, rate=0, direction="input", frame_id="base_link", **kwargs):
|
||||
self.device = device
|
||||
self.name = name
|
||||
self.pin = pin
|
||||
self.type = type
|
||||
self.rate = rate
|
||||
self.direction = direction
|
||||
self.frame_id = frame_id
|
||||
@ -155,7 +154,6 @@ class AnalogFloatSensor(Sensor):
|
||||
self.write_value(req.value)
|
||||
return AnalogFloatSensorWriteResponse()
|
||||
|
||||
|
||||
class DigitalSensor(Sensor):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DigitalSensor, self).__init__(*args, **kwargs)
|
||||
@ -195,13 +193,10 @@ class DigitalSensor(Sensor):
|
||||
self.write_value(req.value)
|
||||
return DigitalSensorWriteResponse()
|
||||
|
||||
|
||||
class RangeSensor(AnalogFloatSensor):
|
||||
class RangeSensor(Sensor):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RangeSensor, self).__init__(*args, **kwargs)
|
||||
|
||||
self.direction = "input"
|
||||
|
||||
self.message_type = MessageType.RANGE
|
||||
|
||||
self.msg = Range()
|
||||
@ -213,14 +208,12 @@ class RangeSensor(AnalogFloatSensor):
|
||||
def read_value(self):
|
||||
self.msg.header.stamp = rospy.Time.now()
|
||||
|
||||
|
||||
class SonarSensor(RangeSensor):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SonarSensor, self).__init__(*args, **kwargs)
|
||||
|
||||
self.msg.radiation_type = Range.ULTRASOUND
|
||||
|
||||
|
||||
class IRSensor(RangeSensor):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(IRSensor, self).__init__(*args, **kwargs)
|
||||
@ -244,7 +237,6 @@ class Ping(SonarSensor):
|
||||
|
||||
return distance
|
||||
|
||||
|
||||
class GP2D12(IRSensor):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(GP2D12, self).__init__(*args, **kwargs)
|
||||
@ -256,7 +248,6 @@ class GP2D12(IRSensor):
|
||||
def read_value(self):
|
||||
value = self.device.analog_read(self.pin)
|
||||
|
||||
|
||||
# The GP2D12 cannot provide a meaning result closer than 3 cm.
|
||||
if value <= 3.0:
|
||||
return float('NaN')
|
||||
@ -318,3 +309,4 @@ class MaxEZ1Sensor(SonarSensor):
|
||||
return self.device.get_MaxEZ1(self.trigger_pin, self.output_pin)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user