记录一下折磨了一周的ros2配置qaq以及踩的无数坑
第一次按照一个教程安装后,命令行输入sudo apt-update 报错 The repository 'http://packages.ros.org/ros/ubuntu $(lsb_release-sc) Release' does not have a Release file.
卸载后,按照第二个教程安装
ROS 2 Documentation: Foxyhttps://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html
添加 gpg key 的步骤无法完成,修改后的整体安装流程如下:
Set 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
Setup Sources
确保 Ubuntu Universe repository 已启用
sudo apt install software-properties-common
sudo add-apt-repository universe
教程原文:用apt方法添加 ROS2 GPG key
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
用这种方法出现了拒绝连接的报错:
于是尝试在命令行里挂梯子,解决连接问题
export http_proxy=socks5://127.0.0.1:7890
export https_proxy=socks5://127.0.0.1:7890
发现问题没有得到解决qwq
最后决定直接打开网址下载key,把文件添加到 /usr/share/keyrings/ 目录下
https://raw.githubusercontent.com/ros/rosdistro/master/ros.key
把Ubuntu翻的底朝天也没有找到usr这个文件夹(哭),但命令行可以进入
推测是文件夹被隐藏,在 Home 目录下用 CtrlH 快捷键,发现了它。接下来CtrlL 再CtrlS 复制路径,用 sudo cp 原来文件路径 复制后文件路径 命令操作
sudo cp /home/ge/Downloads/ros.key /usr/share/keyrings/ros-archive-keyring.gpg
接下来就和教程一样了,把repository添加到 sources list
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
Install ROS2 packages
sudo apt update
sudo apt upgrade
sudo apt install ros-foxy-desktop python3-argcomplete
sudo apt install ros-foxy-ros-base python3-argcomplete
sudo apt install ros-dev-tools
Environment Setup
如果使用的是zsh,就把命令里的 bash 替换成 zsh
# Replace ".bash" with your shell if you're not using bash
# Possible values are: setup.bash, setup.sh, setup.zsh
source /opt/ros/foxy/setup.bash
Try some examples
打开另一个终端,运行一个C++ talker
source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_cpp talker
打开另一个终端,运行一个Python listener
source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_py listener
就这样吧有错误再更新qwq
附上卸载方法:
sudo apt remove ~nros-foxy-* && sudo apt autoremove
sudo rm /etc/apt/sources.list.d/ros2.list
sudo apt update
sudo apt autoremove
# Consider upgrading for packages previously shadowed.
sudo apt upgrade