Read radar data

1. Experimental purpose

Use the radar interface of the microROS control board to learn ESP32 to read the MS200 lidar data through serial port 1 and parse the radar data packets.

 

2. Hardware connection

As shown in the figure below, the microROS control board integrates the MS200 lidar interface. You need to connect the MS200 lidar cable to the microROS control board and lidar. You also need to connect the type-C data cable to the computer and the microROS control board as a burning Firmware features.

image-20240112163507890

The MS200 lidar interface cable has an anti-reverse connection function and can be inserted directly into the interface.

image-20240112173042656

 

3. Core code analysis

The virtual machine path corresponding to the program source code is as follows

Since the MS200 lidar uses serial port communication, serial port 1 of ESP32S3 is selected to communicate with the MS200 lidar. UART1_GPIO_TXD of serial port 1 corresponds to hardware GPIO17, UART1_GPIO_RXD of serial port 1 corresponds to hardware GPIO18, and the baud rate is set to 230400.

MS200 lidar analyzes system messages.

MS200 lidar parses point cloud data packets based on the received protocol data.

According to the point cloud data package, the relevant angle data is extracted. Special processing is added here. When the scanning angle passes from before 360 degrees to after 0 degrees, the angle value needs to be converted.

Get data from MS200 lidar.

Create a new task of MS200 lidar analysis data and extraction of radar data.

Read the distance detected by the MS200 lidar at a certain point, in millimeters.

In app_main, call the Uart1_Init function to initialize serial port 1 and Lidar_Ms200_Init to initialize the lidar. Then, in the loop, read the distances of the MS200 lidar in the four directions of 0 degrees, 90 degrees, 180 degrees, and 270 degrees every 200 milliseconds, and print them out.

 

4. Compile and download the burning firmware

Use a Type-C data cable to connect the virtual machine/computer and the microROS control board. If the system pops up, choose to connect to the virtual machine.

Activate the ESP-IDF development environment. Note that every time you open a new terminal, you need to activate the ESP-IDF development environment before compiling the firmware.

Enter the project directory

Compile, flash, and open the serial port simulator

If you need to exit the serial port simulator, press Ctrl+].

 

5. Experimental results

The serial port simulator prints the "hello yahboom" greeting. And every 200 milliseconds, the distance detected by the MS200 lidar in four directions of 0 degrees, 90 degrees, 180 degrees, and 270 degrees is printed. Among them, the direction indicated by the MS200 lidar arrow is 0 degrees, and the angle increases clockwise. At this time, you can block one of the directions with your hand and observe its numerical changes.

image-20240116145434323

image-20240112173837427