|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
"""
|
|
|
Copyright:2016-2020 www.corvin.cn ROS小课堂
|
|
|
- Description: A ROS Node for the Arduino microcontroller
|
|
|
+ Description: A ROS Node for the Arduino DUE microcontroller
|
|
|
Author: corvin
|
|
|
History:
|
|
|
20200706:init this file.
|
|
@@ -45,7 +45,7 @@ class ArduinoROS():
|
|
|
self.cmd_vel = Twist()
|
|
|
|
|
|
# A cmd_vel publisher so we can stop the robot when shutting down
|
|
|
- self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
|
|
|
+ self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
|
|
|
|
|
|
# A service to turn set the direction of a digital pin (0 = input, 1 = output)
|
|
|
rospy.Service('~digital_set_direction', DigitalSetDirection, self.DigitalSetDirectionHandler)
|
|
@@ -62,6 +62,15 @@ class ArduinoROS():
|
|
|
# A service to read the value of an analog sensor
|
|
|
rospy.Service('~analog_read', AnalogRead, self.AnalogReadHandler)
|
|
|
|
|
|
+ # A service to control camera angle
|
|
|
+ rospy.Service('~camera_control', CameraControl, self.CameraControlHandler)
|
|
|
+
|
|
|
+ # A service to get new pid params
|
|
|
+ rospy.Service('~dynamic_pid', DynamicPID, self.DynamicPIDHandler)
|
|
|
+
|
|
|
+ # A service to return infrared sensor distance
|
|
|
+ rospy.Service('~getInfraredDistance', GetInfraredDistance, self.GetInfraredDistanceHandler)
|
|
|
+
|
|
|
# Initialize the controlller
|
|
|
self.controller = Arduino(self.is_use_serial, self.serial_port, self.serial_baud, self.i2c_smbus_num, self.i2c_slave_addr, self.timeout)
|
|
|
|
|
@@ -147,7 +156,20 @@ class ArduinoROS():
|
|
|
self.controller.light_show(req.value)
|
|
|
return LightShowResponse()
|
|
|
|
|
|
- # Stop the robot
|
|
|
+ def CameraControlHandler(self, req):
|
|
|
+ self.controller.camera_angle(req.angle)
|
|
|
+ return CameraControlResponse()
|
|
|
+
|
|
|
+ def GetInfraredDistanceHandler(self, req):
|
|
|
+ value = self.controller.detect_distance()
|
|
|
+ return GetInfraredDistanceResponse(value[0]/100.0,value[1]/100.0,value[2]/100.0)
|
|
|
+
|
|
|
+ def DynamicPIDHandler(self, req):
|
|
|
+ self.controller.update_pid(req.value1, req.value2, 0, 50,
|
|
|
+ req.value3, req.value4, 0, 50)
|
|
|
+ return DynamicPIDResponse()
|
|
|
+
|
|
|
+ # Stop the robot arduino connect
|
|
|
def shutdown(self):
|
|
|
rospy.logwarn("Shutting down Arduino Node...")
|
|
|
try:
|