Linux|移植安装cartographer_ros

安装ros(kinetic):
1.添加ros到更新源:


2.添加key:
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

3.更新一下软件库:
sudo apt-get update

4.安装ros:
sudo apt-get install ros-kinetic-desktop-full

5.安装完成后更新一下rosdep:

sudo rosdep init rosdep update

6.添加环境变量
全局:

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc source ~/.bashrc


针对当前shell

source /opt/ros/kinetic/setup.bash


7.安装开发支持包:

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential


【Linux|移植安装cartographer_ros】OK!


安装cartographer_ros:
1.安裝wstool和rosdep:
sudo apt-get install -y python-wstool python-rosdep ninja-build
2.新建工作空間,這裏使用catkin_ws:
mkdir catkin_ws
cd catkin_ws
wstool init src
3.下载
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src

在update的时候,下载cere-solver失败,可能是没有的原因,不过cartographer和cartographer_ros都行下载成功了,ceres-solver手动下载即可:
https://github.com/ceres-solver/ceres-solver.git
下载下来之后我使用zip的方式下到电脑上,然后解压得到ceres-solver-master文件夹,改名为ceres-solver后放到catkin工作空间的src下面,然后:
rosdep install --from-paths src --ignore-src --rosdistro kinetic -y
就会开始安装一些东西,可能前面会有关于ceres-solver的警告,不过不影响后面的进度。接下来开始安装:
1.切换到root用户下
sudo su
2.更新环境变量使root用户可以使用catkin_make_isolated命令(参考http://wiki.ros.org/catkin/commands/catkin_make)
source /opt/ros/kinetic/setup.bash
3.安装
catkin_make_isolated --install --use-ninja
在编译过程中,编译cartographer的时候,遇到字符编码错误?提示locale error,为en。看来没装en的编码:
先安装:
locale-gen en_US.UTF-8
vim /etc/default/locale
改成:
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
然后保存后退出,安装
update-locale
locale
locale -a
都可以查看下信息,记得重启。


最后嵌入式机器上可能在编译cc的时候一直提示c++错误,大概是内存不够的意思,这个时候建议切换到具体源码下,直接用ninja来编译,出错就重启,重复此操作,直到单一源码编译通过,不过后来网上查了下有个方法可增加虚拟内存,亲测有效:
1. 创建分区文件,大小 2G
dd if=/dev/zero of=/swapfile bs=1kcount=2048000
2. 生成 swap文件系统
mkswap /swapfile
3. 激活 swap文件
swapon /swapfile
4. 修改 /etc/fstab文件,新增如下内容:
/swapfile swap swap defaults 0 0
catkin_make_isolated--install--use-ninja
这命令并不会重复编译所以不必担心之前编译的被忽略。
看到这个命令圆满执行成功,心里终于踏实了,先运行下面的命令更新cartographer安装
source install_isolated/setup.bash


下面准备开始运行demo。
可以用命令下载:
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
我是在PC上直接下载,速度够快,在网页中直接输入:
https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
上面是个2d的demo大概400m多,下完之后放到/home/ubuntu/slam下面,目录自定,然后运行:
roslaunch cartographer_rosdemo_backpack_2d.launchbag_filename:=/home/ubuntu/slam/cartographer_paper_deutsches_museum.bag
后面就会有图形界面出来了,一运行就开始在slam了,就像之前视频里看到其他大神的那样。


其他DEMO的链接:
# Download the 2D backpack example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag


# Launch the 2D backpack demo.
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag


# Download the 3D backpack example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag


# Launch the 3D backpack demo.
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag


# Download the Revo LDS example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/revo_lds/cartographer_paper_revo_lds.bag


# Launch the Revo LDS demo.
roslaunch cartographer_ros demo_revo_lds.launch bag_filename:=${HOME}/Downloads/cartographer_paper_revo_lds.bag


# Download the PR2 example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/pr2/2011-09-15-08-32-46.bag


# Launch the PR2 demo.
roslaunch cartographer_ros demo_pr2.launch bag_filename:=${HOME}/Downloads/2011-09-15-08-32-46.bag


# Download the Taurob Tracker example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/taurob_tracker/taurob_tracker_simulation.bag


# Launch the Taurob Tracker demo.
roslaunch cartographer_ros demo_taurob_tracker.launch bag_filename:=${HOME}/Downloads/taurob_tracker_simulation.bag


    推荐阅读