编译安装ROS2

编译安装ROS2

添加 ROS 2 apt 存储库

sudo apt update && sudo apt install curl gnupg2 lsb-release

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

然后将存储库添加到源列表

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'

安装开发工具和ROS工具

sudo apt update

sudo apt install -y \
  build-essential \
  cmake \
  git \
  python3-colcon-common-extensions \
  python3-pip \
  python-rosdep \
  python3-vcstool \
  wget
# install some pip packages needed for testing
python3 -m pip install -U \
  argcomplete \
  flake8 \
  flake8-blind-except \
  flake8-builtins \
  flake8-class-newline \
  flake8-comprehensions \
  flake8-deprecated \
  flake8-docstrings \
  flake8-import-order \
  flake8-quotes \
  pytest-repeat \
  pytest-rerunfailures \
  pytest \
  pytest-cov \
  pytest-runner \
  setuptools
# install Fast-RTPS dependencies
sudo apt install --no-install-recommends -y \
  libasio-dev \
  libtinyxml2-dev
# install Cyclone DDS dependencies
sudo apt install --no-install-recommends -y \
  libcunit1-dev

获取 ROS 2 代码

创建工作区并克隆所有存储库

mkdir -p ~/ros2_eloquent/src
cd ~/ros2_eloquent
wget https://raw.githubusercontent.com/ros2/ros2/eloquent/ros2.repos
vcs import src < ros2.repos

使用 rosdep 安装依赖项

sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro eloquent -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 libopensplice69 rti-connext-dds-5.3.1 urdfdom_headers"

在工作区中构建代码

cd ~/ros2_eloquent/
colcon build --symlink-install

注意:如果出现了下载失败的问题

CMake Error at uncrustify-0.68.1-stamp/download-uncrustify-0.68.1.cmake:159 (message):
  Each download failed!

    error: downloading 'https://github.com/uncrustify/uncrustify/archive/45b836cff040594994d364ad6fd3f04adc890a26.tar.gz' failed
         status_code: 1
         status_string: "Unsupported protocol"
         log:
         --- LOG BEGIN ---
         Protocol "https" not supported or disabled in libcurl

  Closing connection -1

是cmake和curl的问题,请重新编译cmake

wget https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2.tar.gz
tar -zxvf cmake-3.13.2.tar.gz
cd cmake-3.13.2
./bootstrap --system-curl -- -DCMAKE_BUILD_TYPE:STRING=Release
make -j128 
sudo make install

编译完成设置环境变量

echo "source ~/ros2_galactic/install/local_setup.bash" >> ~/.bashrc

source ~/.bashrc

此时已经完成编译和环境变量设置

测试

ros2 run demo_nodes_cpp talker

# 打开另一种终端
ros2 run demo_nodes_py listener
posted @ 2022-09-09 16:03  nanmi  阅读(265)  评论(0编辑  收藏  举报