SkoltechRobotics / rplidar

Python module for RPLidar A1 and A2 rangefinder scanners
MIT License
185 stars 126 forks source link

animation is not working #21

Open shahin4u000 opened 5 years ago

shahin4u000 commented 5 years ago

Its been almost one month and i could not find a way to animate the graph which will show the surrounding. can you please tell me where should i do the modification?

`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): 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()

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

`

claymaks commented 4 years ago

Can you share the error you are getting?