【px4室内slam定位导航】之搭建Cartographer环境

一、安装相关依赖包

sudo apt-get install ros-kinetic-tf ros-kinetic-tf-conversions ros-kinetic-laser-geometry
sudo apt-get install ros-kinetic-cv-bridge ros-kinetic-image-transport
sudo apt-get install qt4-qmake qt4-dev-tools
sudo apt-get install protobuf-compiler
sudo apt-get install python-wstool python-rosdep ninja-build

二、创建工作空间并下载源码

cd $HOME
mkdir -p catkin_ws/src
cd catkin_ws
catkin_init_workspace
wstool init src
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall

这里请注意:如果没有外网是下载不了Google自家的数据处理库——ceres-solver的

我们打开src下的隐藏文件.rosinstall看看,然后把ceres-solver的github地址换成国内的,换完之后如下

# THIS IS AN AUTOGENERATED FILE, LAST GENERATED USING wstool ON 2019-04-24
- git:
    local-name: cartographer
    uri: https://github.com/googlecartographer/cartographer.git
    version: 1.0.0
- git:
    local-name: cartographer_ros
    uri: https://github.com/googlecartographer/cartographer_ros.git
    version: 1.0.0
- git:
    local-name: ceres-solver
    uri: https://github.com/ceres-solver/ceres-solver.git
    version: 1.14.0

改完之后就可以下载了:

wstool update -t src

下载完之后我们还需要安装proto3,相关操作请看另外一篇文章

https://blog.csdn.net/weixin_40599145/article/details/89061073

三、安装一个tf转换包直接可以发布机器人的位置信息

这是论坛上对这个包的一些描述:http://wiki.ros.org/robot_pose_publisher

cd $HOME/catkin_ws/src
git clone https://github.com/GT-RAIL/robot_pose_publisher.git
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

 

四、创建slam的launch文件

cd $HOME/catkin_ws/src/cartographer_ros/cartographer_ros/launch
gedit cartographer.launch

 这里直接贴出我的launch文件,这里要注意的是/use_sim_time这里,如果是gazebo仿真就设置为true,如果直接上真机就设置为false,如果这里设置错误仿真的时候时间是会对不上的。


   
      
      
      
      
      
      
   

我们还需要一个lua文件,这个文件是对建图参数设置

cd $HOME/catkin_ws/src/cartographer_ros/cartographer_ros/configuration_files
gedit 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

return options

五、编译

catkin_make_isolated --install --use-ninja 

编译过程中肯定还有很多bug,其实大多都是确实某个包,安装上去就好了。

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