From 8e6b2ff0ce07710d82c0cf1fb1aa0415131458ba Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sat, 7 Jun 2014 19:06:04 -0700 Subject: [PATCH] Added missing pin_mode statements to Analog and AnalogFloat sensor types --- .../src/ros_arduino_python/arduino_sensors.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 2f9b11c..51a7916 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py @@ -89,6 +89,13 @@ class AnalogSensor(Sensor): self.pub = rospy.Publisher("~sensor/" + self.name, Analog) + if self.direction == "output": + self.controller.pin_mode(self.pin, OUTPUT) + else: + self.controller.pin_mode(self.pin, INPUT) + + self.value = LOW + def read_value(self): return self.controller.analog_read(self.pin) @@ -105,6 +112,19 @@ class AnalogFloatSensor(Sensor): self.msg.header.frame_id = self.frame_id self.pub = rospy.Publisher("~sensor/" + self.name, AnalogFloat) + + if self.direction == "output": + self.controller.pin_mode(self.pin, OUTPUT) + else: + self.controller.pin_mode(self.pin, INPUT) + + self.value = LOW + + def read_value(self): + return self.controller.analog_read(self.pin) + + def write_value(self, value): + return self.controller.analog_write(self.pin, value) class DigitalSensor(Sensor):