Interesting gameplay of radar obstacle avoidance

1. Program function description

After the program is started, the mechanical dog will move forward. When an obstacle appears within the detection range, it will adjust its posture to avoid the obstacle, and then continue to move forward. If the handle node is activated.

2. Program code reference path

The source code of this function is located at,

3. Program startup

3.1. Start command

PI4 version driver:

The mechanical dog chassis and radar have been set to start automatically at boot. If you find that they have not started, please enter in the terminal.

If the radar and chassis are started, you need to enter in the terminal:

PI5 version driver:

Open a terminal in the root directory of the Raspberry Pi and enter the following command to enter docker:

image-20240428121756691

Then enter the following command in the docker terminal to start the radar data:

Then enter the command to run the obstacle avoidance program, ** (PI5 version needs to enter the same docker to run, please refer to "Introduction and Use of Radar" for steps)**

3.2. View the topic communication node diagram

Terminal input, ** (PI5 version needs to run in the same docker, please refer to "Introduction and Use of Radar" for steps)**

image-20230421101717940

You can also set the parameter size through the dynamic parameter adjuster, terminal input, ** (PI5 version needs to run in the same docker, please refer to "Introduction and Use of Radar" for steps)**

image-20230421102655283

The meaning of each parameter is as follows:

Parameter nameParameter meaning
linearlinear speed
angularangular velocity
LaserAngleRadar detection angle
ResponseDistObstacle detection distance
SwitchGameplay switch

The above parameters are all adjustable. Except for Switch, the other four need to be set to decimals. After modification, click on the blank space to write.

4. Core source code analysis

Taking the X3 model and the source code of the A1 radar as an example, we mainly look at the callback function of the radar. Here is an explanation of how to obtain the obstacle distance information at each angle.