前言

系统环境: Ubuntu 18.04,硬盘安装。

ROS版本: melodic

深蓝学院(古月居)胡春旭ROS理论与实践笔记整理。

1. 添加源

1
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

2. 添加密钥

1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

3. 安装

1
2
3
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*

4. 初始化rosdep

1
2
sudo rosdep init
rosdep update

问题一:

执行sudo rosdep init时,产生错误:

1
2
3
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.

解决方法

通过修改host解决。

  • 修改host:
1
2
cd /etc
sudo gedit hosts
  • 在文末添加:
1
151.101.84.133 raw.githubusercontent.com

问题二:

执行rosdep update时,产生错误timeout

1
2
3
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: error loading sources list:
('The read operation timed out')

解决方法:

ROS安装过程中如何解决 rosdep update 命令出现错误

5. 设置环境变量

1
2
3
4
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc


6. 安装rosinstall

1
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

7. 加载环境设置文件

1
source /opt/ros/melodic/setup.bash

8. 创建并初始化工作目录

1
2
3
4
5
6
7
8
9
mkdir -p ~/catkin_ws/src

cd ~/catkin_ws/src

catkin_init_workspace

cd ~/catkin_ws/

catkin_make

9. 更新环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo apt install net-tools
gedit ~/.bashrc

# Set ROS melodic
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash

# Set ROS Network
#ifconfig查看ip
export ROS_HOSTNAME=192.168.xx.xx
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311

# Set ROS alias command 快捷指令
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'

10. 小海龟测试

1
2
3
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

注意光标要放在第三个终端上,小海龟才会移动。

小海龟移动测试

参考

ubuntu18.04安装ROS Melodic(最详细配置)

ROS安装过程中如何解决 rosdep update 命令出现错误

Ubuntu18.04安装ROS Melodic(详细,亲测安装完成,有清晰的截图步骤)