|
@@ -9,6 +9,7 @@
|
|
|
20200329:增加获取电池剩余电量百分比函数.
|
|
|
20200412:增加发布红外测距信息的服务.
|
|
|
20200423:增加获取电流传感器信息
|
|
|
+ 20201119:修复i2c获取pid,编码器,电量问题.
|
|
|
"""
|
|
|
from serial.serialutil import SerialException
|
|
|
import thread, smbus, rospy, time, os
|
|
@@ -332,9 +333,11 @@ class Arduino:
|
|
|
result_array = self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0x08)
|
|
|
#There are result_flag valid bytes.
|
|
|
result_flag = result_array.index(120)
|
|
|
+ if result_flag == 0:
|
|
|
+ result_array = result_array[1:(len(result_array)-1)]
|
|
|
+ result_flag = result_array.index(120)
|
|
|
+ result_string=''.join([chr(ch) for ch in result_array[0:(result_flag-1)]])
|
|
|
#rospy.loginfo("Valid bytes: "+str(result_flag))
|
|
|
- #extract result_flag bytes as strings
|
|
|
- result_string=''.join([chr(ec) for ec in result_array[0:(result_flag-1)]])
|
|
|
#extract encoder_counts by space
|
|
|
values=[int(s) for s in result_string.split(" ")]
|
|
|
if len(values) != 3:
|
|
@@ -531,6 +534,8 @@ class Arduino:
|
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('g'))
|
|
|
self.i2c_bus.write_byte(self.i2c_slave_addr, ord('\r'))
|
|
|
percent = self.i2c_bus.read_i2c_block_data(self.i2c_slave_addr, 0, 3)
|
|
|
+ if percent[0] == 120:
|
|
|
+ percent.remove(percent[0])
|
|
|
percent = map(chr, percent)
|
|
|
ret = ''.join(percent)
|
|
|
#print "ret:"+ret
|