系统版本:
Ubuntu 20.04.5
系统配置:
#检查是否为UTF-8编码,是则跳过!
locale
#非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
#验证是否设置成功
locale
添加ROS 2 apt存储库
图形界面设置更清晰方便
将可从互联网下载下面四个选项勾选上,没换源的直接换上中科大的镜像源,挺好用!
添加带有apt的ROS 2 GPG密钥
sudo apt update && sudo apt install curl
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
拒绝访问连接解决方法
sudo gedit /etc/hosts
# 添加
185.199.108.133 raw.githubusercontent.com
将存储库添加到源列表中
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /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
安装Ubuntu20.04所需软件包
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
获取ROS2源码:
mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src
用rosdep安装依赖
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"
提示:[sudo rosdep init 失败解决方案](https://blog.csdn.net/zsl1373/article/details/119790253?spm=1001.2014.3001.5502)
编译
cd ~/ros2_humble/
colcon build --symlink-install
提示:编译过程中如果也需要从github中下载,保持网络通常
设置环境变量到~/.bsahrc中:
sudo echo "source ~/ros2_humble/install/setup.bash" >> ~/.bashrc
运行示例
新建终端1
ros2 run demo_nodes_cpp talker
新建终端2
ros2 run demo_nodes_py listener
能够接发出或者接收到消息即安装成功