|
@@ -22,13 +22,14 @@ INPUT = 0
|
|
|
OUTPUT = 1
|
|
|
|
|
|
class MessageType:
|
|
|
- ANALOG = 0
|
|
|
- DIGITAL = 1
|
|
|
- INFRARED = 2
|
|
|
- RANGE = 3
|
|
|
- FLOAT = 4
|
|
|
- INT = 5
|
|
|
- BOOL = 6
|
|
|
+ ANALOG = 0
|
|
|
+ DIGITAL = 1
|
|
|
+ INFRARED = 2
|
|
|
+ RANGE = 3
|
|
|
+ FLOAT = 4
|
|
|
+ INT = 5
|
|
|
+ BOOL = 6
|
|
|
+ ULTRASONIC = 7
|
|
|
|
|
|
class Sensor(object):
|
|
|
def __init__(self, controller, name, pin, rate, frame_id, direction="input", **kwargs):
|
|
@@ -74,6 +75,10 @@ class Sensor(object):
|
|
|
self.msg.front_dist = self.value[0]
|
|
|
self.msg.left_dist = self.value[1]
|
|
|
self.msg.right_dist = self.value[2]
|
|
|
+ elif self.message_type == MessageType.ULTRASONIC:
|
|
|
+ self.msg.front_dist = self.value[0]
|
|
|
+ self.msg.left_dist = self.value[1]
|
|
|
+ self.msg.right_dist = self.value[2]
|
|
|
else:
|
|
|
self.msg.value = self.value
|
|
|
|
|
@@ -173,6 +178,19 @@ class SonarSensor(RangeSensor):
|
|
|
super(SonarSensor, self).__init__(*args, **kwargs)
|
|
|
self.msg.radiation_type = Range.ULTRASOUND
|
|
|
|
|
|
+class MyRangeSensor2(Sensor):
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ super(MyRangeSensor2, self).__init__(*args, **kwargs)
|
|
|
+
|
|
|
+ self.message_type = MessageType.ULTRASONIC
|
|
|
+ self.msg = UltrasonicSensors()
|
|
|
+ self.msg.header.frame_id = self.frame_id
|
|
|
+
|
|
|
+ self.pub = rospy.Publisher("~sensor/" + self.name, UltrasonicSensors, queue_size=2)
|
|
|
+
|
|
|
+ def read_value(self):
|
|
|
+ self.msg.header.stamp = rospy.Time.now()
|
|
|
+
|
|
|
class IRSensor(RangeSensor):
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
super(IRSensor, self).__init__(*args, **kwargs)
|
|
@@ -223,6 +241,19 @@ class IR2Y0A02(IRSensor):
|
|
|
|
|
|
return dist
|
|
|
|
|
|
+class US025(MyRangeSensor2):
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ super(US025, self).__init__(*args, **kwargs)
|
|
|
+
|
|
|
+ self.msg.field_of_view = 0.01
|
|
|
+ self.msg.min_range = 0.03
|
|
|
+ self.msg.max_range = 4
|
|
|
+
|
|
|
+ def read_value(self):
|
|
|
+ values = self.controller.detect_distance_ultrasonic()
|
|
|
+ distances = np.array([values[0], values[1], values[2]])
|
|
|
+ return distances/100.0
|
|
|
+
|
|
|
class MotorTotalCurrent(AnalogFloatSensor):
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
super(MotorTotalCurrent, self).__init__(*args, **kwargs)
|
|
@@ -240,6 +271,7 @@ class BatPercent(DigitalSensor):
|
|
|
percent = self.controller.getBatPercent()
|
|
|
return int(percent)
|
|
|
|
|
|
+'''
|
|
|
class CurrentValue(DigitalSensor):
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
super(CurrentValue, self).__init__(*args, **kwargs)
|
|
@@ -248,7 +280,7 @@ class CurrentValue(DigitalSensor):
|
|
|
currentvalue = self.controller.getCurrentValue()
|
|
|
#rospy.loginfo("read currentvalue: "+currentvalue)
|
|
|
return float(currentvalue)
|
|
|
-
|
|
|
+'''
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
rospy.loginf("arduino sensor main function ...")
|