Browse Source

删除无用的lightshow.srv服务,优化arduino_driver.py代码

corvin rasp melodic 2 years ago
parent
commit
e8967905ac

+ 0 - 1
src/ros_arduino_bridge/ros_arduino_msgs/CMakeLists.txt

@@ -22,7 +22,6 @@ add_service_files(FILES
                   AnalogWrite.srv
                   AnalogRead.srv
                   AlarmWrite.srv
-                  LightShow.srv
                   GripperControl.srv
                   GripperAngle.srv
                   GetInfraredDistance.srv

+ 0 - 1
src/ros_arduino_bridge/ros_arduino_msgs/srv/LightShow.srv

@@ -1 +0,0 @@
-uint8 value

+ 0 - 2
src/ros_arduino_bridge/ros_arduino_python/config/my_arduino_params.yaml

@@ -2,7 +2,6 @@
 # Description:arduino节点运行时加载的参数,下面对参数进行解释:
 #   is_use_serial:与arduino通信是否使用串口,false的话就是IIC通信
 #   serial_port:串口通信时arduino的端口号
-#   serial_baud:串口通信时波特率
 #   i2c_smbus_num:系统管理总线号,树莓派为1
 #   isc_slave_addr:arduino的IIC设备地址
 # Author: corvin
@@ -14,7 +13,6 @@ is_use_serial: True
 
 # /dev/ttyACM# where is # is a number such as 0, 1 etc
 serial_port: /dev/ttyACM0
-serial_baud: 57600
 
 #raspberryPi:1, huawei altals 200DK: 2
 i2c_smbus_num: 1

+ 1 - 2
src/ros_arduino_bridge/ros_arduino_python/nodes/arduino_node.py

@@ -35,7 +35,6 @@ class ArduinoROS():
         self.is_use_serial = rospy.get_param("~is_use_serial", True)
 
         self.serial_port = rospy.get_param("~serial_port", "/dev/ttyACM0")
-        self.serial_baud = int(rospy.get_param("~serial_baud", 57600))
         self.i2c_smbus_num = rospy.get_param("~i2c_smbus_num", 1)
         self.i2c_slave_addr = rospy.get_param("~i2c_slave_addr", 8)
         self.timeout    = rospy.get_param("~timeout", 0.7)
@@ -82,7 +81,7 @@ class ArduinoROS():
         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)
+        self.controller = Arduino(self.is_use_serial, self.serial_port, self.i2c_smbus_num, self.i2c_slave_addr, self.timeout)
 
         # Make the connection
         self.controller.connect()

+ 3 - 25
src/ros_arduino_bridge/ros_arduino_python/src/ros_arduino_python/arduino_driver.py

@@ -25,13 +25,13 @@ class Arduino:
     N_ANALOG_PORTS  = 10
     N_DIGITAL_PORTS = 54
 
-    def __init__(self, is_use_serial,serial_port="/dev/ttyACM0",baudrate=57600,i2c_smbus_num=1,i2c_slave_addr=8,timeout=0.5):
+    def __init__(self, is_use_serial,serial_port="/dev/ttyACM0",i2c_smbus_num=1,i2c_slave_addr=8,timeout=0.5):
         self.PID_RATE = 40   #Don't change this ! It is a fixed property of the Arduino PID controller.
         self.PID_INTERVAL = 25
+        self.baudrate     = 57600
 
         self.is_use_serial = is_use_serial #与下位机arduino的通信方式是否使用串口还是IIC
         self.serial_port = serial_port
-        self.baudrate    = baudrate
 
         self.i2c_smbus_num  = i2c_smbus_num
         self.i2c_slave_addr = i2c_slave_addr
@@ -110,27 +110,20 @@ class Arduino:
         self.serial_port.open()
 
     def close(self):
-        ''' Close the serial port or i2c bus connect.
-        '''
         self.beep_ring(2)
         rospy.sleep(0.5)
         self.beep_ring(3)
+
         if self.is_use_serial:
             self.serial_port.close()
         else:
             self.i2c_bus.close()
 
     def send(self, cmd):
-        ''' This command should not be used on its own: it is called by the execute commands
-            below in a thread safe manner.
-        '''
         self.serial_port.write(cmd + '\r')
 
     def recv(self, timeout=0.5):
         timeout = min(timeout, self.timeout)
-        ''' This command should not be used on its own: it is called by the execute commands
-            below in a thread safe manner
-        '''
         c = ''
         value = ''
         attempts = 0
@@ -146,16 +139,10 @@ class Arduino:
         return value
 
     def recv_ack(self):
-        ''' This command should not be used on its own: it is called by the execute commands
-            below in a thread safe manner.
-        '''
         ack = self.recv(self.timeout)
         return ack == 'OK'
 
     def recv_int(self):
-        ''' This command should not be used on its own: it is called by the execute commands
-            below in a thread safe manner.
-        '''
         value = self.recv(self.timeout)
         try:
             return int(value)
@@ -163,9 +150,6 @@ class Arduino:
             return None
 
     def recv_array(self):
-        ''' This command should not be used on its own: it is called by the execute commands
-            below in a thread safe manner.
-        '''
         try:
             values = self.recv(self.timeout * self.N_ANALOG_PORTS).split()
             return map(float, values)
@@ -173,8 +157,6 @@ class Arduino:
             return []
 
     def execute(self, cmd):
-        ''' Thread safe execution of "cmd" on the Arduino returning a single integer value.
-        '''
         self.mutex.acquire()
 
         try:
@@ -204,8 +186,6 @@ class Arduino:
         return value
 
     def execute_array(self, cmd):
-        ''' Thread safe execution of "cmd" on the Arduino returning an float array.
-        '''
         self.mutex.acquire()
         try:
             self.serial_port.flushInput()
@@ -240,8 +220,6 @@ class Arduino:
         return values
 
     def execute_ack(self, cmd):
-        ''' Thread safe execution of "cmd" on the Arduino returning True if response is ACK.
-        '''
         self.mutex.acquire()
 
         try:

+ 4 - 0
update_code.sh

@@ -41,3 +41,7 @@ echo -e "${green}>>> 输入以下命令启动小车${normal}"
 echo -e "\n"
 echo -e "${green} roslaunch robot_bringup robot_bringup.launch${normal}"
 echo -e "\n"
+echo -e "${green}>>> 输入以下命令遥控小车${normal}"
+echo -e "\n"
+echo -e "${green} rosrun teleop_twist_keyboard teleop_twist_keyboard.py${normal}"
+echo -e "\n"