typora-root-url: /home/msj/ubuntu笔记本台式机环境配置说明/images
Ubuntu18.04 配置
说明:我们所有文档配置都是按照ubuntu18.04,保证x86架构(笔记本台式机)和 ARM架构(jetson Nano只能安装18.04)的一致性
1. 更换各类源
我们所有源都更换清华源, 如有问题请参考官网
1.1 ubuntu
Ubuntu 的软件源配置文件是 /etc/apt/sources.list
。将系统自带的该文件做个备份,将该文件替换为清华源,即可使用选择的软件源镜像。
# 备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
#打开文件,内容更换成下面内容并保存
sudo gedit /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
2.安装ROS-Melodic
- 设置清华源的source.list
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
- 设置GPG Key,并更新
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
- 安装桌面完整版
sudo apt install ros-melodic-desktop-full
如果安装额外的其他包,用下面命令
sudo apt install ros-melodic-PACKAGE_NAME
- 设置环境变量,令每个终端窗口都可以启动ros
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
- 安装依赖
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
- 初始化rosdep
sudo rosdep init
Bug1 - 会出现错误:这个错误是因为网络无法连接,无法下载20-default.list文件
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
Solution1 - 我们参考清华源处理方法,也有其他更改下载链接方法,请自行百度。
# 手动模拟 rosdep init
sudo mkdir -p /etc/ros/rosdep/sources.list.d/
sudo curl -o /etc/ros/rosdep/sources.list.d/20-default.list https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
# 为 rosdep update 换源
export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml
rosdep update
# 每次 rosdep update 之前,均需要增加该环境变量
# 为了持久化该设定,可以将其写入 .bashrc 中,例如
echo 'export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml' >> ~/.bashrc
#更新
rosdep update
出现以下输出:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/base.yaml
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/python.yaml
Hit https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/ruby.yaml
Query rosdistro index https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Skip end-of-life distro "foxy"
Skip end-of-life distro "galactic"
Skip end-of-life distro "groovy"
Add distro "humble"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Add distro "iron"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Skip end-of-life distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/msj/.ros/rosdep/sources.cache
- 测试是否安装成功,打开roscore
roscore
出现以下输出,显示ros证明安装成功.
3. 安装cartographer-ros
介绍
cartographer_ros的安装、编译、与运行
软件架构
cartographer_install:cartographer的依赖安装包、源码安装包、安装脚本
cartographer_ros_ws/src/cartographer:cartographer的源码(如果之后需要修改carto的算法,需要在这里修改)
cartographer_ros_ws/src/cartographer_ros:cartographer的ros接口
安装
-
如果之前安装过这些库,删除系统中之前安装过的相关依赖库。
cd /usr/local/include sudo rm -rf absl sudo rm -rf ceres sudo rm -rf cartographer cd google sudo rm -rf protobuf
-
卸载ros自带的proto2
sudo apt-get remove libprotobuf-dev
-
安装一些系统依赖
sudo apt-get install \ clang \ cmake \ g++ \ git \ google-mock \ libboost-all-dev \ libcairo2-dev \ libcurl4-openssl-dev \ libeigen3-dev \ libgflags-dev \ libgoogle-glog-dev \ liblua5.2-dev \ libsuitesparse-dev \ lsb-release \ ninja-build \ stow \ python-wstool \ python-rosdep \ python-sphinx \ libatlas-base-dev
-
安装cartographer_install中的依赖库
- 如果之前安装过,需要事先删除依赖库中的build文件夹.
- 最好不要使用脚本安装,最好手动安装,以看出每一步安装的具体报错.
cd cartographer_install # Build and install abseil-cpp set -o errexit set -o verbose cd abseil-cpp git checkout d902eb869bcfacc1bad14933ed9af4bed006d481 mkdir build cd build cmake -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DCMAKE_INSTALL_PREFIX=/usr/local/stow/absl \ .. ninja sudo ninja install cd /usr/local/stow sudo stow absl # Build and install Ceres. 注意使用ninja编译可能失败 因为板子性能限制 cd - cd ../../ceres-solver mkdir build cd build cmake .. -G Ninja -DCXX11=ON ninja #CTEST_OUTPUT_ON_FAILURE=1 ninja test sudo ninja install # 如果ninja编译卡死则用cmake编译, 如果上述步骤通过,忽略此步骤 cd .. rm -rf build mkdir build cd build cmake .. make sudo make install # Build and install proto3. cd ../../protobuf mkdir build cd build cmake -G Ninja \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DCMAKE_BUILD_TYPE=Release \ -Dprotobuf_BUILD_TESTS=OFF \ ../cmake
装arm的:
cd …
把autogen.sh文件的属性改成可执行文件
./autogen.sh
./configure --host=arm-linux --with-protoc=protoc
make
sudo make install
ninja
sudo ninja install
Build and install Cartographer.
cd …/…/cartographer
mkdir build
cd build
cmake … -G Ninja
ninja
#CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install
#### 编译
建立工作空间,并将我们准备的src(包含多个功能包的文件夹)拷贝到工作空间下(以后只需要修改cartographer_ros,即.launch和.lua文件)
```shell
# 创建工作空间
mkdir ~/msj_ws
# 将我们src拷贝到工作空间下
cp YOUR_PATH/src ~/msj_ws
catkin_make
https://google-cartographer-ros.readthedocs.io/en/latest/demos.html