19 import serial.tools.list_ports
20 import string,os,commands,struct
25 from time
import sleep
32 cmd =
"ls /dev/video* > vs.out" 34 vf = open(
'vs.out',
'r') 42 cmd =
"udevadm info "+vd+
" |grep 'ID_VENDOR_ID=0bda' > vs.info" 44 infof = open(
"vs.info",
'r') 45 info = infof.readlines() 51 print 'camera video id: '+vs[i][-2]
57 cmd =
"udevadm info "+vd+
" |grep RealSense > vs.info" 59 infof = open(
"vs.info",
'r') 60 info = infof.readlines() 66 print 'RealSense video id: '+vs[i][-2]
74 print '\033[1;32m[√] 人脸识别摄像头 \033[0m' 76 print '\033[1;31m[×] 人脸识别摄像头 \033[0m' 79 print '\033[1;32m[√] RealSense摄像头 \033[0m' 81 print '\033[1;31m[×] RealSense摄像头 \033[0m' 84 rplidar_pluged =
False 97 port_list = list(serial.tools.list_ports.comports())
98 port_num = len(port_list)
100 print '\033[1;31m[×] 激光雷达\033[0m' 101 print '\033[1;31m[×] 机械臂 \033[0m' 102 print '\033[1;31m[×] PCB1 \033[0m' 103 print '\033[1;31m[×] PCB2 \033[0m' 107 print '当前插入了'+str(port_num)+
'个串口。' 109 print '----------------------------------------------------------------' 110 for i
in range(0,port_num):
112 print '----------------------------------------------------------------' 115 label_rplidar =
'CP2102' 116 for i
in range(0, port_num):
117 if( label_rplidar
in str(port_list[i])):
118 rplidar_pluged =
True 119 port_list.remove(port_list[i])
120 port_num = port_num - 1
122 if not rplidar_pluged:
123 print '\033[1;31m[×] 激光雷达 \033[0m' 125 print '\033[1;32m[√] 激光雷达 \033[0m' 126 os.system(
"cp udev/71-rplidar.rules /etc/udev/rules.d/")
127 print '\033[1;32m |----[√] 激光雷达端口映射文件写入系统 \033[0m' 130 label_arm =
'USB2.0-Serial' 131 for i
in range(0, port_num):
132 if( label_arm
in str(port_list[i])):
134 port_list.remove(port_list[i])
135 port_num = port_num - 1
138 print '\033[1;31m[×] 机械臂 \033[0m' 140 print '\033[1;32m[√] 机械臂 \033[0m' 141 os.system(
"cp udev/72-arm.rules /etc/udev/rules.d/")
142 print '\033[1;32m |----[√] 机械臂端口映射文件写入系统 \033[0m' 149 data = serial.read_all()
151 if time.time()-start >10:
160 port_num = len(port_list)
164 for i
in range(0, port_num):
166 dev_name = str(port_list[i]).split(
' ')[0]
168 serial1 = serial.Serial(dev_name, 115200, timeout=0.5)
170 except Exception
as e:
177 while len(ss)/2<151 :
181 data= str(binascii.b2a_hex(s))
185 print '\033[1;31m 已连接串口超过10秒未接收到数据,请确认是否未供电。 \033[0m' 190 if(label_PCB2
in ss ):
191 PCB2_dev_name = dev_name
192 ss_PCB2 =
'aa55'+ss.split(
'aa55')[1]
195 elif(label_PCB1
in ss):
197 PCB1_dev_name = dev_name
198 ss_PCB1 =
'aa55'+ss.split(
'aa55')[1]
208 x=x^int(s[i*2:i*2+2],16)
210 if x==int(s[-2:],16):
216 print '\033[1;32m[ ] PCB1 \033[0m' 218 print '\033[1;32m |----[√] PCB1接入,端口名: \033[0m'+PCB1_dev_name
219 print '\033[1;32m |----[√] 接收PCB1数据帧: \033[0m' +ss_PCB1
221 print '\033[1;32m |----[√] PCB1数据校验 \033[0m' 222 payload = ss_PCB1[6:-2]
225 print '\033[1;31m |----[×] PCB1标志位 \033[0m' 227 left_encoder = int(payload[2:6],16)
230 print '\033[1;32m |----[×] PCB1数据校验 \033[0m' 232 cmd =
'udevadm info -a -n '+PCB1_dev_name+
'|grep ATTRS{serial}' 233 (status, output) = commands.getstatusoutput(cmd)
234 PCB1_serial = output.split(
'"')[1]
235 print '\033[1;32m |----[√] PCB1芯片序列号: \033[0m'+PCB1_serial
236 f=open(
"udev/73-xbot.rules",
'r') #your path! 239 s= s+',ATTRS{serial}==\"'+PCB1_serial+
'\"' 240 f=open(
"/etc/udev/rules.d/73-xbot.rules",
'w')
243 print '\033[1;32m |----[√] PCB1端口映射文件写入系统 \033[0m' 245 print '\033[1;31m |----[×] PCB1接入 \033[0m' 250 print '\033[1;32m[ ] PCB2 \033[0m' 252 print '\033[1;32m |----[√] PCB2接入,端口名: \033[0m'+PCB2_dev_name
253 print '\033[1;32m |----[√] 接收PCB2数据帧: \033[0m' +ss_PCB2
255 print '\033[1;32m |----[√] PCB2数据校验 \033[0m' 256 payload = ss_PCB2[6:-2]
259 print '\033[1;31m |----[×] PCB2标志位 \033[0m' 262 yaw_platform = struct.unpack(
'B', payload[2:4].decode(
'hex'))[0]
263 pitch_platform = struct.unpack(
'B', payload[4:6].decode(
'hex'))[0]
264 volume = struct.unpack(
'B', payload[6:8].decode(
'hex'))[0]
265 acc_x = struct.unpack(
'<h', payload[8:12].decode(
'hex'))[0]
266 acc_y = struct.unpack(
'<h', payload[12:16].decode(
'hex'))[0]
267 acc_z = struct.unpack(
'<h', payload[16:20].decode(
'hex'))[0]
268 gyro_x = struct.unpack(
'<h', payload[20:24].decode(
'hex'))[0]
269 gyro_y = struct.unpack(
'<h', payload[24:28].decode(
'hex'))[0]
270 gyro_z = struct.unpack(
'<h', payload[28:32].decode(
'hex'))[0]
271 mag_x = struct.unpack(
'<h', payload[32:36].decode(
'hex'))[0]
272 mag_y = struct.unpack(
'<h', payload[36:40].decode(
'hex'))[0]
273 mag_z = struct.unpack(
'<h', payload[40:44].decode(
'hex'))[0]
274 yaw = -struct.unpack(
'<f', payload[44:52].decode(
'hex'))[0]
275 pitch = struct.unpack(
'<f', payload[52:60].decode(
'hex'))[0]
276 roll = struct.unpack(
'<f', payload[60:68].decode(
'hex'))[0]
277 q1 = struct.unpack(
'<f', payload[68:76].decode(
'hex'))[0]
278 q2 = struct.unpack(
'<f', payload[76:84].decode(
'hex'))[0]
279 q3 = struct.unpack(
'<f', payload[84:92].decode(
'hex'))[0]
280 q4 = struct.unpack(
'<f', payload[92:100].decode(
'hex'))[0]
281 error_status = struct.unpack(
'B', payload[100:102].decode(
'hex'))[0]
282 time_stamp = struct.unpack(
'<H', payload[102:106].decode(
'hex'))[0]
283 print '\033[1;32m |----[√] PCB2数据解析 \033[0m' 285 print '\033[1;31m |----[×] PCB2数据校验 \033[0m' 287 cmd =
'udevadm info -a -n '+PCB2_dev_name+
'|grep ATTRS{serial}' 288 (status, output) = commands.getstatusoutput(cmd)
289 PCB2_serial = output.split(
'"')[1]
290 print '\033[1;32m |----[√] PCB2芯片序列号: \033[0m'+PCB2_serial
291 f=open(
"udev/74-sensor.rules",
'r') #your path! 294 s= s+',ATTRS{serial}==\"'+PCB2_serial+
'\"' 295 f=open(
"/etc/udev/rules.d/74-sensor.rules",
'w')
298 print '\033[1;32m |----[√] PCB2端口映射文件写入系统 \033[0m' 302 print '\033[1;31m |----[×] PCB2接入 \033[0m'