在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示

举报
zhangrelay 发表于 2021/07/15 05:03:05 2021/07/15
【摘要】 在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示 智能车无人驾驶技术是目前人工智能和机器人技术的研究热点,有许多开源平台可以使我们零基础零成本入门无人驾驶技术。本文分享一下目前ROS官网最新推荐的一款开源汽车仿真模拟。使用的平台为Ubuntu 16.04 + ROS Kinetic + Gazebo 8。同时需要具备Docker和nvidia-docker的基...

在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安装

请参考文末附录。如果出现如下错误,请按附录内容进行修正:


  
  1. $ nvidia-docker run -ti --rm nvidia/cuda
  2. 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

----


  
  1. relaybot@relaybot-desktop:~/Rob_Soft/car_demo-master$ ./build_demo.bash
  2. [sudo] password for relaybot:
  3. Sending build context to Docker daemon 58.96MB
  4. Step 1/12 : FROM osrf/ros:kinetic-desktop
  5. ---> fe1c52012515
  6. Step 2/12 : LABEL com.nvidia.volumes.needed "nvidia_driver"
  7. ---> Using cache
  8. ---> c0a552983f0f
  9. Step 3/12 : ENV PATH /usr/local/nvidia/bin:${PATH}
  10. ---> Using cache
  11. ---> b4336a6fcd17
  12. Step 4/12 : ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH}
  13. ---> Using cache
  14. ---> d9f0873b5c72
  15. Step 5/12 : RUN apt-get update && apt-get install -y wget lsb-release sudo mesa-utils && apt-get clean
  16. ---> Using cache
  17. ---> d1d2e996eae1
  18. 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
  19. ---> Using cache
  20. ---> 62e82befdf92
  21. Step 7/12 : RUN mkdir -p /tmp/workspace/src
  22. ---> Using cache
  23. ---> 3344777de771
  24. Step 8/12 : COPY prius_description /tmp/workspace/src/prius_description
  25. ---> Using cache
  26. ---> d6c8c42918c2
  27. Step 9/12 : COPY prius_msgs /tmp/workspace/src/prius_msgs
  28. ---> Using cache
  29. ---> ce2281718303
  30. Step 10/12 : COPY car_demo /tmp/workspace/src/car_demo
  31. ---> Using cache
  32. ---> ca825da11474
  33. Step 11/12 : RUN /bin/bash -c 'cd /tmp/workspace && source /opt/ros/kinetic/setup.bash && catkin_make'
  34. ---> Using cache
  35. ---> a78d42ed877a
  36. Step 12/12 : CMD /bin/bash -c source /opt/ros/kinetic/setup.bash && source /tmp/workspace/devel/setup.bash && roslaunch car_demo demo.launch
  37. ---> Using cache
  38. ---> 20890ac15cee
  39. Successfully built 20890ac15cee
  40. Successfully tagged osrf/car_demo:latest
  41. relaybot@relaybot-desktop:~/Rob_Soft/car_demo-master$


----

$ ./run_demo.bash


  
  1. $ ./run_demo.bash
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. ... logging to /root/.ros/log/31d9adfa-620b-11e7-a113-0242ac110002/roslaunch-a0950e425e8e-82.log
  4. Checking log directory for disk usage. This may take awhile.
  5. Press Ctrl-C to interrupt
  6. Done checking log file disk usage. Usage is <1GB.
  7. started roslaunch server http://a0950e425e8e:37129/
  8. SUMMARY
  9. ========
  10. PARAMETERS
  11. * /joy_node0/dev: /dev/input/js0
  12. * /joy_node1/dev: /dev/input/js1
  13. * /robot_description: <?xml version="1....
  14. * /rosdistro: kinetic
  15. * /rosversion: 1.12.7
  16. * /use_sim_time: True
  17. NODES
  18. /
  19. fake_localization (fake_localization/fake_localization)
  20. gazebo (gazebo_ros/gzserver)
  21. gazebo_gui (gazebo_ros/gzclient)
  22. joy_node0 (joy/joy_node)
  23. joy_node1 (joy/joy_node)
  24. joystick_translator (car_demo/joystick_translator)
  25. robot_state_publisher (robot_state_publisher/robot_state_publisher)
  26. rviz (rviz/rviz)
  27. spawn_urdf (gazebo_ros/spawn_model)
  28. very_inaccurate_odom (tf2_ros/static_transform_publisher)
  29. auto-starting new master
  30. process[master]: started with pid [93]
  31. ROS_MASTER_URI=http://localhost:11311
  32. setting /run_id to 31d9adfa-620b-11e7-a113-0242ac110002
  33. process[rosout-1]: started with pid [106]
  34. started core service [/rosout]
  35. process[gazebo-2]: started with pid [109]
  36. process[gazebo_gui-3]: started with pid [113]
  37. process[robot_state_publisher-4]: started with pid [142]
  38. process[fake_localization-5]: started with pid [195]
  39. process[very_inaccurate_odom-6]: started with pid [196]
  40. process[joystick_translator-7]: started with pid [255]
  41. process[joy_node0-8]: started with pid [299]
  42. process[joy_node1-9]: started with pid [300]
  43. Gazebo multi-robot simulator, version 8.1.1
  44. Copyright (C) 2012 Open Source Robotics Foundation.
  45. Released under the Apache 2 License.
  46. http://gazebosim.org
  47. process[spawn_urdf-10]: started with pid [328]
  48. process[rviz-11]: started with pid [356]
  49. [ INFO] [1499318590.218434440]: Finished loading Gazebo ROS API Plugin.
  50. [Msg] Waiting for master.
  51. [ INFO] [1499318590.220829714]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting...
  52. [Msg] Connected to gazebo master @ http://127.0.0.1:11345
  53. [Msg] Publicized address: 172.17.0.2
  54. [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported
  55. [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported
  56. [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported
  57. [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported
  58. [Wrn] [ColladaLoader.cc:1804] Triangle input semantic: 'TEXCOORD' is currently not supported
  59. [spawn_urdf-10] process has finished cleanly
  60. log file: /root/.ros/log/31d9adfa-620b-11e7-a113-0242ac110002/spawn_urdf-10*.log
  61. [ INFO] [1499318597.020363774, 1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/'
  62. [ INFO] [1499318597.029090560, 1341.708000000]: Camera Plugin (ns = /) <tf_prefix_>, set to ""
  63. [ WARN] [1499318597.051198614, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  64. [ WARN] [1499318597.051501949, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  65. [ INFO] [1499318597.051634287, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  66. [ INFO] [1499318597.051772773, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  67. [ WARN] [1499318597.071652157, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  68. [ WARN] [1499318597.071737149, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  69. [ INFO] [1499318597.071765174, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  70. [ INFO] [1499318597.071788477, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  71. [ WARN] [1499318597.074830942, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  72. [ WARN] [1499318597.075126204, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  73. [ INFO] [1499318597.075418562, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  74. [ INFO] [1499318597.075720639, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  75. [ WARN] [1499318597.089499716, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  76. [ WARN] [1499318597.090064739, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  77. [ INFO] [1499318597.090382446, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  78. [ INFO] [1499318597.090626321, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  79. [ INFO] [1499318603.934692266, 1341.708000000]: Block laser plugin missing <gaussianNoise>, defaults to 0.0
  80. [ INFO] [1499318603.934773061, 1341.708000000]: Block laser plugin missing <hokuyoMinIntensity>, defaults to 101
  81. [ INFO] [1499318603.934847668, 1341.708000000]: Block laser plugin missing <updateRate>, defaults to 0
  82. [ INFO] [1499318604.031684097, 1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/'
  83. [ WARN] [1499318604.036142916, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  84. [ WARN] [1499318604.036419387, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  85. [ INFO] [1499318604.036500172, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  86. [ INFO] [1499318604.036576326, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  87. [ INFO] [1499318604.048912318, 1341.708000000]: Camera Plugin (ns = /) <tf_prefix_>, set to ""
  88. [ INFO] [1499318604.601344650, 1341.708000000]: Laser Plugin: Using the 'robotNamespace' param: '/'
  89. [ INFO] [1499318604.602166296, 1341.708000000]: Starting Laser Plugin (ns = /)!
  90. [ INFO] [1499318604.609125255, 1341.708000000]: Laser Plugin (ns = /) <tf_prefix_>, set to ""
  91. [ WARN] [1499318604.622696602, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  92. [ WARN] [1499318604.622786468, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  93. [ INFO] [1499318604.622838959, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  94. [ INFO] [1499318604.622875155, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  95. [ WARN] [1499318604.675410176, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  96. [ WARN] [1499318604.675486412, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  97. [ INFO] [1499318604.675527058, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  98. [ INFO] [1499318604.675556004, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  99. [ INFO] [1499318605.145527632, 1341.708000000]: Laser Plugin: Using the 'robotNamespace' param: '/'
  100. [ INFO] [1499318605.145614241, 1341.708000000]: Starting Laser Plugin (ns = /)!
  101. [ INFO] [1499318605.154089749, 1341.708000000]: Laser Plugin (ns = /) <tf_prefix_>, set to ""
  102. [ WARN] [1499318605.158758063, 1341.708000000]: Range plugin missing <radiation>, defaults to ultrasound
  103. [ WARN] [1499318605.158840499, 1341.708000000]: Range plugin missing <fov>, defaults to 0.05
  104. [ INFO] [1499318605.158877742, 1341.708000000]: Range plugin missing <gaussianNoise>, defaults to 0.0
  105. [ INFO] [1499318605.158909882, 1341.708000000]: Range plugin missing <updateRate>, defaults to 0
  106. [ INFO] [1499318605.244331364, 1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/'
  107. [ INFO] [1499318605.260901986, 1341.708000000]: Camera Plugin: Using the 'robotNamespace' param: '/'
  108. [ INFO] [1499318605.268178012, 1341.708000000]: Camera Plugin (ns = /) <tf_prefix_>, set to ""
  109. [ INFO] [1499318605.295667008, 1341.708000000]: Camera Plugin (ns = /) <tf_prefix_>, set to ""
  110. [Wrn] [PriusHybridPlugin.cc:361] PriusHybridPlugin loading params
  111. [ INFO] [1499318605.487444516, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: rear_right_wheel_joint
  112. [ INFO] [1499318605.487560947, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: rear_left_wheel_joint
  113. [ INFO] [1499318605.487821573, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_right_wheel_joint
  114. [ INFO] [1499318605.487860817, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_left_wheel_joint
  115. [ INFO] [1499318605.487897223, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_right_steer_joint
  116. [ INFO] [1499318605.487938402, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: front_left_steer_joint
  117. [ INFO] [1499318605.487983362, 1341.708000000]: GazeboRosJointStatePublisher is going to publish joint: steering_joint
  118. [ INFO] [1499318605.488209156, 1341.708000000]: Starting GazeboRosJointStatePublisher Plugin (ns = //)!, parent name: prius
  119. [ INFO] [1499318605.694392977, 1341.729000000]: waitForService: Service [/gazebo/set_physics_properties] is now available.
  120. [ INFO] [1499318605.875331513, 1341.751000000]: Physics dynamic reconfigure ready.
  121. [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映像。


  
  1. $ cd car_demo
  2. $ ./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


----

智能汽车仿真演示

OSRF博客转载

我们很高兴用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映像的实用程序。

NVIDIA-GPU-泊坞窗

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文档

  1. GNU / Linux x86_64,内核版本> 3.10
  2. 多克尔> = 1.9(官方docker-enginedocker-cedocker-ee仅)
  3. NVIDIA GPU与架构>费米(2.1)
  4. NVIDIA驱动程序 > = 340.29与二进制nvidia-modprobe

您的驱动程序版本可能会限制您的CUDA功能(请参阅CUDA要求

从二进制包安装

二进制包可在发行页面上下载

软件包安装将自动设置nvidia-docker-plugin并根据您的分发,将其注册到init系统。

从源头构建

在存储库问题的根目录makemake install构建二进制文件。
稍后还将在由环境变量设置的位置prefix/usr/local默认情况下)处理二进制文件您必须nvidia-docker-plugin手动启动此方法:

sudo -b nohup nvidia-docker-plugin

 

或者,您可以为您的发行版使用make debmake rpm生成deb / rpm软件包。
软件包安装将自动设置nvidia-docker-plugin并根据您的分发,将其注册到init系统。

make cleanmake distclean分别清理构建和分配环境。


----

需要注意,依据驱动类型和显卡型号选择合适的CUDA版本:

CUDA图像有两种口味,可通过NVIDIA公共中心库存储

runtime:一个轻量级的图像,包含最低限度,部署使用CUDA的预构建应用程序。
devel:通过添加编译器工具链,调试工具和标准CUDA库的开发文件来扩展运行时映像。使用此映像从源代码编译CUDA应用程序。

要求

运行CUDA容器需要一台具有至少一个支持CUDA功能的GPU和与您使用的CUDA工具包版本兼容的驱动程序。
运行CUDA容器的机器只需要NVIDIA驱动程序,不需要安装CUDA工具包。

NVIDIA驱动程序向后兼容 CUDA工具包版本

CUDA工具包版本 驱动程序版本 GPU架构
6.5 > = 340.29 > = 2.0(费米)
7 > = 346.46 > = 2.0(费米)
7.5 > = 352.39 > = 2.0(费米)
8 = 361.93或> = 375.51 == 6.0(P100)
8 > = 367.48 > = 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.needednvidia/cuda我们提供图像开始时都包含这个标签所有执行此操作的Dockerfiles FROM nvidia/cuda将自动继承此元数据,从而可以无缝工作nvidia-docker

为了检测图像与主机驱动程序不兼容,我们依赖于第二个元数据com.nvidia.cuda.version标签此标签存在于每个CUDA基本图像中,并具有相应的版本号。该版本与驱动程序支持的最大CUDA版本进行比较,为此目的nvidia-docker使用CUDA API函数cudaDriverGetVersion如果驱动程序对于运行此版本的CUDA来说太旧了,则在启动容器之前会出现错误:


  
  1. $ nvidia-docker run --rm nvidia/cuda
  2. nvidia-docker | 2016/04/21 21:41:35 Error: unsupported CUDA version: driver 7.0 < image 7.5

备择方案

在这种情况下,nvidia-docker不会简单地将参数注入docker命令行。因此,重现这种行为更复杂。您将需要检查工作流中的图像或容器编排解决方案中的图像。查看图像中的标签很简单:


  
  1. $ docker inspect -f '{{index .Config.Labels "com.nvidia.volumes.needed"}}' nvidia/cuda
  2. nvidia_driver
  3. $ docker inspect -f '{{index .Config.Labels "com.nvidia.cuda.version"}}' nvidia/cuda
  4. 7.5

如果您构建自己的自定义CUDA映像,建议您为兼容性原因重用相同的标签。


----


文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/74534069

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。