天天看點

【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,如果這裡設定錯誤仿真的時候時間是會對不上的。

<?xml version="1.0"?>
   <launch>
      <param name="/use_sim_time" value="true" />
      <node name="cartographer_node"
            pkg="cartographer_ros"
            type="cartographer_node"
            args="-configuration_directory $(find cartographer_ros)/configuration_files -configuration_basename cartographer.lua"
            output="screen">
      </node>
      <node name="cartographer_occupancy_grid_node"
            pkg="cartographer_ros"
            type="cartographer_occupancy_grid_node" />
      <node name="robot_pose_publisher"
            pkg="robot_pose_publisher"
            type="robot_pose_publisher"
            respawn="false"
            output="screen" />
      <node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 base_link laser 100" />
   </launch>
           

我們還需要一個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,其實大多都是确實某個包,安裝上去就好了。

繼續閱讀