ros安装
前奏
参考1
参考2
官网1
Ubuntu18官网文档
Ubuntu18 IOS
磁盘:100G
root@muzhi:~# cat /etc/issue
Ubuntu 18.04.6 LTS \n \l
root@muzhi:~# uname -a
Linux muzhi 5.4.0-84-generic #94~18.04.1-Ubuntu SMP Thu Aug 26 23:17:46 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root@muzhi:~# hostname -I
192.168.92.129 # NAT网络
# 修改固定IP
~# cp /etc/netplan/01-network-manager-all.yaml{,-`date +'%Y%m%d%H%M'`}
~# vim /etc/netplan/01-network-manager-all.yaml
network:
version: 2
renderer: NetworkManager
ethernets:
ens33:
addresses: [192.168.92.129/24]
gateway4: 192.168.92.2
dhcp4: false
optional: true
nameservers:
addresses: [192.168.92.2, 114.114.114.114]
# 重启网络服务使配置生效
~# sudo netplan apply
# 查看内存
~# free -h
总计 已用 空闲 共享 缓冲/缓存 可用
内存: 1.9G 1.3G 157M 6.2M 477M 462M
交换: 2.0G 193M 1.8G
安装ROS
~# 是root用户
~$ 是普通用户
使用普通用户执行命令前必须在命令前sudo,使用root用户执行命令时则不用添加,如加上也可能执行
# 系统用户
muzhi用户密码: muzhi
root用户密码: muzhi
# 添加ROS软件源
~# sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# 添加密钥
~# sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
# 安装ROS
~# sudo apt update ===> 这步如不执行会出现下一步安装不成功!!!
==== 参考项 ==========
apt search ros-melodic # 搜索安装包
===================
~# sudo apt install -y ros-melodic-desktop-full
# 设置环境变量(安装了多个版本则需要参考上述Ubuntu官方安装文档)
~# echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
~# source ~/.bashrc
# 安装依赖
~# sudo apt install -y python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
# 初始化rosdep
~# sudo apt install -y python-rosdep
~# sudo rosdep init
报错1:
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:
打开该网站 https://ipaddress.com/website/raw.githubusercontent.com,找到诸如下述3个IP并将其粘贴到hosts文件中
185.199.108.133
185.199.109.133
185.199.110.133
185.199.111.133
操作如下
~# vim /etc/hosts
185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
如使用虚拟机安装,则需另写到win机器的hosts文件中,地址 C:\Windows\System32\drivers\etc
# 再来执行初始化命令
~# sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run
rosdep update
# 上述都执行没问题后再往下继续
~# rosdep update
报错:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdep update' as root is not recommended.
You should run 'sudo rosdep fix-permissions' and invoke 'rosdep update' again without sudo.
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit 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:
('The read operation timed out',)
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:
('The read operation timed out',)
root@muzhi:~# rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdep update' as root is not recommended.
You should run 'sudo rosdep fix-permissions' and invoke 'rosdep update' again without sudo.
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
ERROR: error loading sources list:
('The read operation timed out',)
============= 跳过 ============
解决:
~# wget -O 20-default.list https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
~# mv /etc/ros/rosdep/sources.list.d/20-default.list{,-`date +'%Y%m%d%H%M'`}
~# cp 20-default.list /etc/ros/rosdep/sources.list.d/
#更新本地 rosdep 数据库
~# rosdep update
============================
解决:
~# ssh-keygen -t rsa -P ''
~# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxlw3sK59r63gutSvIDXL7dNdevb4NBDcVd4K6w/s3kGAHpSSghhc8jKGfwL2Z3MMmYcA8LHelngy68WuQdxiQp61UKv/QZx6AnQGFLevd9CUZdyhXTL2K3EDbs4dap+UZdP+jk+V2I6AwWhHhiKT6tFC3PW2zAR3iBSYJw9IE8MDU3XwHcXeen3wh2uAeMj7/pun/mgI2Q9EQUnVCEWW31OPRXGz5MNeH8fhAyd6PVdLyKfOfnjigeFjWgkdJtjdjOxzoq/SM+zTINFl1mqsMmDySL9Akm7y37XcWuZsSAmc4fUYMYHhCmvT+gHDAkNz7JMGqFe8QyhOQmy0dKGJ5 root@muzhi
将上述公钥传到github上,然后克隆项目
~# git clone --depth=1 https://github.com/ros/rosdistro.git
============= 跳过 ===============
~# mv /etc/ros/rosdep/sources.list.d/20-default.list{,-`date +'%Y%m%d%H%M'`}
~# cp rosdistro/rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/
==================================
将如下4个文件中的https地址做替换
/etc/ros/rosdep/sources.list.d/20-default.list
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py
# 操作如下
~# cp /etc/ros/rosdep/sources.list.d/20-default.list{,-bak}
~# vim /etc/ros/rosdep/sources.list.d/20-default.list ====> 这条是命令
# os-specific listings first
yaml file:///root/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///root/rosdistro/rosdep/base.yaml
yaml file:///root/rosdistro/rosdep/python.yaml
yaml file:///root/rosdistro/rosdep/ruby.yaml
gbpdistro file:///root/rosdistro/releases/fuerte.yaml fuerte
~# vim /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py ====> 打开该文件
FUERTE_GBPDISTRO_URL = 'file:///root/rosdistro/releases/fuerte.yaml' ====> 修改该项
~# vim /usr/lib/python2.7/dist-packages/rosdep2/rep3.py ====> 打开该文件
REP3_TARGETS_URL = 'file:///root/rosdistro/releases/targets.yaml' ====> 修改该项
~# vim /usr/lib/python2.7/dist-packages/rosdistro/__init__.py ====> 打开该文件
DEFAULT_INDEX_URL = 'file:///root/rosdistro/index-v4.yaml' ====> 修改该项
~# rosdep update ===> 这条是命令
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdep update' as root is not recommended.
You should run 'sudo rosdep fix-permissions' and invoke 'rosdep update' again without sudo.
Hit file:///root/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///root/rosdistro/rosdep/base.yaml
Hit file:///root/rosdistro/rosdep/python.yaml
Hit file:///root/rosdistro/rosdep/ruby.yaml
Hit file:///root/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///root/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Add distro "galactic"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /root/.ros/rosdep/sources.cache
运行小海龟示例
~# roscore ===> 在图形化界面中运行该命令,运行后该不要关闭该窗口
# 再在图形化界面中使用root用户新开一个窗口(第二个窗口)
用途: turtlesim_node节点和turtle_teleop_key节点之间是通过一个ROS话题来互相通信
语法:rosrun [package_name] [node_name]
实操
~# rosrun turtlesim turtlesim_node
~/rosdistro# rosnode list
返回如下信息:
/rosout
/turtlesim
# rqt_graph命令来显示当前运行的节点和话题(可选项)
~# rqt_graph
# 再在图形化界面中使用root用户再新开一个窗口(第三个窗口)
用途:turtle_teleop_key在一个话题上发布按键输入消息,而turtlesim则订阅该话题以接收该消息
语法:rosrun [package_name] turtle_teleop_key
实操
~# rosrun turtlesim turtle_teleop_key
注:执行该命令时不能在小乌龟全屏下执行,也不能在终端全屏下执行,专业用语叫 "光标处于激活状态",也就是既能显示终端也能看到小乌龟界面,这2个画面都能看到时 在终端中(非小乌龟界面) 通过方向键即可控制小海龟的移动
安装Gazebo并与ROS连接
以下操作需要在上述都完成后进行
上面安装ros时是安装的 ros-melodic-desktop-full 版本,ros-melodic-desktop-full因为安装的是全版本(包含Gazebo),所以这里安装Gazebo时要
root@muzhi:~# apt list|grep gazebo-*
root@muzhi:~# apt install -y gazebo9 libgazebo9-dev
# Gazebo与ROS连接
(1) 安装ROS-Gazebo接口
root@muzhi:~# sudo apt install -y ros-melodic-gazebo-ros-pkgs ros-melodic-gazebo-msgs ros-melodic-gazebo-plugins ros-melodic-gazebo-ros-control
(2) 验证是否连接成功
图形化界面上新打开第一个窗口输入:
root@muzhi:~# roscore
图形化界面上新打开第二个窗口输入:
root@muzhi:~# rosrun gazebo_ros gazebo
报错:
libcurl: (51) SSL: no alternative certificate subject name matches target host name 'api.ignitionfuel.org'
VMware: vmw_ioctl_command error 无效的参数.
Aborted (core dumped)
解决:
root@muzhi:~# vim ~/.ignition/fuel/config.yaml
把api.ignitionfuel.org 改成 fuel.ignitionrobotics.org,而后再运行
root@muzhi:~# rosrun gazebo_ros gazebo
再一次报错
VMware: vmw_ioctl_command error 无效的参数.
Aborted (core dumped)
解决:
参照:https://blog.csdn.net/weixin_43059285/article/details/108012524
这里使用方案一,如下图(点虚拟机右键==属性==要在关机下进行)
root@muzhi:~# mkdir -p ~/.gazebo/models && cd ~/.gazebo/models
root@muzhi:~/.gazebo/models# wget http://file.ncnynl.com/ros/gazebo_models.txt
root@muzhi:~/.gazebo/models# wget -i gazebo_models.txt
root@muzhi:~/.gazebo/models# ls model.tar.g* | xargs -n1 tar xzvf
root@muzhi:~/.gazebo/models# killall gzserver
root@muzhi:~/.gazebo/models# killall gzclient