注:运行平台是NVIDIA tx2
1.安装(这是官网推荐安装方法,建议使用,下面运行实例有tx2上安装方法)
1.1配置 Ubuntu 软件仓库
配置你的 Ubuntu 软件仓库(repositories) 以允许 "restricted"、"universe" 和 "multiverse"这三种安装模式。 你可以按照 Ubuntu 中的配置指南来完成配置。
1.2添加 sources.list
设置你的电脑以从 packages.ros.org 接收软件.
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
1.3添加公钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
如果你无法连接到公钥服务器,尝试用 hkp://pgp.mit.edu:80 替换上述命令中的服务器地址。
你也可以使用 curl 替代 apt-key 命令,如果你在使用一个代理服务器的话这可能会有帮助:
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
1.4安装
首先,确保你的 Debian 包索引是最新的:
sudo apt update
在 ROS 中有很多不同的库和工具。我们提供了四种默认选项供你开始。你也可以单独安装 ROS 的软件包。
如果下面的步骤出现问题,你可以用这个源来替代上面提到的源:ros-shadow-fixed
桌面完整版(推荐): : 包含 ROS、rqt、rviz、机器人通用库、2D/3D 模拟器、导航以及 2D/3D 感知包。
sudo apt install ros-melodic-desktop-full
sudo apt install ros-melodic-desktop
ROS-基础包: 包含 ROS 包,构建和通信库。没有图形界面工具。
sudo apt install ros-melodic-ros-base
单独的包: 你也可以安装某个指定的ROS软件包(使用软件包名称替换掉下面的PACKAGE):
sudo apt install ros-melodic-PACKAGE
如:
sudo apt install ros-melodic-slam-gmapping
要查找可用软件包,请运行:
apt search ros-melodic
1.5初始化 rosdep
在你使用 ROS 之前,需要初始化 rosdep。rosdep 让你能够轻松地安装被想要编译的源代码,或被某些 ROS 核心组件需要的系统依赖。
sudo rosdep initrosdep update
1.6设置环境
将 ROS 环境变量自动添加到新 bash 会话会很方便:
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrcsource ~/.bashrc
如果你不只安装了一个 ROS 发行版, ~/.bashrc 只能使用你需要的 ROS 版本的 setup.bash 。
如果你只想设置当前 bash 会话的 ROS 环境变量,只需要输入:
source /opt/ros/melodic/setup.bash
如果你使用 zsh,那么你需要将上述命令改为:
echo "source /opt/ros/melodic/setup.zsh" >> ~/.zshrcsource ~/.zshrc
1.7构建工厂依赖
到目前为止,你已经安装了运行核心 ROS 包所需的内容。为了创建和管理自己的 ROS 工作区,有各种各样的工具和需求分别分布。例如:rosinstall 是一个经常使用的命令行工具,它使你能够轻松地从一个命令下载许多 ROS 包的源树。
要安装这个工具和其他构建ROS包的依赖项,请运行:
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
1,安装中的错误
2.1初始化rosdep时报错,20-default.list无法下载:
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.
网上典型热门解决方法如下:
1)ca-certificates问题,证书不对,重新安装证书
sudo apt-get install ca-certificates
2)系统时间同步问题,需要同步系统时间
参照链接https://blog.csdn.net/A18373279153/article/details/81003937进行系统时间同步
sudo apt-get install ntpdate
sudo ntpdate cn.pool.ntp.org
sudo hwclock --systohc
3) 还是ssl certs问题,继续尝试解决
sudo c_rehash /etc/ssl/certs
sudo -E rosdep init
4)python-rosdep问题
sudo apt-get install python-rosdep
但以上方法全部无效,无奈之下直接在/etc目录下新建/ros/rosdep/sources.list.d/20-default.list文件(注意sudo rosdep init失败时,/etc下并没有/ros目录,需要依次逐级新建),然后将https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list内容粘贴进去,如下:
# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/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
至此,终于解决了20-default.list下载不下来的问题。
注:这里虽然手动新建了20-default.list,但执行sudo rosdep init依然会出现之前的错误,这里我们无视,继续执行下一步。
然而我进入/etc目录下发现有/ros/rosdep/sources.list.d/20-default.list这个文件,于是直接进行接下的操作;但是还是会报错,如下显示:
rosdep update
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 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (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 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (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 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (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 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (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 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:
<urlopen error <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml)>
通过网上大量的查找资源找到的解决方法:
sudo gedit /etc/resolv.conf
将原有的nameserver这一行注释,并添加以下两行:
nameserver 8.8.8.8 #google域名服务器
nameserver 8.8.4.4 #google域名服务器
保存退出,执行
sudo apt-get update
再执行
rosdep update
然后在回到之前的问题上:
ming@ming:~$ sudo rosdep init
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
自此完全解决这个问题,Ros成功安装。
3,实例安装与运行
首先,我是在NVIDIA tx2上运行并安装gstcam的实例。
3.1 git上下载自动脚本
git clone https://github.com/jetsonhacks/installROSTX2.git
ls
cd installROSTX2/
ls
./setupCatkinWorkspace.sh
3.2 运行程序
cd ~/catkin-ws
source devel/setup.bash
cd src
git clone https://github.com/ros-drivers/gscam.git
sudo apt-get install gstreamer1.0-tools libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev
cd ..
catkin_make -DGSTREAMER_VERSION_1_x=On
添加文件〜/ catkin_ws / src / gscam / examples / tx2.launch
<launch>
<!-- This launchfile should bring up a node that broadcasts a ros image
transport on /webcam/image_raw -->
<arg name="DEVICE" default="/dev/video0"/>
<!-- The GStreamer framerate needs to be an integral fraction -->
<arg name="FPS" default="30/1"/>
<arg name="PUBLISH_FRAME" default="false"/>
<arg name="GST10" default="false"/>
<node ns="v4l" name="gscam_driver_v4l" pkg="gscam" type="gscam" output="screen">
<param name="camera_name" value="default"/>
<param name="camera_info_url" value="package://gscam/examples/uncalibrated_parameters.ini"/>
<param name="gscam_config" value="nvcamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),width=1280, height=720,format=I420, framerate=30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=BGRx ! videoconvert ! ffmpegcolorspace "/>
<!-- not working <param name="gscam_config" value="nvcamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM),width=1280, height=720,format=I420, framerate=30/1' ! nvvidconv flip-method=0 ! 'video/x-raw, format=BGRx' ! videoconvert ! 'video/x-raw, format=BGR' ! appsink "/>-->
<!-- working, but maybe too much <param name="gscam_config" value="nvcamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),width=1280, height=720,format=I420, framerate=30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR "/> -->
<param name="frame_id" value="/v4l_frame"/>
<param name="sync_sink" value="true"/>
</node>
<node if="$(arg PUBLISH_FRAME)" name="v4l_transform" pkg="tf" type="static_transform_publisher" args="1 2 3 0 -3.141 0 /world /v4l_frame 10"/>
</launch>
运行
roslaunch gscam tx2.launch
# on other console, run
rosrun image_view image_view image:=/v4l/camera/image_raw
roslaunch gscam tx2.launch运行过程中出现以下错误时:
[robot_launch.launch] is neither a launch file in package [kinova_gazebo] nor is [kinova_gazebo] a launch file name
The traceback for the exception was written to the log file
报错说明ros系统中,并没有安装相对应的package。在这种情况下,进入工程文件的最顶层,使用catkin_make命令对文件进行编译。如果此时再执行,还是会报错的,那么还要再加上一条语句:
source devel/setup.bash
将devel/setup.bash添加到系统,之后再运行就可以了。
附上参考网站地址:
ROS安装官网:http://wiki.ros.org/cn/melodic/Installation/Ubuntu#A.2BUh1Zy1MW_rosdep
ROS 初始化rosdep时报错:
(1)https://zhuanlan.zhihu.com/p/77483614
(2)https://www.jianshu.com/p/bdbfbac69114
(3)https://blog.csdn.net/mrh1714348719/article/details/103803110#commentBox
ROS运行实例报错:https://blog.csdn.net/lqzdreamer/article/details/82812738
TX2上运行实例:
(1)https://github.com/jetsonhacks/installROSTX2
(2)https://github.com/ros-drivers/gscam/issues/38