解决问题思维
- 明确自己想要的(编译安装cartographer);准备号基本的依赖环境确认版本直接编译即可(出错时,根据报错,缺什么解决什么即可)
- (github加速,非必须)如果有梯子,在终端运行该命令可以让终端走代理,使得github拉项目十倍速以上(最后的ip端口填写自己代理的ip端口即可,此处是在本机开的代理):git config --global http.proxy http://domain.local\vsilva:Passw0rd@127.0.0.1:7890
最简单方式——直接使用该脚本安装即可,想要看看详细的可以看后续的配置安装过程
#!/bin/bash
echo "delete cartographer_ws..."
sudo rm -rf ~/cartographer_ws/
mkdir -p ~/cartographer_ws/src
echo "add git proxy..."
read -p "please enter http_proxy addr and its port(eg. 127.0.0.1:7890):" HTTP_PROXY
git config --global http.proxy http://domain.local\vsilva:Passw0rd@$HTTP_PROXY
cd ~/cartographer_ws/src && git clone https://github.com/googlecartographer/cartographer_ros.git && git clone https://github.com/googlecartographer/cartographer.git
echo "install deps..."
sudo apt install -y libgflags-dev libgoogle-glog-dev liblua5.2-dev libsuitesparse-dev ninja-build stow
echo "install ceres-1.14.0..."
cd ~/cartographer_ws/ && git clone https://github.com/ceres-solver/ceres-solver.git && cd ceres-solver/ && git checkout 1.14.0 && mkdir build && cd build && cmake .. && make -j$proc && sudo make install
echo "install abseil.."
bash ~/cartographer_ws/src/cartographer/scripts/install_abseil.sh
echo "make cartographer.."
cd ~/cartographer_ws/ && catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash
一. 配置安装Cartographer
- 安装基本依赖库(默认大家均已安装ROS、Cmake)
sudo apt-get update &&
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblua5.2-dev libsuitesparse-dev
- 创建catkin_ws拉取相关项目功能包(以下工作空间可以自己选,此处是code/ws/slam下创建)
cd ~/code/ws && mkdir -p slam/cartographer_ws/src && cd ~/code/ws/slam/cartographer_ws/src
git clone https://github.com/googlecartographer/cartographer.git && git clone https://github.com/googlecartographer/cartographer_ros.git
- 安装ceres-1.14.0
cd ~/code/ws/slam/ && git clone https://github.com/ceres-solver/ceres-solver.git
cd ceres-solver && git checkout 1.14.0
mkdir build && cd build && cmake … && make -j$proc && sudo make install
- 安装absl(使用cartographer下的脚本安装即可)
sudo apt-get install stow -y
cd ~/code/ws/slam/cartographer_ws/src/cartographer/scripts && ./install_abseil.sh
- 安装protobuf-3.6.1(版本过高会报错)
- 直接编译即可,遇到错再说(只要依赖库版本没有问题就不会出错)
cd ~/code/ws/slam/cartographer_ws/
catkin_make_isolated -DPYTHON_EXECUTABLE=/usr/bin/python3
ps.上面这句指定python3编译只在装了conda时候用即可,未装则可不指定
-
成功安装(核心:找对依赖库版本)
-
使用官方数据包测试
source devel_isolated/setup.bash
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
二. 在gazebo仿真环境中使用cartographer算法建图并在建好的地图导航
-
编译cartographer(见教程一)
-
下载turtlebot并编译:
- cd ~/code/ws/slam/cartographer_ws/src
- git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
- git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
- git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
- cd …
- catkin_make_isolated -DPYTHON_EXECUTABLE=/usr/bin/python3
- 设置环境变量:
- echo “export TURTLEBOT3_MODEL=burger” >> ~/.bashrc
- source ~/.bashrc
- source /devel_isolated/setup.bash
- 修改launch文件
- catkin_ws/src/turtlebot3/turtlebot3_slam/launch/turtlebot3_cartographer.launch文件,把$(arg configuration_basename)更改为turtlebot3_lds_2d_gazebo.lua
- 打开仿真gazebo仿真环境:
- source devel_isolated/setup.bash
- roslaunch turtlebot3_gazebo turtlebot3_world.launch
- 使用cartographer算法建图
- roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
- 使用键盘控制Turtlebot3运动
- source devel_isolated/setup.bash
- roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
- 保存地图
- rosrun map_server map_saver -f ~/map
- 点击2D Nav Goal,设置目标点,导航
SUM:
- 遇到一些版本不符,只是API名称的一个改变什么的,切换版本不行的话,最简答的办法是直接修改源代码和当前版本契合即可。