问题描述
安装ROS底层系统时,经常遇到一个情况就是apt找不到ros的对应版本
解决方案
添加ros官方给的apt源和安装密钥
ROS1
# ros奖项
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# 获取ROS密钥
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
ROS2
sudo apt update && sudo apt install curl gnupg2 lsb-release
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - #获取ROS密钥
sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
现在就可以安装了
比如ROS1的melodic:
sudo apt update
sudo apt install ros-melodic-desktop
比如ROS2的humble
sudo apt-get update
sudo apt-get install ros-humble-desktop
初始化rosdep
sudo rosdep init
rosdep update
设置环境变量
melodic:
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
humble:
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
测试安装结果
ROS1测试方法
启动核心节点:
roscore
运行示例 publisher :
rosrun rospy_tutorials talker.py
运行示例 subscriber
rosrun roscpp_tutorials listener
ROS2测试方法
直接启动publisher和subscriber:
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener