【cartographer+move_base】在gazebo中给px4添加激光雷达并接入ROS进行SLAM自动导航避障

1.按照官网教程安装好ROS+px4

http://dev.px4.io/en/setup/dev_env_linux_ubuntu.html

2.为了确保能加载正确的路径,在.bashrc中增加如下代码。(其中physics是你的用户名)

source /home/physics/src/Firmware/Tools/setup_gazebo.bash /home/physics/src/Firmware /home/physics/src/Firmware/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/physics/src/Firmware
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/physics/src/Firmware/Tools/sitl_gazebo
source /usr/share/gazebo-9/setup.sh
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/x86_64-linux-gnu/gazebo-9/plugins/

请注意:px4固件更新之后build目录下的文件夹变成了/px4_sitl_default

3.px4官方world里面有雷达的world,我们在launch文件里面正确加载就可以了

/home/physics/src/Firmware/launch/mavros_posix_sitl.launch

这里主要修改两处地方

 

 修改完成之后roslaunch的时候就能正确加载带有激光雷达的world了



   
    
    
    
    
    
    
    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
    
        
        
        
        
    

 4.我这里使用的建图算法是cartographer,如果要接入虚拟的激光雷达进行建图还需要修改坐标系名字以便于后面tf变换正确

/home/physics/src/Firmware/Tools/sitl_gazebo/models/rplidar/model.sdf

主要修改上面两行,其实关于整个雷达的描述以及配置最后构建的时候都是调用这个文件的,我们可以在这里修改我们需要的参数



  
    

      
        0 0 0 0 0 0
        0.19
        
          4.15e-6
          0
          0
          2.407e-6
          0
          2.407e-6
        
      

      
        
          
            0.02 0.05 0.05
          
        
      

      
        
          
            
              360
              1
              -3.14
              3.14
            
          
          
            0.2
            6
            0.05
          
          
            gaussian
            0.0
            0.01
          
        
        
        
          /scan
          laser
        
        1
        10
        true
      
    
  


/home/physics/catkin_ws/src/cartographer_ros/cartographer_ros/launch/cartographer.launch

这里主要修改一个地方,就是增加一个param,不然建图的时候会得不到正确的时间


   
      
      
      
      
      
     
      
      
      
     
     

   

/home/physics/catkin_ws/src/cartographer_ros/cartographer_ros/configuration_files/cartographer.lua

这里也是增加几个参数:

修改好之后如下:

include "map_builder.lua"
include "trajectory_builder.lua"

options = {

    map_builder = MAP_BUILDER,
    trajectory_builder = TRAJECTORY_BUILDER,
    map_frame = "map",
    tracking_frame = "base_link",
    published_frame = "base_link",
    odom_frame = "odom",
    provide_odom_frame = true,
    use_odometry = false,
    use_nav_sat = false,
    use_landmarks = false,
    publish_frame_projected_to_2d = false,
    num_laser_scans = 1,
    num_multi_echo_laser_scans = 0,
    num_subdivisions_per_laser_scan = 1,
    rangefinder_sampling_ratio = 1,
    odometry_sampling_ratio = 1,
    fixed_frame_pose_sampling_ratio = 1,
    imu_sampling_ratio = 1,
    landmarks_sampling_ratio = 1,
    num_point_clouds = 0,
    lookup_transform_timeout_sec = 0.2,
    submap_publish_period_sec = 0.3,
    pose_publish_period_sec = 5e-3,
    trajectory_publish_period_sec = 30e-3,
}

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.use_imu_data = false

TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true

POSE_GRAPH.optimization_problem.huber_scale = 1e2

TRAJECTORY_BUILDER_2D.num_accumulated_range_data = 10

return options

 5.启动

roslaunch px4 mavros_posix_sitl.launch
rosrun offb offb_node
roslaunch cartographer_ros cartographer.launch
roslaunch px4_navigation px4_nav.launch

【cartographer+move_base】在gazebo中给px4添加激光雷达并接入ROS进行SLAM自动导航避障_第1张图片

因为整个系统工程涉及模块较多,这这里难以一一展开记录等整个工程完成,会整理上传到github

你可能感兴趣的:(slam,PX4开发)