ROS2简介
ROS2(Robot Operating System 2,机器人操作系统第二代)是一个用于开发机器人应用程序的开源中间件。它并非传统意义上的操作系统,而是运行在 Linux、Windows 或 macOS 等主流操作系统之上,提供一套通信机制、工具库、生态系统,帮助开发者构建模块化、实时性高、可靠性强的机器人系统。
安装及环境配置
1.设置语言环境
1.1检查locale
locale
如图所示 C一般表示默认设置的locale(也被称为POSIX),UTF-8表示字符编码。
理论上只要是支持UTF-8的locale都没有问题,可以不用修改。
1.2修改locale
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
1.3验证是否修改成功
如图所示 已经修改成功
2.设置源
sudo apt update && sudo apt install curl -y
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F'"' '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo ${UBUNTU_CODENAME:-${VERSION_CODENAME}})_all.deb"
sudo dpkg -i /tmp/ros2-apt-source.deb
3.安装ROS2
sudo apt update
sudo apt install ros-humble-desktop
4.安装ros-dev-tools(开发者必备)
sudo apt install ros-dev-tools
5.设置环境变量
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
6.验证是否安装成功
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker
如图所示 说明安装成功