Based on Ubuntu18.04+ROS Melodic to build SLAM car host computer (Raspberry Pi)


1. The function package and serial port used

1. Feature Pack

This project uses several open source project function packages to implement SLAM mapping and navigation based on lidar. The code used can be downloaded on Code Cloud .

The function package needs to be saved and compiled on the master and slave.

2. Serial port

In this project, the Raspberry Pi is used as the upper computer for development, and the radar and the lower computer need to be serially communicated with the Raspberry Pi. Through the test here, the serial port of my radar is /dev/ttyUSB1 , and the serial port of the lower computer is /dev/ttyUSB0 .

If you don't know your serial port, you can check the serial port used by plugging and unplugging the device and then using the command ls /dev/ttyUSB* .

You need to modify the following files according to your actual situation:

Lower computer serial port

Modify the file bringup.launch in the launch folder under the function package zxcar , and place your serial port number as shown in the figure below.
Insert picture description here

Radar serial port

Modify the file rplidar.launch in the folder launch/lidar under the function package zxcar , and fill in your radar serial port into the position in the figure below.
Insert picture description here

Two, create workspace and compile

1. Create a workspace

Create a new workspace and place the downloaded function package into the folder src under it.
Insert picture description here

2. Compile

Compile in the workspace. An error may appear during the first compilation. Just download the dependencies according to the error prompt.
Insert picture description here

For details, please refer to: ROS dependency package installation problem

Here, use the command sudo apt-get install ros-melodic-geographic-msgs to install the required dependencies, and then compile again.
Insert picture description here

3. Permission

To run python files in linux, you need to give them executable permissions. In order to reduce trouble, run the command **sudo chmod -R +x src/** to give executable permissions to all the files in the function package.
Insert picture description here

4. Refresh the environment

In order to facilitate the subsequent running of the ROS program, there is no need to repeatedly refresh the environment, this time the source command is written into the .bashrc file to ensure that the refresh is directly performed every time the command line is opened.

sudo vi ~/.bashrc

Write the content at the end of the file:

source ~/ws/devel/setup.bash

Insert picture description here

Three, calibration

As imu may have problems such as tilt during installation, calibration is required.

1. Calibrate imu

First, start the bringup.launch file under the zxcar function package on the Raspberry Pi side (host side) . When the words "zxcar_driver start success!" appear , it means the startup is successful.

roslaunch zxcar bringup.launch

Insert picture description here

Then start another command line and continue to start the do_calib node on the host side to perform imu calibration. When doing this, the car should rest flat on the ground, do not touch the car by hand to ensure calibration accuracy.

rosrun imu_calib do_calib

Insert picture description here

Follow the prompts Press [ENTER] once done. Press the Enter key to proceed to the next measurement. A total of six measurements are required.
Insert picture description here
After the calibration is completed, the file imu_calib.yaml will be generated in the current directory. This file needs to be replaced with the file with the same name in the /zxcar/param/imu directory.

roscd zxcar/param/imu/
sudo rm -rf imu_calib.yaml 
mv ~/imu_calib.yaml ~/ws/src/zxcar/param/imu/

Insert picture description here

2. Calibrate the angular velocity

Start the bringup.launch file under the zxcar function package on the Raspberry Pi side (host side) and open the command line to start the calibrate_angular node. When the words "Bring up rqt_reconfigure to control the test." appear , it means that the startup is successful.
Insert picture description here
Start the rqt tool on the PC side (slave side) according to the prompts.

rosrun rqt_reconfigure rqt_reconfigure 

Insert picture description here

The parameters that can be modified here are as follows:

  • test_angle: test the angle of rotation
  • speed: test the speed of rotation
  • tolerance: the error range of the test

Keep the default parameters unchanged, bring up the mobile phone compass and square it above the car, record the current angle value and check start_test to start the test and record the final angle on the mobile phone, and calculate the rotation angle of the car.
Insert picture description here
Here my car is rotated by 355 degrees, so I use 355/360 to calculate the zoom factor. Measure the effect of rotation again, and fill in the bringup.launch file with the average number of multiple measurements.

roscd zxcar/launch/
sudo vi bringup.launch 

Insert picture description here

3. Calibrate the line speed

Similarly, the line speed needs to be calibrated. In the
host, run the following commands in two command lines:

roslaunch zxcar bringup.launch
rosrun zxcar_nav calibrate_linear.py

After the Bring up rqt_reconfigure to control the test. prompt appears, run the rqt tool on the slave

rosrun rqt_reconfigure rqt_reconfigure

Insert picture description here
Also click start_test to test, and measure the walking distance of the trolley with a tape measure. Here I measured 1.02 meters walked, divided by 1 meter, and filled the resulting zoom factor into the bringup.launch file.

roscd zxcar/launch/
sudo vi bringup.launch 

Insert picture description here

Fourth, radar mapping and navigation

After the calibration is completed, the radar mapping work can be carried out.

1. Build a map

Launch the lidar_slam.launch file in the host

roslaunch zxcar lidar_slam.launch

The first startup error is as follows, and the relevant dependencies need to be installed.

sudo apt-get install ros-melodic-gmapping
sudo apt-get install ros-melodic-move-base
sudo apt-get install ros-melodic-amcl
sudo apt-get install ros-melodic-map-server
sudo apt-get install ros-melodic-global-planner
sudo apt-get install ros-melodic-dwa-local-planner

Insert picture description here
After the installation is complete, run it again, and the word odom received! appears to indicate a successful startup.
Insert picture description here

Then you need to run the lidar_slam_rviz.launch file on the slave to start the RVIZ interface and start the node teleop_twist_keyboard at the same time .

roslaunch zxcar lidar_slam_rviz.launch
rosrun teleop_twist_keyboard teleop_twist_keyboard.py

Insert picture description here

The node teleop_twist_keyboard is used to control the car to walk, and the method of use is the same as the prompt:
Insert picture description here
by manipulating the car to walk, you can see the effect of the map creation in RVIZ.
Insert picture description here

2. Save the drawing

After building a radar map by manipulating the car to walk, you need to save the created map under zxcar/maps .

Run the following command from the machine to save the drawing.

roscd heimarobot/maps
rosrun map_server map_saver -f house

After saving, you can stop the lidar_slam.launch file on the host.

3. Navigation

Run the following commands on the slave, and the words **odom received!** are also displayed, which means the startup is successful.

roslaunch zxcar navigate.launch

Run the command on the host to start RVIZ

roslaunch zxcar navigate_rviz.launch

Insert picture description here

At this time, you need to use the 2D Pose Estimate brush in the toolbar above RVIZ to calibrate the initial position of the car, and then use 2D Nav Goal to navigate.

Guess you like

Origin blog.csdn.net/weixin_45929038/article/details/114061424