ubuntu 20.04源码编译安装ros2 humble

虚拟机

官网下载ubuntu-20.04.6-desktop-amd64.iso,创建新的虚拟机,虚拟机配置如下

配置及安装

源配置

启用Ubuntu Universe存储库

sudo apt install software-properties-common
sudo add-apt-repository universe

添加带有apt的ros2 GPG秘钥

sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

添加存储库到源列表

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

安装开发工具及ros工具

sudo apt update && sudo apt install -y \
  python3-flake8-docstrings \
  python3-pip \
  python3-pytest-cov \
  ros-dev-tools

安装软件包

python3 -m pip install -U \
   flake8-blind-except \
   flake8-builtins \
   flake8-class-newline \
   flake8-comprehensions \
   flake8-deprecated \
   flake8-import-order \
   flake8-quotes \
   "pytest>=5.3" \
   pytest-repeat \
   pytest-rerunfailures

获取源码

mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src
// 上面的命令经常性报错,可以按下面的命令分步执行
wget https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos
vcs import src < ros2.repos

安装依赖

sudo apt upgrade
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

源码编译

cd ~/ros2_humble/
colcon build --symlink-install
// 如果在编译过程中,出现packages failed、packages had stderr output,可以使用下的命令将其单独编译通过后在全部编译
colcon build --symlink-install --packages-select iceoryx_posh

配置环境

// ros2环境
echo " source ~/ros2_humble/install/setup.bash" >> ~/.bashrc
// 解决ros2命令不能自动补全的bug
echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc

ros2测试

// 话题通信测试
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener
// 小乌龟测试
ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key
posted @ 2023-09-07 14:59  泡泡吐泡泡啊  阅读(787)  评论(0编辑  收藏  举报