-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
74 lines (57 loc) · 1.76 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
import serial
import binascii
from CalcLidarData import CalcLidarData
import matplotlib.pyplot as plt
import math
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='polar')
ax.set_title('lidar (exit: Key E)',fontsize=18)
# Eキーを押すと終了します。
plt.connect('key_press_event', lambda event: exit(1) if event.key == 'e' else None)
ser = serial.Serial(port='/dev/tty.usbserial-0001',
baudrate=230400,
timeout=5.0,
bytesize=8,
parity='N',
stopbits=1)
tmpString = ""
lines = list()
angles = list()
distances = list()
i = 0
while True:
loopFlag = True
flag2c = False
if(i % 40 == 39):
if('line' in locals()):
line.remove()
line = ax.scatter(angles, distances, c="pink", s=5)
ax.set_theta_offset(math.pi / 2)
plt.pause(0.01)
angles.clear()
distances.clear()
i = 0
while loopFlag:
b = ser.read()
tmpInt = int.from_bytes(b, 'big')
if (tmpInt == 0x54):
tmpString += b.hex()+" "
flag2c = True
continue
elif(tmpInt == 0x2c and flag2c):
tmpString += b.hex()
if(not len(tmpString[0:-5].replace(' ','')) == 90 ):
tmpString = ""
loopFlag = False
flag2c = False
continue
lidarData = CalcLidarData(tmpString[0:-5])
angles.extend(lidarData.Angle_i)
distances.extend(lidarData.Distance_i)
tmpString = ""
loopFlag = False
else:
tmpString += b.hex()+" "
flag2c = False
i +=1
ser.close()