zlite/rplidar

i am having some issue with rplidar . can you please help me out ?

Opened this issue · 0 comments

i was trying to display the rplidar data in matplot animation. but there is no way that i can display. I will be so glad if you could have a look my code and let me the problem that i have:

here is the code:

`
from rplidar import RPLidar, RPLidarException
import matplotlib.pyplot as plt
import matplotlib.animation as animation

lidar = RPLidar('/dev/ttyUSB0')

info = lidar.get_info()
print(info)

health = lidar.get_health()
print(health)

fig = plt.figure()

ax = fig.add_subplot(1, 1, 1, projection='polar')

def run(i):
try:
angle = []
distance = []
for i, scan in enumerate(lidar.iter_scans()):

        for d in scan:  # d[0] : Quality of the measurement
            # if 0< d[1] <200:     #d[1] : Angle of the measurement
            #    print(d[2]/10)   #d[2] : Distance of the measurement '''
            angle.append(0.0174533 * d[1])
            distance.append(d[2])

        print('angle:', angle)
        ax.clear()
        ax.scatter(angle, distance, s=5)
        angle.clear()
        distance.clear()
except KeyboardInterrupt:
    print("Stopping...")
    lidar.stop()
    lidar.stop_motor()
    lidar.disconnect()

ani = animation.FuncAnimation(fig, run, interval=50)
plt.show(block=False)
`