From d83dcb8cb6a9f6cf656a1d50f9cbb90c1945c599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Tr=C3=B6ster?= Date: Mon, 28 Apr 2014 10:22:15 +0200 Subject: [PATCH] added code for arduino pwm output --- ros_arduino_msgs/CMakeLists.txt | 1 + ros_arduino_python/nodes/arduino_node.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index ad5e695..16e7f81 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -15,6 +15,7 @@ add_service_files(FILES DigitalWrite.srv ServoRead.srv ServoWrite.srv + AnalogWrite.srv ) generate_messages( diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 4e2f34b..085289b 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -76,8 +76,11 @@ class ArduinoROS(): # A service to turn a digital sensor on or off rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler) + + # A service to set pwm values for the pins + rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler) - # Initialize the controlller + # Initialize the controlller self.controller = Arduino(self.port, self.baud, self.timeout) # Make the connection @@ -173,7 +176,11 @@ class ArduinoROS(): def DigitalWriteHandler(self, req): self.controller.digital_write(req.pin, req.value) return DigitalWriteResponse() - + + def AnalogWriteHandler(self, req): + self.controller.analog_write(req.pin, req.value) + return AnalogWriteRrsponse() + def shutdown(self): # Stop the robot try: