mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-03 11:14:08 +05:30
Added AnalogRead (analog_Read) and DigitaRead (digital_read) services
This commit is contained in:
parent
c26830b5c4
commit
1f3ae62769
@ -14,9 +14,11 @@ add_message_files(FILES
|
|||||||
add_service_files(FILES
|
add_service_files(FILES
|
||||||
DigitalSetDirection.srv
|
DigitalSetDirection.srv
|
||||||
DigitalWrite.srv
|
DigitalWrite.srv
|
||||||
|
DigitalRead.srv
|
||||||
ServoRead.srv
|
ServoRead.srv
|
||||||
ServoWrite.srv
|
ServoWrite.srv
|
||||||
AnalogWrite.srv
|
AnalogWrite.srv
|
||||||
|
AnalogRead.srv
|
||||||
)
|
)
|
||||||
|
|
||||||
generate_messages(
|
generate_messages(
|
||||||
|
3
ros_arduino_msgs/srv/AnalogRead.srv
Executable file
3
ros_arduino_msgs/srv/AnalogRead.srv
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
uint8 pin
|
||||||
|
---
|
||||||
|
uint16 value
|
3
ros_arduino_msgs/srv/DigitalRead.srv
Executable file
3
ros_arduino_msgs/srv/DigitalRead.srv
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
uint8 pin
|
||||||
|
---
|
||||||
|
bool value
|
@ -75,10 +75,16 @@ class ArduinoROS():
|
|||||||
rospy.Service('~digital_set_direction', DigitalSetDirection, self.DigitalSetDirectionHandler)
|
rospy.Service('~digital_set_direction', DigitalSetDirection, self.DigitalSetDirectionHandler)
|
||||||
|
|
||||||
# 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 read the value of a digital sensor
|
||||||
|
rospy.Service('~digital_read', DigitalRead, self.DigitalReadHandler)
|
||||||
|
|
||||||
# A service to set pwm values for the pins
|
# A service to set pwm values for the pins
|
||||||
rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler)
|
rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler)
|
||||||
|
|
||||||
|
# A service to read the value of an analog sensor
|
||||||
|
rospy.Service('~analog_read', AnalogRead, self.AnalogReadHandler)
|
||||||
|
|
||||||
# Initialize the controlller
|
# Initialize the controlller
|
||||||
self.controller = Arduino(self.port, self.baud, self.timeout)
|
self.controller = Arduino(self.port, self.baud, self.timeout)
|
||||||
@ -176,10 +182,18 @@ 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 DigitalReadHandler(self, req):
|
||||||
|
value = self.controller.digital_read(req.pin)
|
||||||
|
return DigitalReadResponse(value)
|
||||||
|
|
||||||
def AnalogWriteHandler(self, req):
|
def AnalogWriteHandler(self, req):
|
||||||
self.controller.analog_write(req.pin, req.value)
|
self.controller.analog_write(req.pin, req.value)
|
||||||
return AnalogWriteResponse()
|
return AnalogWriteResponse()
|
||||||
|
|
||||||
|
def AnalogReadHandler(self, req):
|
||||||
|
value = self.controller.analog_read(req.pin)
|
||||||
|
return AnalogReadResponse(value)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
# Stop the robot
|
# Stop the robot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user