树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法

树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法 请连接信号较好速度较快的wifi,或者使用手机wifi,否则将导致安装失败。
部分教程参考(https://blog.csdn.net/qq_41450811/article/details/99079041)
安装过程中遇到问题请转到文末。

  • 1:设置软件源
sudo gedit /etc/apt/sources.list

将文档里面的内容替换成
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-proposed main multiverse restricted universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-proposed main multiverse restricted universe deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe## Note, this file is written by cloud-init on first boot of an instance ## modifications made here will not survive a re-bundle. ## if you wish to make changes you can: ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg ##or do the same in user-data ## b.) add sources in /etc/apt/sources.list.d ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://ports.ubuntu.com/ubuntu-ports bionic main restricted # deb-src http://ports.ubuntu.com/ubuntu-ports bionic main restricted## Major bug fix updates produced after the final release of the ## distribution. deb http://ports.ubuntu.com/ubuntu-ports bionic-updates main restricted # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates main restricted## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://ports.ubuntu.com/ubuntu-ports bionic universe # deb-src http://ports.ubuntu.com/ubuntu-ports bionic universe deb http://ports.ubuntu.com/ubuntu-ports bionic-updates universe # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates universe## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://ports.ubuntu.com/ubuntu-ports bionic multiverse # deb-src http://ports.ubuntu.com/ubuntu-ports bionic multiverse deb http://ports.ubuntu.com/ubuntu-ports bionic-updates multiverse # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates multiverse## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://ports.ubuntu.com/ubuntu-ports bionic-backports main restricted universe multiverse # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-backports main restricted universe multiverse## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu bionic partner # deb-src http://archive.canonical.com/ubuntu bionic partnerdeb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted deb http://ports.ubuntu.com/ubuntu-ports bionic-security universe # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security universe deb http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse deb http://ports.ubuntu.com/ubuntu-ports bionic-proposed restricted main multiverse universe

换成国内的源,下载速度会快一些,ctrl+s保存,打开Software&Update,软件源替换成如图所示。
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

打开终端输入以下命令:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list' sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

  • 2 设置最新的密钥
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

执行效果:
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

  • 3 安装
sudo apt-get update

执行效果
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

sudo apt-get install ros-melodic-desktop-full sudo apt-get install ros-melodic-rqt*

执行效果:
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

  • 4初始化rosdep:
sudo rosdep init rosdep update

执行效果
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

  • 5安装rosinstall:
sudo apt-get install python-rosinstall

  • 6 加载环境设置文件
source /opt/ros/melodic/setup.bash

  • 7 创建并初始化工作目录
    ROS使用一个名为catkin的ROS专用构建系统。为了使用它,用户需要创建并初始化catkin工作目录,如下所示。除非用户创建新的工作目录,否则此设置只需设置一次。
mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src catkin_init_workspace

目前,只有src目录和CMakeLists.txt文件在catkin工作目录中,使用catkin_make命令来构建
cd ~/catkin_ws/ catkin_make

树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

  • 8设置环境变量:
sudo apt install net-tools gedit ~/.bashrc

在最后一行添加以下内容,其中ROS_HOSTNAME需要换成本机ip地址,一般可以设置为localhost
# Set ROS melodic source /opt/ros/melodic/setup.bash source ~/catkin_ws/devel/setup.bash # Set ROS Network #ifconfig查看你的电脑ip地址或者使用localhost代替 export ROS_HOSTNAME=localhost export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311

  • 9:验证安装
rosversion –d

执行效果:
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

  • 10小海龟测试,打开三个终端:
roscore rosrun turtlesim turtlesim_node rosrun turtlesim turtle_teleop_key

执行效果:
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片

安装过程中可能出现的问题及其解决办法: 1:如果出现错误: Could not get lock /var/lib/dpkg/lock - open解决方法
主要原因:主要是因为apt还在运行
解决方案:杀死所有的apt进程。
(1)查找所有apt相关的进程,并用命令杀死。例如
树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法
文章图片
(2) 锁定的文件会阻止 Linux 系统中某些文件或者数据的访问,这个概念也存在于 Windows 或者其他的操作系统中。
一旦你运行了 apt-get 或者 apt 命令,锁定文件将会创建于 /var/lib/apt/lists/、/var/lib/dpkg/、/var/cache/apt/archives/ 中。
这有助于运行中的 apt-get 或者 apt 进程能够避免被其它需要使用相同文件的用户或者系统进程所打断。当该进程执行完毕后,锁定文件将会删除。
所以:
①移除对应目录下的锁文件:
②强制重新配置软件包:
③更新软件包源文件:
$ sudo rm /var/lib/dpkg/lock 之后像下面这样强制重新配置软件包: $ sudo dpkg --configure –a 接下来,更新你的软件包源列表: $ sudo apt update

2:sudo rosdep init时出现问题:
ERROR: cannot download default sources list from:https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list Website may be down.

主要原因:网络问题
解决办法:(1)换个网络尝试下(可以尝试手机热点);
(2)如果不行的话
sudo gedit /etc/hosts 添加:151.101.84.133raw.githubusercontent.com

3:sudo: rosdep:command not found
解决办法:
sudo apt install python-rosdep

4:ros安装过程失败想要卸载重新安装可执行:
sudo apt-get purge ros-* sudo rm -rf /etc/ros gedit ~/.bashrc

【树莓派|树莓派4BUbuntu18.04安装ROS Melodic完整教程及部分报错解决方法】5:其它问题:重启有可能解决问题。

    推荐阅读