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: