在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示
智能车无人驾驶技术是目前人工智能和机器人技术的研究热点,有许多开源平台可以使我们零基础零成本入门无人驾驶技术。本文分享一下目前ROS官网最新推荐的一款开源汽车仿真模拟。使用的平台为Ubuntu 16.04 + ROS Kinetic + Gazebo 8。同时需要具备Docker和nvidia-docker的基础。
Gazebo:
RVIZ:
1. Docker安装
请参考https://www.docker.com官网和CSDN相关博客。
2. nvidia-docker安装
$ nvidia-docker run -ti --rm nvidia/cuda nvidia-docker | 2017/07/06 13:13:17 Error: unsupported CUDA version: driver 6.5 < image 8.0.61
3. 配置和使用ROS/Gazebo中的Prius示例
$ ./build_demo.bash
----
relaybot@relaybot-desktop:~/Rob_Soft/car_demo-master$ ./build_demo.bash [sudo] password for relaybot: Sending build context to Docker daemon 58.96MB Step 1/12 : FROM osrf/ros:kinetic-desktop ---> fe1c52012515 Step 2/12 : LABEL com.nvidia.volumes.needed "nvidia_driver" ---> Using cache ---> c0a552983f0f Step 3/12 : ENV PATH /usr/local/nvidia/bin:${PATH} ---> Using cache ---> b4336a6fcd17 Step 4/12 : ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} ---> Using cache ---> d9f0873b5c72 Step 5/12 : RUN apt-get update && apt-get install -y wget lsb-release sudo mesa-utils && apt-get clean ---> Using cache ---> d1d2e996eae1 Step 6/12 : RUN echo "deb http://packages.osrfoundation.org/gazebo/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list && wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add - && apt-get update && apt-get install -y gazebo8 ros-kinetic-gazebo8-ros-pkgs ros-kinetic-fake-localization ros-kinetic-joy && apt-get clean ---> Using cache ---> 62e82befdf92 Step 7/12 : RUN mkdir -p /tmp/workspace/src ---> Using cache ---> 3344777de771 Step 8/12 : COPY prius_description /tmp/workspace/src/prius_description ---> Using cache ---> d6c8c42918c2 Step 9/12 : COPY prius_msgs /tmp/workspace/src/prius_msgs ---> Using cache ---> ce2281718303 Step 10/12 : COPY car_demo /tmp/workspace/src/car_demo ---> Using cache ---> ca825da11474 Step 11/12 : RUN /bin/bash -c 'cd /tmp/workspace && source /opt/ros/kinetic/setup.bash && catkin_make' ---> Using cache ---> a78d42ed877a Step 12/12 : CMD /bin/bash -c source /opt/ros/kinetic/setup.bash && source /tmp/workspace/devel/setup.bash && roslaunch car_demo demo.launch ---> Using cache ---> 20890ac15cee Successfully built 20890ac15cee Successfully tagged osrf/car_demo:latest relaybot@relaybot-desktop:~/Rob_Soft/car_demo-master$
----
$ ./run_demo.bash
$ ./run_demo.bash CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ... logging to /root/.ros/log/31d9adfa-620b-11e7-a113-0242ac110002/roslaunch-a0950e425e8e-82.log 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://a0950e425e8e:37129/ SUMMARY ======== PARAMETERS * /joy_node0/dev: /dev/input/js0 * /joy_node1/dev: /dev/input/js1 * /robot_description: <?xml version="1.... * /rosdistro: kinetic * /rosversion: 1.12.7 * /use_sim_time: True NODES / fake_localization (fake_localization/fake_localization) gazebo (gazebo_ros/gzserver) gazebo_gui (gazebo_ros/gzclient) joy_node0 (joy/joy_node) joy_node1 (joy/joy_node) joystick_translator (car_demo/joystick_translator) robot_state_publisher (robot_state_publisher/robot_state_publisher) rviz (rviz/rviz) spawn_urdf (gazebo_ros/spawn_model) very_inaccurate_odom (tf2_ros/static_transform_publisher) auto-starting new master process[master]: started with pid [93] ROS_MASTER_URI=http://localhost:11311 setting /run_id to 31d9adfa-620b-11e7-a113-0242ac110002 process[rosout-1]: started with pid [106] started core service [/rosout] process[gazebo-2]: started with pid [109] process[gazebo_gui-3]: started with pid [113] process[robot_state_publisher-4]: started with pid [142] process[fake_localization-5]: started with pid [195] process[very_inaccurate_odom-6]: started with pid [196] process[joystick_translator-7]: started with pid [255] process[joy_node0-8]: started with pid [299] process[joy_node1-9]: started with pid [300] Gazebo multi-robot simulator,version 8.1.1 Copyright (C) 2012 Open Source Robotics Foundation. Released under the Apache 2 License. http://gazebosim.org process[spawn_urdf-10]: started with pid [328] process[rviz-11]: started with pid [356] [ INFO] [1499318590.218434440]: Finished loading Gazebo ROS API Plugin. [Msg] Waiting for master. [ INFO] [1499318590.220829714]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised,waiting... [Msg] Connected to gazebo master @ http://127.0.0.1:11345 [Msg] Publicized address: 172.17.0.2 [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported [spawn_urdf-10] process has finished cleanly log file: /root/.ros/log/31d9adfa-620b-11e7-a113-0242ac110002/spawn_urdf-10*.log [ INFO] [1499318597.020363774,1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/' [ INFO] [1499318597.029090560,1341.708000000]: Camera Plugin (ns = /) <tf_prefix_>,set to "" [ WARN] [1499318597.051198614,1341.708000000]: Range plugin missing <radiation>,defaults to ultrasound [ WARN] [1499318597.051501949,1341.708000000]: Range plugin missing <fov>,defaults to 0.05 [ INFO] [1499318597.051634287,1341.708000000]: Range plugin missing <gaussianNoise>,defaults to 0.0 [ INFO] [1499318597.051772773,1341.708000000]: Range plugin missing <updateRate>,defaults to 0 [ WARN] [1499318597.071652157,defaults to ultrasound [ WARN] [1499318597.071737149,defaults to 0.05 [ INFO] [1499318597.071765174,defaults to 0.0 [ INFO] [1499318597.071788477,defaults to 0 [ WARN] [1499318597.074830942,defaults to ultrasound [ WARN] [1499318597.075126204,defaults to 0.05 [ INFO] [1499318597.075418562,defaults to 0.0 [ INFO] [1499318597.075720639,defaults to 0 [ WARN] [1499318597.089499716,defaults to ultrasound [ WARN] [1499318597.090064739,defaults to 0.05 [ INFO] [1499318597.090382446,defaults to 0.0 [ INFO] [1499318597.090626321,defaults to 0 [ INFO] [1499318603.934692266,1341.708000000]: Block laser plugin missing <gaussianNoise>,defaults to 0.0 [ INFO] [1499318603.934773061,1341.708000000]: Block laser plugin missing <hokuyoMinIntensity>,defaults to 101 [ INFO] [1499318603.934847668,1341.708000000]: Block laser plugin missing <updateRate>,defaults to 0 [ INFO] [1499318604.031684097,1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/' [ WARN] [1499318604.036142916,defaults to ultrasound [ WARN] [1499318604.036419387,defaults to 0.05 [ INFO] [1499318604.036500172,defaults to 0.0 [ INFO] [1499318604.036576326,defaults to 0 [ INFO] [1499318604.048912318,set to "" [ INFO] [1499318604.601344650,1341.708000000]: Laser Plugin: Using the 'robotNamespace' param: '/' [ INFO] [1499318604.602166296,1341.708000000]: Starting Laser Plugin (ns = /)! [ INFO] [1499318604.609125255,1341.708000000]: Laser Plugin (ns = /) <tf_prefix_>,set to "" [ WARN] [1499318604.622696602,defaults to ultrasound [ WARN] [1499318604.622786468,defaults to 0.05 [ INFO] [1499318604.622838959,defaults to 0.0 [ INFO] [1499318604.622875155,defaults to 0 [ WARN] [1499318604.675410176,defaults to ultrasound [ WARN] [1499318604.675486412,defaults to 0.05 [ INFO] [1499318604.675527058,defaults to 0.0 [ INFO] [1499318604.675556004,defaults to 0 [ INFO] [1499318605.145527632,1341.708000000]: Laser Plugin: Using the 'robotNamespace' param: '/' [ INFO] [1499318605.145614241,1341.708000000]: Starting Laser Plugin (ns = /)! [ INFO] [1499318605.154089749,set to "" [ WARN] [1499318605.158758063,defaults to ultrasound [ WARN] [1499318605.158840499,defaults to 0.05 [ INFO] [1499318605.158877742,defaults to 0.0 [ INFO] [1499318605.158909882,defaults to 0 [ INFO] [1499318605.244331364,1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/' [ INFO] [1499318605.260901986,1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/' [ INFO] [1499318605.268178012,set to "" [ INFO] [1499318605.295667008,set to "" [Wrn] [PriusHybridPlugin.cc:361] PriusHybridPlugin loading params [ INFO] [1499318605.487444516,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: rear_right_wheel_joint [ INFO] [1499318605.487560947,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: rear_left_wheel_joint [ INFO] [1499318605.487821573,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_right_wheel_joint [ INFO] [1499318605.487860817,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_left_wheel_joint [ INFO] [1499318605.487897223,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_right_steer_joint [ INFO] [1499318605.487938402,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_left_steer_joint [ INFO] [1499318605.487983362,1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: steering_joint [ INFO] [1499318605.488209156,1341.708000000]: Starting GazeboRosJointStatePublisher Plugin (ns = //)!,parent name: prius [ INFO] [1499318605.694392977,1341.729000000]: waitForService: Service [/gazebo/set_physics_properties] is now available. [ INFO] [1499318605.875331513,1341.751000000]: Physics dynamic reconfigure ready. [Wrn] [Publisher.cc:141] Queue limit reached for topic /gazebo/default/pose/local/info,deleting message. This warning is printed only once.
----
----详细过程如下----
ROS / GAZEBO中的Prius演示
这是使用ROS kinetic发布的传感器数据的gazebo 8中的Prius的模拟。通过发布ROS消息来控制汽车的节气门,制动器,转向和换档。ROS节点允许使用游戏手柄或操纵杆进行驾驶。
要求(基本)
该演示已经在Ubuntu Xenial(16.04)
推荐(选配)
- 一个操纵杆
- 创建到
/dev/input/js0
或的链接的操纵杆驱动程序/dev/input/js1
编译
首先克隆repo,然后运行脚本build_demo.bash
。它使用本地源代码构建了一个docker映像。
$ cd car_demo $ ./build_demo.bash
运行
将游戏控制器连接到您的电脑。使用脚本run_demo.bash
运行演示。
$ ./run_demo.bash
一个RVIZ窗口将打开,显示汽车和传感器输出。将出现一个Gazebo窗口,显示模拟。使用控制器驱动世界各地的prius,或者点击Gazebo窗口并使用WASD
钥匙来驾驶汽车。
如果使用Logitech F710控制器:
- 确保MODE状态指示灯熄灭
- 将swtich设置为XInput模式
- 右侧杆控制油门和制动器
- 左键控制转向
- Y把车放进DRIVE
- A把车放进REVERSE
- B把车放到中性
----
先看效果:
Gazebo:
參考網址:
1. http://www.ros.org/news/2017/06/simulated-car-demo.html
2. https://github.com/NVIDIA/nvidia-docker
----
智能汽车仿真演示
我们很高兴用ROS Kinetic和Gazebo 8展示Mcity的Prius仿真。ROS使用现有的软件和库可以更快地开发模拟。车辆的节气门,制动器,转向和变速器通过发布到ROS主题进行控制。所有传感器数据都是使用ROS发布的,可以使用RViz进行可视化。
我们利用Gazebo 8的功能来整合现有的模型和传感器。仿真世界(环境)包含了一个新型的Mcity和交汇高速公路。还有来自Gazebo模型库的模型,包括垃圾箱,交通锥和加油站。在车辆本身上,屋顶上有一个16束激光雷达,8个超声波传感器,4个摄像头和2个平面激光雷达。
仿真模拟是开源的,可以在osit / osdf / car_demo上的GitHub上获得。通过安装nvidia-docker并从Docker Hub拉出“osrf / car_demo”来尝试。有关构建和运行的更多信息,请参阅源存储库中的README。
----
NVIDIA Docker
该存储库包括构建和运行NVIDIA Docker映像的实用程序。
@H_492_403@ @H_386_404@CUDA如何与Docker集成的示例文档
完整的文档可在存储库wiki中找到。
首先要了解为什么需要NVIDIA Docker,这是一个很好的开始。
快速开始
假设NVIDIA驱动程序和Docker已正确安装(请参阅安装)
Ubuntu发行版
#安装nvidia-docker和nvidia-docker-plugin wget -P / tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb sudo dpkg - i / tmp / nvidia-docker * .deb && rm / tmp / nvidia-docker * .deb#测试nvidia-smi nvidia-docker运行--rm nvidia / cuda nvidia-smi
----
先决条件
运行的先决条件列表nvidia-docker
如下所示。
有关如何为您的Linux发行版安装Docker的信息,请参阅Docker文档。
- GNU / Linux x86_64,内核版本> 3.10
- 多克尔> = 1.9(官方
docker-engine
,docker-ce
或docker-ee
仅) - NVIDIA GPU与架构>费米(2.1)
- NVIDIA驱动程序> = 340.29与二进制
nvidia-modprobe
您的驱动程序版本可能会限制您的CUDA功能(请参阅CUDA要求)
从二进制包安装
二进制包可在发行页面上下载。
软件包安装将自动设置nvidia-docker-plugin
并根据您的分发,将其注册到init系统。
从源头构建
在存储库问题的根目录make
或make install
构建二进制文件。
稍后还将在由环境变量设置的位置prefix
(/usr/local
默认情况下)处理二进制文件。您必须nvidia-docker-plugin
手动启动此方法:
sudo -b nohup nvidia-docker-plugin
或者,您可以为您的发行版使用make deb
或make rpm
生成deb / rpm软件包。
软件包安装将自动设置nvidia-docker-plugin
并根据您的分发,将其注册到init系统。
make clean
并make distclean
分别清理构建和分配环境。
----
@H_404_766@需要注意,依据驱动类型和显卡型号选择合适的CUDA版本:
@H_404_766@
CUDA图像有两种口味,可通过NVIDIA公共中心库存储。
runtime:一个轻量级的图像,包含最低限度,部署使用CUDA的预构建应用程序。devel
:通过添加编译器工具链,调试工具和标准CUDA库的开发文件来扩展运行时映像。使用此映像从源代码编译CUDA应用程序。
要求
运行CUDA容器需要一台具有至少一个支持CUDA功能的GPU和与您使用的CUDA工具包版本兼容的驱动程序。
运行CUDA容器的机器只需要NVIDIA驱动程序,不需要安装CUDA工具包。
NVIDIA驱动程序向后兼容CUDA工具包版本
CUDA工具包版本 | 驱动程序版本 | GPU架构 | |
---|---|---|---|
6.5 | > = 340.29 | > = 2.0(费米) | |
> = 346.46 | > = 2.0(费米) | ||
> = 352.39 | 8 | = 361.93或> = 375.51 | == 6.0(P100) |
> = 2.0(费米) |
例子
看一下样本部分,找到编译简单CUDA应用程序的Dockerfiles示例。
#运行交互式CUDA会话隔离第一个GPU NV_GPU = 0 nvidia-docker运行-ti --rm nvidia / cuda#查询CUDA 7.5编译器版本 nvidia-docker运行--rm nvidia / cuda:7.5-devel nvcc --version
----
挑战
安装用户级驱动程序库和设备文件会破坏容器的环境,只有当容器运行GPU应用程序时才应该执行。这里的挑战是确定给定的图像是否将使用GPU。我们还应该防止基于与主机NVIDIA驱动程序版本不兼容的Docker映像启动容器,您可以在此wiki页面上找到更多详细信息。
NVIDIA-泊坞窗
没有通用的解决方案来检测是否有任何图像将使用GPU代码。在nvidia-docker
我们假设基于我们的nvidia/cuda
图像(DockerHub上可用)的任何图像将是GPU应用程序,因此它们需要驱动程序卷和设备文件。
更具体地说,当nvidia-docker run
使用时,我们检查在命令行上指定的图像。在此图像中,我们查找标签的存在和值com.nvidia.volumes.needed
。nvidia/cuda
我们提供的图像开始时都包含这个标签。所有执行此操作的DockerfilesFROM nvidia/cuda
将自动继承此元数据,从而可以无缝工作nvidia-docker
。
为了检测图像与主机驱动程序不兼容,我们依赖于第二个元数据com.nvidia.cuda.version
标签。此标签存在于每个CUDA基本图像中,并具有相应的版本号。该版本与驱动程序支持的最大CUDA版本进行比较,为此目的nvidia-docker
使用CUDA API函数cudaDriverGetVersion
。如果驱动程序对于运行此版本的CUDA来说太旧了,则在启动容器之前会出现错误:
$ nvidia-docker run --rm nvidia/cuda nvidia-docker | 2016/04/21 21:41:35 Error: unsupported CUDA version: driver 7.0 < image 7.5
备择方案
在这种情况下,nvidia-docker
不会简单地将参数注入docker
命令行。因此,重现这种行为更复杂。您将需要检查工作流中的图像或容器编排解决方案中的图像。查看图像中的标签很简单:
$ docker inspect -f '{{index .Config.Labels "com.nvidia.volumes.needed"}}' nvidia/cuda nvidia_driver $ docker inspect -f '{{index .Config.Labels "com.nvidia.cuda.version"}}' nvidia/cuda 7.5
如果您构建自己的自定义CUDA映像,建议您为兼容性原因重用相同的标签。
----
原文链接:https://www.f2er.com/ubuntu/352304.html