ROS
参考博客: https://blog.csdn.net/qq_45067735/article/details/107303796.
1.ROS安装
安装见ROS官方网站: http://wiki.ros.org/Installation/Ubuntu
或者参考教程: https://blog.csdn.net/qq_44830040/article/details/106049992(这个教程是用的国内源安装,虽然可以使用ros,但是可能在和其他的一起使用时出现问题例如darknet_ros,虽然国内源下载会快很多,但还是建议从官网下载)
注意:Ubuntu18.04可以直接全部安装(即指令 sudo apt-get install ros-melodic-desktop 即对于ROS Melodic,选择desktop-full的方式安装,这将同时安装Gazebo9和感知相关库)但是我个人建议18.04的也不进行全部安装,直接安装的gazebo9.0存在缺陷可能在后面出现问题,建议也是选择安装desktop,然后在下面的步骤中安装gazebo9.13或者以上
Ubuntu16.04(ROS Kinetic)选择destop否则安装gazebo7无法进行后续仿真
这里把安装ROS(以melodic为例)也列举出来:
(1)配置Ubuntu存储库
在软件与更新中点击 源代码
(2)设置sources.list
以下分别是清华镜像、中科大镜像和官方默认选其中一个即可,但是个 人推荐国内镜像,下载会快很多
清华镜像:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
中科大镜像:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
官方默认:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
(3)设置key
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
(4)安装
sudo apt update
sudo apt install ros-melodic-desktop
正常安装ROS的话可以sudo apt install ros-melodic-desktop-full,这里是sudo apt install ros-melodic-desktop原因前面已经说了
(5)设定环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
(6)构建软件包的依赖关系
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init
若出现错误:
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.
输入下面的指令
cd /etc
sudo gedit hosts
末尾添加:
151.101.84.133 raw.githubusercontent.com
然后保存文件退出即可。
如果出现错误:
ERROR: default sources list file already exists: /etc/ros/rosdep/sources.list.d/20-default.list Please delete if you wish to re-initialize
解决办法,执行如下命令:
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
然后继续输入
sudo rosdep init
(7)执行rosdep update更新
rosdep update
若出现以下报错
ERROR: error loading sources list: (‘The read operation timed out’,)
也可能是网络原因,反复执行下面指令(建议手机热点)
rosdep update
(8)测试ROS
打开一个终端
roscore
... logging to /home/robin/.ros/log/a5118af0-5474-11ea-8b86-e454e828c524/r Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://robin-G3-3590:34223/ ros_comm version 1.12.14 SUMMARY PARAMETERS /rosdistro: kinetic /rosversion: 1.12.14 NODES auto-starting new master process[master]: started with pid [30244] ROS_MASTER_URI=http://robin-G3-3590:11311/ setting /run_id to a5118af0-5474-11ea-8b86-e454e828c524 process[rosout-1]: started with pid [30261] started core service [/rosout]
打开第二个终端输入
rosrun turtlesim turtlesim_node
若出现小海龟
则再打开第三个终端
rosrun turtlesim turtle_teleop_key
启动海龟控制节点(方向键控制海龟运动)
(7)catkin_ws
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash
2.Gazebo安装
无论是ros Kinetic还是Melodic,自带的Gazebo都存在缺陷,若是安装ros时已经安装了gazebo建议卸载并重新安装。建议gazebo版本在9.13以上
Gazebo安装见官网:
http://gazebosim.org/tutorials?tut=install_ubuntu&cat=install.
注意几点:
(1).选用Alternative installation: step-by-step的安装方式
(2).安装Gazebo9.13或者以上
这里为了方便把gazebo的安装也列出来
(3).设置计算机以接受来自package.osrfoundation.org的软件
1.设置计算机以接受来自package.osrfoundation.org的软件
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
cat /etc/apt/sources.list.d/gazebo-stable.list
#如果出现deb http://packages.osrfoundation.org/gazebo/ubuntu-stable xenial main表示没问题
2.设置密钥
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update
3.安装gazebo9.1指令:
sudo apt-get install gazebo9=9.1*
安装之后终端输入gazebo
若打开Gazebo说明安装成功
4.Gazebo本身是独立于ROS的,因此还需要安装ROS的Gazebo插件
sudo apt install ros-melodic-gazebo9-*
sudo apt install ros-melodic-gazebo-*
测试
roscore
rosrun gazebo_ros gazebo
若能打开Gazebo说明Gazebo和ROS间的插件也安装成功。
输入gazebo --version
也可以查看到gazebo的版本