-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlidar.py
72 lines (51 loc) · 1.56 KB
/
lidar.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
from rplidar import RPLidar, RPLidarException
import smbus
bus = smbus.SMBus(1)
address = 8
def send_data_to_arduino(data):
bus.write_byte(address,data)
print("raspberry pi sent: ", data)
lidar = RPLidar('/dev/ttyUSB0')
lidar.__init__('/dev/ttyUSB0', 115200, 3, None)
lidar.connect()
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
try:
for i, scan in enumerate(lidar.iter_scans()):
one_sent = False
last_angle = None
for d in scan:
if 350 <= d[1] <= 360 or 0 <= d[1] <= 10:
if (d[2] / 10) <= 100:
one_sent = True
print(1)
send_data_to_arduino(1)
break
else:
one_sent = False
if last_angle is not None and abs((last_angle - d[1]) % 360) > 355:
one_sent = False
last_angle = d[1]
if not one_sent:
print(0)
send_data_to_arduino(0)
one_sent = False
if False:
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
break
except KeyboardInterrupt as err:
print('key board interupt')
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except RPLidarException as err:
print(err)
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
except AttributeError:
print('hi attribute error')