安裝 slam

Set Up a Catkin Workspace and Install RPLIDAR ROS Packages

  1. Update the package list
    ​​​​sudo apt-get update
    
  2. Install the following dependencies
    ​​​​sudo apt-get install cmake python-catkin-pkg python-empy python-nose python-setuptools libgtest-dev python-rosinstall python-rosinstall-generator python-wstool build-essential git
    
  3. Create the catkin workspace
    ​​​​mkdir -p ~/catkin_ws/src
    ​​​​cd ~/catkin_ws/
    
  4. edit the .bashrc text file
    ​​​​gedit ~/.bashrc
    
sudo apt-get install gedit
  1. Make sure these two lines are at the end of the .bashrc file

    ​​​​source /opt/ros/melodic/setup.bash
    ​​​​source ~/catkin_ws/devel/setup.bash
    
  2. Save the file, and close it

    ​​​​source ~/catkin_ws/devel/setup.bash
    ​​​​cd src
    
  3. Clone the RPLIDAR and go to the root of the workspace

    ​​​​sudo git clone https://github.com/Slamtec/rplidar_ros.git
    ​​​​cd ~/catkin_ws/
    ​​​​catkin_make
    
  4. change error

    ​​​​cd ~/catkin_ws/src/rplidar_ros/src
    ​​​​sudo chmod +x node.cpp
    ​​​​sudo gedit node.cpp
    
    • chage this
      • ROS_INFO("RPLIDAR running on ROS package rplidar_ros. SDK Version:"RPLIDAR_SDK_VERSION"");
    • to this
      • ROS_INFO("RPLIDAR running on ROS package rplidar_ros. SDK Version:" RPLIDAR_SDK_VERSION "");
  5. Go to the root of the workspace and compile workspace

    ​​​​cd ~/catkin_ws/
    ​​​​catkin_make
    
  6. Launch the RPLIDAR launch file

    ​​​​roslaunch rplidar_ros rplidar.launch
    ​​​​rostopic list
    
  7. see LIDAR data

    ​​​​rostopic echo /scan
    

Run rviz

  1. Launch RPLIDAR
    ​​​​roslaunch rplidar_ros rplidar.launch
    
  2. launch rviz
    ​​​​rviz
    

Download the Hector-SLAM Package

  1. Move to your catkin workspace’s source folder

    ​​​​cd ~/catkin_ws/src
    
  2. download the Hector-SLAM package

    ​​​​git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git
    
  3. Go to the launch file for Hector-SLAM. All of this below is a single command

    ​​​​sudo gedit ~/catkin_ws/src/hector_slam/hector_mapping/launch/mapping_default.launch
    
    • change this
      ​​​​​​​​<arg name="base_frame" default="base_footprint"/>
      ​​​​​​​​<arg name="odom_frame" default="nav"/>
      
    • to this
      ​​​​​​​​<arg name="base_frame" default="base_link"/>
      ​​​​​​​​<arg name="odom_frame" default="base_link"/>
      
    • change this
      ​​​​​​​​<!--<node pkg="tf" type="static_transform_publisher" name="map_nav_broadcaster" args="0 0 0 0 0 0 map nav 100"/>-->
      
    • to this
      ​​​​​​​​<node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 base_link laser 100"/>
      
  4. Type the following command

    ​​​​cd ~/catkin_ws/src/hector_slam/hector_slam_launch/launch
    
  5. Open the tutorial.launch file

    ​​​​gedit tutorial.launch
    
    • change this
      ​​​​​​​​<param name="/use_sim_time" value="true"/>
      
    • to this
      ​​​​​​​​<param name="/use_sim_time" value="false"/>
      
  6. Save the file, and close it

cd ~/catkin_ws/
catkin_make