一、前提介绍:
本文主要采用两种方式在NVIDIA 下基于 Ubuntun20.04安装 ros2-foxy。
使用环境:
NVIDIA 为 Jetson 系列下 Jetson Xavier NX;
Ubuntun版本:20.04
二、安装方法:
1、使用脚本编译方式:
使用执行下列脚本进行安装:
bash
#!/bin/bash
#
# Copyright (c) 2021 Jetsonhacks
# MIT License
# Roughly follows the 'Install ROS From Source' procedures from:
# https://index.ros.org/doc/ros2/Installation/Foxy/Linux-Development-Setup/
# mostly from:
# Dockerfile.ros.foxy
# https://github.com/dusty-nv/jetson-containers
#
ROS_PKG=ros_base
ROS_DISTRO=foxy
# Core ROS2 workspace - the "underlay"
ROS_BUILD_ROOT=/opt/ros/${ROS_DISTRO}-src
ROS_INSTALL_ROOT=/opt/ros/${ROS_DISTRO}
locale # check for UTF-8
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
# Add the ROS 2 apt repository
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
curl \
wget \
gnupg2 \
lsb-release
sudo rm -rf /var/lib/apt/lists/*
wget --no-check-certificate https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc
sudo apt-key add ros.asc
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
# install development packages
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
libbullet-dev \
libpython3-dev \
python3-colcon-common-extensions \
python3-flake8 \
python3-pip \
python3-pytest-cov \
python3-rosdep \
python3-setuptools \
python3-vcstool \
python3-rosinstall-generator \
libasio-dev \
libtinyxml2-dev \
libcunit1-dev
sudo rm -rf /var/lib/apt/lists/*
# install some pip packages needed for testing
python3 -m pip install -U \
argcomplete \
flake8-blind-except \
flake8-builtins \
flake8-class-newline \
flake8-comprehensions \
flake8-deprecated \
flake8-docstrings \
flake8-import-order \
flake8-quotes \
pytest-repeat \
pytest-rerunfailures \
pytest
# compile yaml-cpp-0.6, which some ROS packages may use (but is not in the 18.04 apt repo)
git clone --branch yaml-cpp-0.6.0 https://github.com/jbeder/yaml-cpp yaml-cpp-0.6 && \
cd yaml-cpp-0.6 && \
mkdir build && \
cd build && \
cmake -DBUILD_SHARED_LIBS=ON .. && \
make -j$(nproc) && \
sudo cp libyaml-cpp.so.0.6.0 /usr/lib/aarch64-linux-gnu/ && \
sudo ln -s /usr/lib/aarch64-linux-gnu/libyaml-cpp.so.0.6.0 /usr/lib/aarch64-linux-gnu/libyaml-cpp.so.0.6
# https://answers.ros.org/question/325245/minimal-ros2-installation/?answer=325249#post-id-325249
sudo mkdir -p ${ROS_BUILD_ROOT}/src && \
cd ${ROS_BUILD_ROOT}
sudo sh -c "rosinstall_generator --deps --rosdistro ${ROS_DISTRO} ${ROS_PKG} launch_xml launch_yaml example_interfaces > ros2.${ROS_DISTRO}.${ROS_PKG}.rosinstall && \
cat ros2.${ROS_DISTRO}.${ROS_PKG}.rosinstall && \
vcs import src < ros2.${ROS_DISTRO}.${ROS_PKG}.rosinstall"
# download unreleased packages
sudo sh -c "git clone --branch ros2 https://github.com/Kukanani/vision_msgs ${ROS_BUILD_ROOT}/src/vision_msgs && \
git clone --branch ${ROS_DISTRO} https://github.com/ros2/demos demos && \
cp -r demos/demo_nodes_cpp ${ROS_BUILD_ROOT}/src && \
cp -r demos/demo_nodes_py ${ROS_BUILD_ROOT}/src && \
rm -r -f demos"
# install dependencies using rosdep
sudo apt-get update
cd ${ROS_BUILD_ROOT}
sudo rosdep init
rosdep update && \
rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y --skip-keys "console_bridge fastcdr fastrtps rti-connext-dds-5.3.1 urdfdom_headers qt_gui" && \
sudo rm -rf /var/lib/apt/lists/*
# build it!
sudo mkdir -p ${ROS_INSTALL_ROOT}
# sudo required to write build logs
sudo colcon build --merge-install --install-base ${ROS_INSTALL_ROOT}
# We do this twice to make sure everything gets built
# For some reason, this has been an issue
sudo colcon build --merge-install --install-base ${ROS_INSTALL_ROOT}
# Using " expands environment variable immediately
echo "source $ROS_INSTALL_ROOT/setup.bash" >> ~/.bashrc
echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
echo "export _colcon_cd_root=~/ros2_install" >> ~/.bashrc
脚本安装完毕后,默认会在在/opt/ros/目录下,生成foxy和foxy-src文件夹,foxy为编译后的程序;
使用source 将对应 foxy文件夹里面加载到环境变量中:
bash
source /opt/ros/foxy/setup.bash
然后 运行 ros2 --help 如果不报错就代表安装成功。
2、使用docker安装ros2-foxy
2.1 安装docker命令
依次执行下列命令:
bash
sudo apt-get update # 更新软件列表
sudo apt-get install -y docker.io #安装docker
systemctl start docker #配置开机启动
systemctl enable docker
sudo docker --version #检测是否安装成功
2.2 下载启动 ros镜像
执行下列命令:
bash
docker pull aigrobv/ros-foxy:ci@sha256:035df49e8f307946a10b73d307ac2c35ce0c08ea2da5a824dbdaa4952fcf06ed
#sudo docker pull osrf/ros:foxy-desktop //下载ROS镜像,如果需要arm架构,可以修改对应镜像
# https://hub.docker.com/layers/aigrobv/ros-foxy/ci/images/sha256-146d88b0137f260f442d1c0b77b749237b392358d44476074829ff880f705e6e
sudo docker images #查看镜像信息
sudo docker run -it osrf/ros:foxy-desktop #启动镜像
ros2 -h #查看ROS2的帮助信息,如不报错则代表安装成功
三、总结:
本文在NVIDIA 使用了 Ubuntun20.04环境下 脚本编译安装 ros2-foxy 和 使用docker安装 ros-foxy的两种方式,相对来说,docker方式简单一点,推荐docker方式安装。