Browse Source

增加IIC设备打开是smbus的选择问题,可以适配树莓派和华为allas板子

corvin 5 years ago
parent
commit
6fc4c87840

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

@@ -7,6 +7,8 @@ is_use_serial: True
 
 serial_port: /dev/ttyACM0
 serial_baud: 57600
+
+i2c_smbus_num: 1   #raspberryPi:1, huawei altals 200DK: 2
 i2c_slave_addr: 0x08  #Get arduino due i2c slave addr
 
 timeout: 0.5

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

@@ -23,11 +23,12 @@ class ArduinoROS():
 
         # Cleanup when termniating the node
         rospy.on_shutdown(self.shutdown)
-        
+
         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)
         self.base_frame = rospy.get_param("~base_frame", 'base_footprint')
@@ -76,7 +77,7 @@ class ArduinoROS():
         rospy.Service('~light_show', LightShow, self.LightShowHandler)
 
         # Initialize the controlller
-        self.controller = Arduino(self.is_use_serial, self.serial_port, self.serial_baud, self.i2c_slave_addr, self.timeout)
+        self.controller = Arduino(self.is_use_serial, self.serial_port, self.serial_baud, self.i2c_smbus_num, self.i2c_slave_addr, self.timeout)
 
         # Make the connection
         self.controller.connect()

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

@@ -22,7 +22,7 @@ class Arduino:
     N_ANALOG_PORTS  = 10
     N_DIGITAL_PORTS = 54
 
-    def __init__(self, is_use_serial, serial_port="/dev/ttyACM0", baudrate=57600, i2c_slave_addr=8, timeout=0.5):
+    def __init__(self, is_use_serial, serial_port="/dev/ttyACM0", baudrate=57600,i2c_smbus_num=1, i2c_slave_addr=8, timeout=0.5):
         self.PID_RATE = 40 # Do not change this!  It is a fixed property of the Arduino PID controller.
         self.PID_INTERVAL = 25
 
@@ -30,6 +30,7 @@ class Arduino:
         self.serial_port   = serial_port
         self.baudrate = baudrate
 
+        self.i2c_smbus_num = i2c_smbus_num
         self.i2c_slave_addr = i2c_slave_addr
 
         self.timeout  = timeout
@@ -51,7 +52,7 @@ class Arduino:
         if self.is_use_serial:
             self.serial_connect()
         else:
-            self.i2c_bus = smbus.SMBus(1)
+            self.i2c_bus = smbus.SMBus(self.i2c_smbus_num)
             self.i2c_connect()
 
     def serial_connect(self):