目录
一、Foxy安装教程
ROS2 Foxy对应Ubuntu20.04版本!
1.1 鱼香ROS安装工具(推荐)
wget http://fishros.com/install -O fishros && . fishros
1.2 手动安装
1.2.1 设置编码
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.2.2 设置软件源
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'
1.2.3 安装ROS2
sudo apt update
sudo apt install ros-foxy-desktop
1.2.4 设置环境变量
source /opt/ros/foxy/setup.bash
注意:如果已经安装了ROS1,会提示一个警告,ROS_DISTRO
环境变量的值会变化,即之前是noetic,现在变成了foxy!
如果有ROS1程序脚本中有使用该环境变量,则会报错!
1.2.5 安装自动补全工具
sudo apt install python3-argcomplete
1.3 测试
1.3.1 运行talker:
source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_cpp talker
1.3.2 运行Listener
source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_py listener
二、Humble安装教程
ROS2 Humble对应Ubuntu22.04版本!
2.1 鱼香ROS安装工具(推荐)
wget http://fishros.com/install -O fishros && . fishros
2.2 手动安装
2.2.1 设置编码
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
2.2.2 安装依赖
sudo apt update
sudo apt install software-properties-common curl gnupg lsb-release
sudo add-apt-repository universe
2.2.3 添加ROS2 GPG密钥
sudo apt update && sudo apt install curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
2.2.4 将存储库添加到源列表
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
2.2.5 安装ROS2
sudo apt update
sudo apt install ros-humble-desktop
2.2.6 设置环境变量
source /opt/ros/humble/setup.bash
注意:如果已经安装了ROS1,会提示一个警告,ROS_DISTRO
环境变量的值会变化,即之前是noetic,现在变成了humble!
如果有ROS1程序脚本中有使用该环境变量,则会报错!
2.2.7 安装自动补全工具
sudo apt install python3-argcomplete
2.3 测试
2.3.1 运行talker:
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker
2.3.2 运行Listener
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_py listener
三、ROS2更换DDS
ROS2的默认RWM使用的DDS是Fast RTPS
,Cyclone DDS
默认也安装好了,还可以这样安装RTI Connext
:
sudo apt update
sudo apt install ros-foxy-rmw-connext-cpp
安装之后通过环境变量即可切换DDS:
export RMW_IMPLEMENTATION=rmw_connext_cpp
或者
echo "RMW_IMPLEMENTATION=rmw_connext_cpp" >> ~/.bashrc
注意:connextDDS需要有licence才能使用,教育licence或商业licence!
四、删除ROS2
sudo apt remove ros-foxy-*
sudo apt autoremove