|
@@ -95,7 +95,13 @@ class Arduino:
|
|
if test != self.baudrate:
|
|
if test != self.baudrate:
|
|
raise Exception
|
|
raise Exception
|
|
|
|
|
|
- self.beep_ring(1)
|
|
|
|
|
|
+ self.beep_ring(2)
|
|
|
|
+ rospy.sleep(0.1)
|
|
|
|
+ self.beep_ring(3)
|
|
|
|
+ rospy.sleep(0.05)
|
|
|
|
+ self.beep_ring(2)
|
|
|
|
+ rospy.sleep(0.1)
|
|
|
|
+ self.beep_ring(3)
|
|
rospy.loginfo("Arduino is connected by IIC !")
|
|
rospy.loginfo("Arduino is connected by IIC !")
|
|
except Exception:
|
|
except Exception:
|
|
rospy.logerr(sys.exc_info())
|
|
rospy.logerr(sys.exc_info())
|
|
@@ -111,7 +117,9 @@ class Arduino:
|
|
def close(self):
|
|
def close(self):
|
|
''' Close the serial port or i2c bus connect.
|
|
''' Close the serial port or i2c bus connect.
|
|
'''
|
|
'''
|
|
- self.beep_ring(0)
|
|
|
|
|
|
+ self.beep_ring(2)
|
|
|
|
+ rospy.sleep(0.5)
|
|
|
|
+ self.beep_ring(3)
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
self.serial_port.close()
|
|
self.serial_port.close()
|
|
else:
|
|
else:
|
|
@@ -482,21 +490,21 @@ class Arduino:
|
|
return None
|
|
return None
|
|
|
|
|
|
def beep_ring(self, value):
|
|
def beep_ring(self, value):
|
|
-# if self.is_use_serial:
|
|
|
|
|
|
+ if self.is_use_serial:
|
|
return self.execute_ack('p %d' %value)
|
|
return self.execute_ack('p %d' %value)
|
|
-# else:
|
|
|
|
-# cmd = (' %d\r' %(value))
|
|
|
|
-# try:
|
|
|
|
-# self.i2c_bus.write_i2c_block_data(self.i2c_slave_addr, ord('p'), [ord(c) for c in cmd])
|
|
|
|
-# except:
|
|
|
|
-# return None
|
|
|
|
|
|
+ else:
|
|
|
|
+ cmd = (' %d\r' %(value))
|
|
|
|
+ try:
|
|
|
|
+ self.i2c_bus.write_i2c_block_data(self.i2c_slave_addr, ord('p'), [ord(c) for c in cmd])
|
|
|
|
+ except:
|
|
|
|
+ return None
|
|
|
|
|
|
def detect_distance(self): #检测三个红外测距传感器的返回值,一共返回三个值,分别为前,左,右三个测距值
|
|
def detect_distance(self): #检测三个红外测距传感器的返回值,一共返回三个值,分别为前,左,右三个测距值
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
return self.execute_array('h')
|
|
return self.execute_array('h')
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|
|
- self.i2c_bus.write_byte(self.i2c_slave_addr, int(ord('h')))
|
|
|
|
|
|
+ self.i2c_bus.write_byte(self.i2c_slave_addr, int(ord('j')))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|
|
|
|
|
|
result_array2 = self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|
|
result_array2 = self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|