Skip to content

Commit

Permalink
Added dummy lidar listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Mannvika committed Apr 24, 2024
1 parent bc26137 commit 25ebf24
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions LIDARListener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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")
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:
strength, distance = map(float, received_data)
ax.clear()
ax.scatter(angles, np.full_like(angles, distance), c=np.full_like(angles, strength), cmap='viridis',
alpha=0.75)
ax.set_title("LiDAR Strength and Distance")
plt.draw()
plt.pause(0.001)
print("Strength:", strength, "Distance:", distance)


def main():
print("test")

if __name__ == "__main__":
main()

0 comments on commit 25ebf24

Please sign in to comment.