一、设置安装源
1.将ubuntu中找到更新和软件 ,将下载源改为安装源(ustc.edu.cn)
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 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
如:
三、更新软件列表
sudo apt update
如:
四、桌面完整安装:(推荐):ROS,rqt,rviz,机器人通用库,2D / 3D模拟器,导航和2D / 3D感知
sudo apt-get install ros-melodic-desktop-full
五、需要先初始化rosdep。rosdep能够轻松地安装要编译的源代码的系统依赖关系,并且需要在ROS中运行一些核心组件。
sudo rosdep init
rosdep update
则此处报错较多
1.下载rosdistro-master的压缩包,然后解压到主目录
cd ~
unzip rosdistro-master.zip
mv rosdistro-master rosdistro
链接: https://pan.baidu.com/s/1z25LvAV1Z7dCTuzELqhOsA
2.修改 20-default.list文件
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
内容修改如下
# os-specific listings first
yaml file:///home/xxx/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/xxx/rosdistro/rosdep/base.yaml
yaml file:///home/xxx/rosdistro/rosdep/python.yaml
yaml file:///home/xxx/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/xxx/rosdistro/releases/fuerte.yaml fuerte
# newer distributions(Groovy,Hydro,...)must not be listed anymore, they are being fetched
from the rosdistro index.yaml instead
注意:上述xxx需替换为自己的用户名
3.修改 sources _list.py 文件
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
注释原 DEFAULT_SOURCES_LIST_URL 一行,然后在其后添加如下一行,注意:xxx 替换
DEFAULT_SOURCES_LIST_URL = 'file:///home/xxx/rosdistro/rosdep/sources.list.d/20-default.list'
- 修改 rep3.py文件
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
注释原 REP3_TARGETS_URL 一行,然后在其后添加如下一行,注意:替换xxx
REP3_TARGETS_URL = 'file:///home/xxx/rosdistro/releases/targets.yaml'
5.修改 init.py 文件
sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
注释原 DEFAULT_INDEX_URL 一行,然后在其后添加如下一行,注意:替换xxx
DEFAULT_INDEX_URL = 'file:///home/xxx/rosdistro/index-v4.yaml'
6.重新
rosdep update
7.如果更新一直失败请使用如下操作
1)首先按装
sudo pip install rosdepc
2)或者安装
sudo pip3 install rosdepc
如果1,2都不行请使用
3)
sudo apt-get install python3-pip
sudo pip install rosdepc
- 再次更新
sudo rosdepc init
rosdepc update
六、ros环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
七、如果安装了多个ROS分发,则〜/ .bashrc必须仅为您当前使用的版本提供setup.bash。
rosinstall是一种常用的命令行工具可安装上
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
八、小海龟例子
1、第一个终端
roscore
2、第二个终端
rosrun turtlesim turtlesim_node
3、第三个终端
rosrun turtlesim turtle_teleop_key