1、首先执行这三条命令
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
2、初始化rosdep
sudo rosdep init
rosdep update
rosdep输出的正确结果为:
但这两步都出现了问题,第一步会出现以下错误:
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.
第二步会出现以下错误:
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
<urlopen error [Errno 111] Connection refused>
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:
<urlopen error <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml)>
解决方法:
1)下载此链接中的压缩包,解压到/etc/ros目录下;
链接: https://pan.baidu.com/s/1Qlyo-GtxvKsWjhFqGndPLA
提取码: ere4
2)执行
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
删除文本里的所有内容,粘贴以下内容:
# os-specific listings first
yaml file:///etc/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///etc/ros/rosdistro/master/rosdep/base.yaml
yaml file:///etc/ros/rosdistro/master/rosdep/python.yaml
yaml file:///etc/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro file:///etc/ros/rosdistro/master/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
保存退出;
3)执行:
ros update
多尝试几次,就能出来正确结果了,博主执行了5次才成功,结果如下:
3、安装rosinstall
sudo apt-get install python-rosinstall
执行结果为:
4、加载环境设置文件,创建并初始化工作目录
source /opt/ros/melodic/setup.bash
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
命令执行结果如下:
5、设置环境变量
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=localhost
export ROS_MASTER_URI=http://localhost:11311
# Set ROS alias command 快捷指令
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
6、运行小海龟进行测试
roscore
运行结果如下:
新打开一个终端,执行如下命令:
rosrun turtlesim turtlesim_node
执行结果如下:
并且弹出一个蓝色背景的小海龟界面。
再次新打开一个终端,执行如下命令:
rosrun turtlesim turtle_teleop_key
执行结果如下:
按上下左右箭头操控小海龟,小海龟运行示例如下:
结束。