mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-03 19:24:09 +05:30
added code for arduino pwm output
This commit is contained in:
parent
e0f00edf8c
commit
d83dcb8cb6
@ -15,6 +15,7 @@ add_service_files(FILES
|
|||||||
DigitalWrite.srv
|
DigitalWrite.srv
|
||||||
ServoRead.srv
|
ServoRead.srv
|
||||||
ServoWrite.srv
|
ServoWrite.srv
|
||||||
|
AnalogWrite.srv
|
||||||
)
|
)
|
||||||
|
|
||||||
generate_messages(
|
generate_messages(
|
||||||
|
@ -76,8 +76,11 @@ class ArduinoROS():
|
|||||||
|
|
||||||
# A service to turn a digital sensor on or off
|
# A service to turn a digital sensor on or off
|
||||||
rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler)
|
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)
|
self.controller = Arduino(self.port, self.baud, self.timeout)
|
||||||
|
|
||||||
# Make the connection
|
# Make the connection
|
||||||
@ -173,7 +176,11 @@ class ArduinoROS():
|
|||||||
def DigitalWriteHandler(self, req):
|
def DigitalWriteHandler(self, req):
|
||||||
self.controller.digital_write(req.pin, req.value)
|
self.controller.digital_write(req.pin, req.value)
|
||||||
return DigitalWriteResponse()
|
return DigitalWriteResponse()
|
||||||
|
|
||||||
|
def AnalogWriteHandler(self, req):
|
||||||
|
self.controller.analog_write(req.pin, req.value)
|
||||||
|
return AnalogWriteRrsponse()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
# Stop the robot
|
# Stop the robot
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user