-
Notifications
You must be signed in to change notification settings - Fork 3
/
LIDARListener.py
42 lines (35 loc) · 1.15 KB
/
LIDARListener.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
import socket
import matplotlib.pyplot as plt
import numpy as np
# HOST AND PORT
PORT = 65432
angles = np.linspace(0, 2*np.pi, 100)
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_title("LiDAR Strength and Distance")
ax.set_ylim(0, 100) # ADJUST LIMIT
plt.show()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', PORT))
s.listen(10)
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
if not data:
break
print(data)
received_data = data.decode().split(',')
if len(received_data) == 2:
angle, distance = map(float, received_data)
angle = np.deg2rad(angle)
if 0 <= angle <= 2*np.pi and 0 <= distance <= 100:
ax.clear()
ax.scatter(angle, distance, c='b', alpha=0.75)
ax.set_title("LiDAR Strength and Distance")
ax.set_ylim(0, 100) # ADJUST LIMIT
plt.pause(0.01)
def main():
print("test")
if __name__ == "__main__":
main()