-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·124 lines (92 loc) · 2.73 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
# @Time : 2021/10/30 22:37
# @Author : Jiabao Li
# @FileName: main.py
# @Software: PyCharm
from drivers.Laser import *
from drivers.Sonic import *
from drivers.Radar import *
from drivers.Serial import *
if __name__ == '__main__':
'''
毫米波雷达
读取距离
'''
finder = find_port_radarlike(MyRadar, ['00','01','05']) # 自动寻找串口,并提供可能的addr列表
if finder is None:
print('didnt find any port and address match the device')
exit(1)
print('find port and addr:', finder)
R = MyRadar(port=finder[0], addr=finder[1])
R.start(object_num=3, enable_bg_correct=True) # 目标检测数量2,启动背景获取&纠正
for _ in range(200):
print('2 objects distance:', R.snapshot())
exit(1)
#
# '''
# 超声波
# 读取`测量状态`和`距离`数据
# '''
# S = MySonic(find_port(MySonic))
# for d in S.get_distance():
# print('distance:', d, 'mm')
'''
激光主动问询
'''
mylaser = MyLaserLowSpeed('COM13')
# mylaser = MyLaserLowSpeed(find_port(MyLaser_base))
mylaser.first_start(measure_mode=1) # 初次启动(包含了初始化)
res = mylaser.snapshot(times=3) # 要测3次 res = [(vs1, dis1), (vs2, dis2) ...]
print(res)
'''
激光2钟示例
'''
mylaser = MyLaserLowSpeed('COM13')
# mylaser = MyLaserLowSpeed(find_port(MyLaser_base))
mylaser.first_start() # 初次启动(包含了初始化)
'''
激光
读取`key`和`value`的原始数据
'''
print('='*20, 'focus on the raw datas')
try:
'''
·异常捕获·,也可不要. It is save to do so.
'''
i = 0 # 计数
for k, v in mylaser.reader():
i += 1
print(k, v)
if i == 10:
# 只测10次
mylaser.stop()
break
except Exception as e:
print(traceback.format_exc())
raise
except:
mylaser.stop() # 停止激光设备
'''
激光
读取`测量状态`和`距离`数据
'''
print('='*20, 'focus on the distance datas')
mylaser.start()
try:
'''
·异常捕获·,也可不要.It is save to do so.
'''
i = 0 # 计数
for sta, dis in mylaser.get_distance():
i += 1
print(f'status:{sta}', f'distance:{dis}mm')
if i == 2000:
# 只测50次
mylaser.stop()
break
except Exception as e:
print(traceback.format_exc())
raise
except:
mylaser.stop() # 停止激光设备
mylaser.close_port() # 关闭串口