1

I am using the RPLidar A1: https://www.adafruit.com/product/4010

My goal is to collect data sets and plot them in order to get a live visual representation of the data.

My current code is:

import numpy as np
import matplotlib.pyplot as plt
from rplidar import RPLidar

def get_data():
    lidar = RPLidar('COM6', baudrate=115200)
    for scan in lidar.iter_scans(max_buf_meas=500):
        break
    lidar.stop()
    return scan

for i in range(1000000):
    if(i%7==0):
        x = []
        y = []
    print(i)
    current_data=get_data()
    for point in current_data:
        if point[0]==15:
            x.append(point[2]*np.sin(point[1]))
            y.append(point[2]*np.cos(point[1]))
    plt.clf()
    plt.scatter(x, y)
    plt.pause(.1)
plt.show()

The above code produces a refreshing graph with changing data as shown below:

RPLidar A1: Real Time Data Plot

The issue is that this is not an accurate representation. There is a native application by SLAMTEC called frame_grabber which clearly shows this device giving accurate rectangular shaped representation of my room. Instead I keep getting a circular shape ranging from small to large.

The raw data from the sensor comes in the form of an array containing roughly 100 sets of the following data: (quality, theta, r). My code checks if the quality is good (15 is maximum), and then goes on to plot data sets and clears the data array every seven instances in order to get rid of old data.

I checked the raw polar data in excel and the data also appears to create a circularish shape.

LearnIT
  • 304
  • 1
  • 4
  • 21

1 Answers1

3

After a few days of trying out various libraries for plotting and trying a few other things I've noticed the mistake.

Hopefully this can prevent someone from making the same mistake in the future.

The lidars typically give data in terms of "theta" and "r". On the other hand the numpy as well as the built in math library in Python accept arguments in radians for performing cos and sin operations.

I've converted the units from degrees to radians and now everything works perfectly.

LearnIT
  • 304
  • 1
  • 4
  • 21