|
@@ -316,7 +316,7 @@ class Arduino:
|
|
raise SerialException
|
|
raise SerialException
|
|
return None
|
|
return None
|
|
else:
|
|
else:
|
|
- print values
|
|
|
|
|
|
+ #print values
|
|
return values
|
|
return values
|
|
|
|
|
|
def i2c_get_encoder_counts(self):
|
|
def i2c_get_encoder_counts(self):
|
|
@@ -332,7 +332,7 @@ class Arduino:
|
|
|
|
|
|
result_array = self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|
|
result_array = self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|
|
#There are result_flag valid bytes.
|
|
#There are result_flag valid bytes.
|
|
- result_flag = result_array.index(120)
|
|
|
|
|
|
+ result_flag = result_array.index(120)
|
|
#rospy.loginfo("Valid bytes: "+str(result_flag))
|
|
#rospy.loginfo("Valid bytes: "+str(result_flag))
|
|
#extract result_flag bytes as strings
|
|
#extract result_flag bytes as strings
|
|
result_string=''.join([chr(e) for e in self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08, result_flag)])
|
|
result_string=''.join([chr(e) for e in self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08, result_flag)])
|
|
@@ -378,7 +378,7 @@ class Arduino:
|
|
self.i2c_bus.write_i2c_block_data(self.i2c_slave_addr, ord('z'), [ord(c) for c in cmd])
|
|
self.i2c_bus.write_i2c_block_data(self.i2c_slave_addr, ord('z'), [ord(c) for c in cmd])
|
|
except:
|
|
except:
|
|
return None
|
|
return None
|
|
-
|
|
|
|
|
|
+
|
|
def gripper_angle(self, angle):
|
|
def gripper_angle(self, angle):
|
|
''' control gripper angle
|
|
''' control gripper angle
|
|
'''
|
|
'''
|
|
@@ -420,7 +420,7 @@ class Arduino:
|
|
except:
|
|
except:
|
|
return None
|
|
return None
|
|
|
|
|
|
- def analog_read(self, pin):
|
|
|
|
|
|
+ def analog_read(self, pin):
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
return self.execute('a %d' %pin)
|
|
return self.execute('a %d' %pin)
|
|
else:
|
|
else:
|
|
@@ -435,7 +435,7 @@ class Arduino:
|
|
except:
|
|
except:
|
|
return None
|
|
return None
|
|
|
|
|
|
- def analog_write(self, pin, value):
|
|
|
|
|
|
+ def analog_write(self, pin, value):
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
return self.execute_ack('x %d %d' %(pin, value))
|
|
return self.execute_ack('x %d %d' %(pin, value))
|
|
else:
|
|
else:
|
|
@@ -445,7 +445,7 @@ class Arduino:
|
|
except:
|
|
except:
|
|
return None
|
|
return None
|
|
|
|
|
|
- def digital_read(self, pin):
|
|
|
|
|
|
+ def digital_read(self, pin):
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
return self.execute('d %d' %pin)
|
|
return self.execute('d %d' %pin)
|
|
else:
|
|
else:
|
|
@@ -461,7 +461,7 @@ class Arduino:
|
|
except:
|
|
except:
|
|
return None
|
|
return None
|
|
|
|
|
|
- def digital_write(self, pin, value):
|
|
|
|
|
|
+ def digital_write(self, pin, value):
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
return self.execute_ack('w %d %d' %(pin, value))
|
|
return self.execute_ack('w %d %d' %(pin, value))
|
|
else:
|
|
else:
|
|
@@ -471,7 +471,7 @@ class Arduino:
|
|
except:
|
|
except:
|
|
return None
|
|
return None
|
|
|
|
|
|
- def pin_mode(self, pin, mode):
|
|
|
|
|
|
+ def pin_mode(self, pin, mode):
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
return self.execute_ack('c %d %d' %(pin, mode))
|
|
return self.execute_ack('c %d %d' %(pin, mode))
|
|
else:
|
|
else:
|
|
@@ -481,7 +481,7 @@ class Arduino:
|
|
except:
|
|
except:
|
|
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:
|
|
# else:
|
|
@@ -494,7 +494,7 @@ class Arduino:
|
|
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:
|
|
# ch = ''
|
|
# ch = ''
|
|
# values = ''
|
|
# values = ''
|
|
# cnt = 0
|
|
# cnt = 0
|
|
@@ -509,7 +509,7 @@ class Arduino:
|
|
# print 222222222
|
|
# print 222222222
|
|
# print self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|
|
# print self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|
|
# #There are result_flag valid bytes.
|
|
# #There are result_flag valid bytes.
|
|
-# result_flag = result_array.index(120)
|
|
|
|
|
|
+# result_flag = result_array.index(120)
|
|
# #rospy.loginfo("Valid bytes: "+str(result_flag))
|
|
# #rospy.loginfo("Valid bytes: "+str(result_flag))
|
|
# #extract result_flag bytes as strings
|
|
# #extract result_flag bytes as strings
|
|
# result_string=''.join([chr(e) for e in self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08, result_flag)])
|
|
# result_string=''.join([chr(e) for e in self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08, result_flag)])
|
|
@@ -522,12 +522,12 @@ class Arduino:
|
|
|
|
|
|
|
|
|
|
def getBatPercent(self): #获取电池的剩余电量百分比
|
|
def getBatPercent(self): #获取电池的剩余电量百分比
|
|
-
|
|
|
|
|
|
+
|
|
if self.is_use_serial:
|
|
if self.is_use_serial:
|
|
percent = self.execute('g')
|
|
percent = self.execute('g')
|
|
#rospy.loginfo("bat percent:" + str(percent))
|
|
#rospy.loginfo("bat percent:" + str(percent))
|
|
return percent
|
|
return percent
|
|
- else:
|
|
|
|
|
|
+ else:
|
|
try:
|
|
try:
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('g'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('g'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|
|
@@ -544,7 +544,7 @@ class Arduino:
|
|
currentvalue = self.execute('f')
|
|
currentvalue = self.execute('f')
|
|
#rospy.loginfo("get current value:" + str(currentvalue))
|
|
#rospy.loginfo("get current value:" + str(currentvalue))
|
|
return currentvalue
|
|
return currentvalue
|
|
- else:
|
|
|
|
|
|
+ else:
|
|
try:
|
|
try:
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('f'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('f'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|