[ROS学习](1) Ubuntu18.04 下的ROS安装
更换软件源
-
备份原文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bcakup
-
打开文件,添加源,或替换掉原来所有内容
使用vim
编辑器(可将vim
替换为 gedit 编辑器进行编辑)sudo vi /etc/apt/sources.list
# 阿里云源 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse # 测试版源 deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse # 源码 deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse # 测试版源 deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
-
更新软件列表
sudo apt-get update
-
更新软件(可选)
sudo apt-get upgrade
安装ROS
-
设置软件源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
-
设置key
sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
-
更新软件源
sudo apt update
-
安装
共有四个版本,建议安装
full
版本desktop-full:
sudo apt install ros-melodic-desktop-full
desktop:(普通版本)
sudo apt install ros-melodic-desktop
ROS-Base:(基础版)
sudo apt install ros-melodic-ros-base
Individual Package:(独立包安装)(PACKAGE : 要安装的功能包名)
sudo apt install ros-melodic-PACKAGE
列举可用的功能包:
apt search ros-melodic
-
配置环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrcsource ~/.bashrc
-
构建依赖包
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
安装 rosdep
sudo apt install python-rosdep
初始化及更新 rosdep
sudo rosdep initrosdep update
解决
rosdep init
与rosdep update
访问超时的问题sudo apt-get install python3-pip sudo pip3 install 6-rosdepsudo 6-rosdep
构建项目的workspace
-
创建工作空间文件夹
于确定的目录下打开终端
创建新的文件夹 ros_work_spacemkdir ros_work_space
进入该目录下
cd ros_work_space/
创建
src
目录mkdir src
进入
src
目录下cd src/
使用
ros
指令生成CMakeLists.txt
catkin_init_workspace
-
编译工作空间
返回src
目录下cd ..
输入指令对该工作空间进行编译
catkin_make
-
设置环境变量
输入指令以设置环境变量source devel/setup.bash
输入指令以查看设置的环境变量
echo $ROS_PACKAGE_PATH
在修改完环境变量之后重启终端窗口才可以生效