[ROS] 安装Gazebo 使用Gazebo 实现摄像头仿真 雷达仿真 Kinect仿真

电玩女神 2023-02-17 15:57 73阅读 0赞

目录

安装Gazebo

1.添加源

2.安装gazebo

使用Gazepo 实现摄像头仿真

1.工作空间与功能包的创建

2)Gazebo配置文件

3)车体urdf建模与控制程序

4)launch文件

5)执行launch文件运行程序

使用Gazepo 实现雷达仿真

1)Launch文件

2) 执行

使用Gazepo 实现Kinect仿真

1)launch文件

2)执行


安装Gazebo

Gazeop是一款仿真软件,和ROS有非常好的兼容性,通常来说使用rviz就可以满足绝大部分需求,但是要考虑真实世界的物理属性的话(比如摩擦力,空气阻力,湿度,地面凹凸程度等),就需要用到Gazepo

1.添加源

sudo sh -c ‘echo “deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main” > /etc/apt/sources.list.d/gazebo-stable.list’

wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -

2.安装gazebo

sudo apt-get update

sudo apt-get install gazebo7

sudo apt-get install libgazebo7-dev

使用Gazepo 实现摄像头仿真

1.工作空间与功能包的创建

  1. //创建工作空间
  2. $ source /opt/ros/kinetic/setup.zsh
  3. $ mkdir -p ~/catkin_ws/src
  4. $ cd ~/catkin_ws/src
  5. $ catkin_init_workspace
  6. $ cd ~/catkin_ws
  7. $ catkin_make
  8. $ souce ~/catkiin_ws/devel/setup.zsh
  9. $ cd ~/catkin_ws/src
  10. //创建功能包
  11. $ catkin_create_pkg my_gazebo gazebo_plugins gazebo_ros gazebo_ros_control roscpp rospy
  12. $ cd ~/catkin_ws
  13. $ catkin_make
  14. $ source devel/setup.zsh
  15. //创建目录结构
  16. $ cd ~/catkin_ws/src/my_gazebo
  17. $ mkdir worlds launch

2)Gazebo配置文件

请按照下列方式命名,或修改launch文件

$ cd world

$ touch playground.world

该文件由Gazebo界面配置后导出,非手动编写,复制即可

  1. <sdf version='1.4'>
  2. <world name='default'>
  3. <light name='sun' type='directional'>
  4. <cast_shadows>1</cast_shadows>
  5. <pose>0 0 10 0 -0 0</pose>
  6. <diffuse>0.8 0.8 0.8 1</diffuse>
  7. <specular>0.2 0.2 0.2 1</specular>
  8. <attenuation>
  9. <range>1000</range>
  10. <constant>0.9</constant>
  11. <linear>0.01</linear>
  12. <quadratic>0.001</quadratic>
  13. </attenuation>
  14. <direction>0.5 0.1 -0.9</direction>
  15. </light>
  16. <scene>
  17. <ambient>0.4 0.4 0.4 1</ambient>
  18. <background>0.7 0.7 0.7 1</background>
  19. <shadows>1</shadows>
  20. </scene>
  21. <physics type='ode'>
  22. <max_step_size>0.01</max_step_size>
  23. <real_time_factor>1</real_time_factor>
  24. <real_time_update_rate>100</real_time_update_rate>
  25. <gravity>0 0 -9.8</gravity>
  26. </physics>
  27. <model name='bookshelf'>
  28. <static>1</static>
  29. <link name='link'>
  30. <inertial>
  31. <mass>1</mass>
  32. </inertial>
  33. <collision name='back'>
  34. <pose>0 0.005 0.6 0 -0 0</pose>
  35. <geometry>
  36. <box>
  37. <size>0.9 0.01 1.2</size>
  38. </box>
  39. </geometry>
  40. <max_contacts>10</max_contacts>
  41. <surface>
  42. <bounce/>
  43. <friction>
  44. <ode/>
  45. </friction>
  46. <contact>
  47. <ode/>
  48. </contact>
  49. </surface>
  50. </collision>
  51. <visual name='visual1'>
  52. <pose>0 0.005 0.6 0 -0 0</pose>
  53. <geometry>
  54. <box>
  55. <size>0.9 0.01 1.2</size>
  56. </box>
  57. </geometry>
  58. <material>
  59. <script>
  60. <uri>file://media/materials/scripts/gazebo.material</uri>
  61. <name>Gazebo/Wood</name>
  62. </script>
  63. </material>
  64. </visual>
  65. <collision name='left_side'>
  66. <pose>0.45 -0.195 0.6 0 -0 0</pose>
  67. <geometry>
  68. <box>
  69. <size>0.02 0.4 1.2</size>
  70. </box>
  71. </geometry>
  72. <max_contacts>10</max_contacts>
  73. <surface>
  74. <bounce/>
  75. <friction>
  76. <ode/>
  77. </friction>
  78. <contact>
  79. <ode/>
  80. </contact>
  81. </surface>
  82. </collision>
  83. <visual name='visual2'>
  84. <pose>0.45 -0.195 0.6 0 -0 0</pose>
  85. <geometry>
  86. <box>
  87. <size>0.02 0.4 1.2</size>
  88. </box>
  89. </geometry>
  90. <material>
  91. <script>
  92. <uri>file://media/materials/scripts/gazebo.material</uri>
  93. <name>Gazebo/Wood</name>
  94. </script>
  95. </material>
  96. </visual>
  97. <collision name='right_side'>
  98. <pose>-0.45 -0.195 0.6 0 -0 0</pose>
  99. <geometry>
  100. <box>
  101. <size>0.02 0.4 1.2</size>
  102. </box>
  103. </geometry>
  104. <max_contacts>10</max_contacts>
  105. <surface>
  106. <bounce/>
  107. <friction>
  108. <ode/>
  109. </friction>
  110. <contact>
  111. <ode/>
  112. </contact>
  113. </surface>
  114. </collision>
  115. <visual name='visual3'>
  116. <pose>-0.45 -0.195 0.6 0 -0 0</pose>
  117. <geometry>
  118. <box>
  119. <size>0.02 0.4 1.2</size>
  120. </box>
  121. </geometry>
  122. <material>
  123. <script>
  124. <uri>file://media/materials/scripts/gazebo.material</uri>
  125. <name>Gazebo/Wood</name>
  126. </script>
  127. </material>
  128. </visual>
  129. <collision name='bottom'>
  130. <pose>0 -0.195 0.03 0 -0 0</pose>
  131. <geometry>
  132. <box>
  133. <size>0.88 0.4 0.06</size>
  134. </box>
  135. </geometry>
  136. <max_contacts>10</max_contacts>
  137. <surface>
  138. <bounce/>
  139. <friction>
  140. <ode/>
  141. </friction>
  142. <contact>
  143. <ode/>
  144. </contact>
  145. </surface>
  146. </collision>
  147. <visual name='visual4'>
  148. <pose>0 -0.195 0.03 0 -0 0</pose>
  149. <geometry>
  150. <box>
  151. <size>0.88 0.4 0.06</size>
  152. </box>
  153. </geometry>
  154. <material>
  155. <script>
  156. <uri>file://media/materials/scripts/gazebo.material</uri>
  157. <name>Gazebo/Wood</name>
  158. </script>
  159. </material>
  160. </visual>
  161. <collision name='top'>
  162. <pose>0 -0.195 1.19 0 -0 0</pose>
  163. <geometry>
  164. <box>
  165. <size>0.88 0.4 0.02</size>
  166. </box>
  167. </geometry>
  168. <max_contacts>10</max_contacts>
  169. <surface>
  170. <bounce/>
  171. <friction>
  172. <ode/>
  173. </friction>
  174. <contact>
  175. <ode/>
  176. </contact>
  177. </surface>
  178. </collision>
  179. <visual name='visual5'>
  180. <pose>0 -0.195 1.19 0 -0 0</pose>
  181. <geometry>
  182. <box>
  183. <size>0.88 0.4 0.02</size>
  184. </box>
  185. </geometry>
  186. <material>
  187. <script>
  188. <uri>file://media/materials/scripts/gazebo.material</uri>
  189. <name>Gazebo/Wood</name>
  190. </script>
  191. </material>
  192. </visual>
  193. <collision name='low_shelf'>
  194. <pose>0 -0.195 0.43 0 -0 0</pose>
  195. <geometry>
  196. <box>
  197. <size>0.88 0.4 0.02</size>
  198. </box>
  199. </geometry>
  200. <max_contacts>10</max_contacts>
  201. <surface>
  202. <bounce/>
  203. <friction>
  204. <ode/>
  205. </friction>
  206. <contact>
  207. <ode/>
  208. </contact>
  209. </surface>
  210. </collision>
  211. <visual name='visual6'>
  212. <pose>0 -0.195 0.43 0 -0 0</pose>
  213. <geometry>
  214. <box>
  215. <size>0.88 0.4 0.02</size>
  216. </box>
  217. </geometry>
  218. <material>
  219. <script>
  220. <uri>file://media/materials/scripts/gazebo.material</uri>
  221. <name>Gazebo/Wood</name>
  222. </script>
  223. </material>
  224. </visual>
  225. <collision name='high_shelf'>
  226. <pose>0 -0.195 0.8 0 -0 0</pose>
  227. <geometry>
  228. <box>
  229. <size>0.88 0.4 0.02</size>
  230. </box>
  231. </geometry>
  232. <max_contacts>10</max_contacts>
  233. <surface>
  234. <bounce/>
  235. <friction>
  236. <ode/>
  237. </friction>
  238. <contact>
  239. <ode/>
  240. </contact>
  241. </surface>
  242. </collision>
  243. <visual name='visual7'>
  244. <pose>0 -0.195 0.8 0 -0 0</pose>
  245. <geometry>
  246. <box>
  247. <size>0.88 0.4 0.02</size>
  248. </box>
  249. </geometry>
  250. <material>
  251. <script>
  252. <uri>file://media/materials/scripts/gazebo.material</uri>
  253. <name>Gazebo/Wood</name>
  254. </script>
  255. </material>
  256. </visual>
  257. <velocity_decay>
  258. <linear>0</linear>
  259. <angular>0</angular>
  260. </velocity_decay>
  261. <self_collide>0</self_collide>
  262. <kinematic>0</kinematic>
  263. <gravity>1</gravity>
  264. </link>
  265. <pose>0 1.53026 0 0 -0 0</pose>
  266. </model>
  267. <model name='jersey_barrier'>
  268. <static>1</static>
  269. <link name='link'>
  270. <visual name='visual'>
  271. <geometry>
  272. <mesh>
  273. <uri>model://jersey_barrier/meshes/jersey_barrier.dae</uri>
  274. </mesh>
  275. </geometry>
  276. </visual>
  277. <collision name='upright'>
  278. <pose>0 0 0.5715 0 -0 0</pose>
  279. <geometry>
  280. <box>
  281. <size>4.06542 0.3063 1.143</size>
  282. </box>
  283. </geometry>
  284. <max_contacts>10</max_contacts>
  285. <surface>
  286. <bounce/>
  287. <friction>
  288. <ode/>
  289. </friction>
  290. <contact>
  291. <ode/>
  292. </contact>
  293. </surface>
  294. </collision>
  295. <collision name='base'>
  296. <pose>0 0 0.032258 0 -0 0</pose>
  297. <geometry>
  298. <box>
  299. <size>4.06542 0.8107 0.064516</size>
  300. </box>
  301. </geometry>
  302. <max_contacts>10</max_contacts>
  303. <surface>
  304. <bounce/>
  305. <friction>
  306. <ode/>
  307. </friction>
  308. <contact>
  309. <ode/>
  310. </contact>
  311. </surface>
  312. </collision>
  313. <collision name='base2'>
  314. <pose>0 0 0.1 0 -0 0</pose>
  315. <geometry>
  316. <box>
  317. <size>4.06542 0.65 0.1</size>
  318. </box>
  319. </geometry>
  320. <max_contacts>10</max_contacts>
  321. <surface>
  322. <bounce/>
  323. <friction>
  324. <ode/>
  325. </friction>
  326. <contact>
  327. <ode/>
  328. </contact>
  329. </surface>
  330. </collision>
  331. <collision name='base3'>
  332. <pose>0 0 0.2 0 -0 0</pose>
  333. <geometry>
  334. <box>
  335. <size>4.06542 0.5 0.1</size>
  336. </box>
  337. </geometry>
  338. <max_contacts>10</max_contacts>
  339. <surface>
  340. <bounce/>
  341. <friction>
  342. <ode/>
  343. </friction>
  344. <contact>
  345. <ode/>
  346. </contact>
  347. </surface>
  348. </collision>
  349. <collision name='left-angle'>
  350. <pose>0 -0.224 0.2401 0.9 -0 0</pose>
  351. <geometry>
  352. <box>
  353. <size>4.06542 0.5 0.064516</size>
  354. </box>
  355. </geometry>
  356. <max_contacts>10</max_contacts>
  357. <surface>
  358. <bounce/>
  359. <friction>
  360. <ode/>
  361. </friction>
  362. <contact>
  363. <ode/>
  364. </contact>
  365. </surface>
  366. </collision>
  367. <collision name='right-angle'>
  368. <pose>0 0.224 0.2401 -0.9 0 0</pose>
  369. <geometry>
  370. <box>
  371. <size>4.06542 0.5 0.064516</size>
  372. </box>
  373. </geometry>
  374. <max_contacts>10</max_contacts>
  375. <surface>
  376. <bounce/>
  377. <friction>
  378. <ode/>
  379. </friction>
  380. <contact>
  381. <ode/>
  382. </contact>
  383. </surface>
  384. </collision>
  385. <velocity_decay>
  386. <linear>0</linear>
  387. <angular>0</angular>
  388. </velocity_decay>
  389. <self_collide>0</self_collide>
  390. <kinematic>0</kinematic>
  391. <gravity>1</gravity>
  392. </link>
  393. <pose>-4 -1 0 0 -0 -0.7</pose>
  394. </model>
  395. <model name='ground_plane_0'>
  396. <static>1</static>
  397. <link name='link'>
  398. <collision name='collision'>
  399. <geometry>
  400. <plane>
  401. <normal>0 0 1</normal>
  402. <size>100 100</size>
  403. </plane>
  404. </geometry>
  405. <surface>
  406. <friction>
  407. <ode>
  408. <mu>100</mu>
  409. <mu2>50</mu2>
  410. </ode>
  411. </friction>
  412. <bounce/>
  413. <contact>
  414. <ode/>
  415. </contact>
  416. </surface>
  417. <max_contacts>10</max_contacts>
  418. </collision>
  419. <visual name='visual'>
  420. <cast_shadows>0</cast_shadows>
  421. <geometry>
  422. <plane>
  423. <normal>0 0 1</normal>
  424. <size>100 100</size>
  425. </plane>
  426. </geometry>
  427. <material>
  428. <script>
  429. <uri>file://media/materials/scripts/gazebo.material</uri>
  430. <name>Gazebo/Grey</name>
  431. </script>
  432. </material>
  433. </visual>
  434. <velocity_decay>
  435. <linear>0</linear>
  436. <angular>0</angular>
  437. </velocity_decay>
  438. <self_collide>0</self_collide>
  439. <kinematic>0</kinematic>
  440. <gravity>1</gravity>
  441. </link>
  442. <pose>0.497681 0 0 0 -0 0</pose>
  443. </model>
  444. <state world_name='default'>
  445. <sim_time>0 0</sim_time>
  446. <real_time>0 44986</real_time>
  447. <wall_time>1377677575 940727583</wall_time>
  448. <model name='Dumpster'>
  449. <pose>1 -3.44458 0 0 -0 0</pose>
  450. <link name='link'>
  451. <pose>1 -3.44458 0 0 -0 0</pose>
  452. <velocity>0 0 0 0 -0 0</velocity>
  453. <acceleration>0 0 0 0 -0 0</acceleration>
  454. <wrench>0 0 0 0 -0 0</wrench>
  455. </link>
  456. </model>
  457. <model name='cube_20k'>
  458. <pose>1.41131 -1 0 0 -0 0.9</pose>
  459. <link name='link'>
  460. <pose>1.41131 -1 0.5 0 -0 0.9</pose>
  461. <velocity>0 0 0 0 -0 0</velocity>
  462. <acceleration>0 0 0 0 -0 0</acceleration>
  463. <wrench>0 0 0 0 -0 0</wrench>
  464. </link>
  465. </model>
  466. <model name='unit_cylinder_1'>
  467. <pose>-2 -3.4888 0.5 0 -0 0</pose>
  468. <link name='link'>
  469. <pose>-2 -3.4888 0.5 0 -0 0</pose>
  470. <velocity>0 0 0 0 -0 0</velocity>
  471. <acceleration>0 0 0 0 -0 0</acceleration>
  472. <wrench>0 0 0 0 -0 0</wrench>
  473. </link>
  474. </model>
  475. </state>
  476. <gui fullscreen='0'>
  477. <camera name='user_camera'>
  478. <pose>1.33336 -0.422442 27.6101 3e-06 1.5698 3.04015</pose>
  479. <view_controller>orbit</view_controller>
  480. </camera>
  481. </gui>
  482. <model name='unit_cylinder_1'>
  483. <pose>-2 -3.4888 0.5 0 -0 0</pose>
  484. <link name='link'>
  485. <inertial>
  486. <mass>1</mass>
  487. <inertia>
  488. <ixx>1</ixx>
  489. <ixy>0</ixy>
  490. <ixz>0</ixz>
  491. <iyy>1</iyy>
  492. <iyz>0</iyz>
  493. <izz>1</izz>
  494. </inertia>
  495. </inertial>
  496. <collision name='collision'>
  497. <geometry>
  498. <cylinder>
  499. <radius>0.5</radius>
  500. <length>1</length>
  501. </cylinder>
  502. </geometry>
  503. <max_contacts>10</max_contacts>
  504. <surface>
  505. <bounce/>
  506. <friction>
  507. <ode/>
  508. </friction>
  509. <contact>
  510. <ode/>
  511. </contact>
  512. </surface>
  513. </collision>
  514. <visual name='visual'>
  515. <geometry>
  516. <cylinder>
  517. <radius>0.5</radius>
  518. <length>1</length>
  519. </cylinder>
  520. </geometry>
  521. <material>
  522. <script>
  523. <uri>file://media/materials/scripts/gazebo.material</uri>
  524. <name>Gazebo/Grey</name>
  525. </script>
  526. </material>
  527. </visual>
  528. <velocity_decay>
  529. <linear>0</linear>
  530. <angular>0</angular>
  531. </velocity_decay>
  532. <self_collide>0</self_collide>
  533. <kinematic>0</kinematic>
  534. <gravity>1</gravity>
  535. </link>
  536. <static>0</static>
  537. </model>
  538. <model name='Dumpster'>
  539. <link name='link'>
  540. <collision name='collision'>
  541. <geometry>
  542. <mesh>
  543. <uri>model://dumpster/meshes/dumpster.dae</uri>
  544. </mesh>
  545. </geometry>
  546. <max_contacts>10</max_contacts>
  547. <surface>
  548. <bounce/>
  549. <friction>
  550. <ode/>
  551. </friction>
  552. <contact>
  553. <ode/>
  554. </contact>
  555. </surface>
  556. </collision>
  557. <visual name='visual'>
  558. <geometry>
  559. <mesh>
  560. <uri>model://dumpster/meshes/dumpster.dae</uri>
  561. </mesh>
  562. </geometry>
  563. <material>
  564. <script>
  565. <uri>model://dumpster/materials/scripts</uri>
  566. <uri>model://dumpster/materials/textures</uri>
  567. <name>Dumpster/Diffuse</name>
  568. </script>
  569. </material>
  570. </visual>
  571. <velocity_decay>
  572. <linear>0</linear>
  573. <angular>0</angular>
  574. </velocity_decay>
  575. <self_collide>0</self_collide>
  576. <inertial>
  577. <inertia>
  578. <ixx>1</ixx>
  579. <ixy>0</ixy>
  580. <ixz>0</ixz>
  581. <iyy>1</iyy>
  582. <iyz>0</iyz>
  583. <izz>1</izz>
  584. </inertia>
  585. <mass>1</mass>
  586. </inertial>
  587. <kinematic>0</kinematic>
  588. <gravity>1</gravity>
  589. </link>
  590. <pose>1 -3.44458 0 0 -0 -0.3</pose>
  591. <static>0</static>
  592. </model>
  593. <model name='cube_20k'>
  594. <link name='link'>
  595. <pose>0 0 0.5 0 -0 0</pose>
  596. <collision name='collision'>
  597. <geometry>
  598. <mesh>
  599. <uri>model://cube_20k/meshes/cube_20k.stl</uri>
  600. <scale>0.5 0.5 0.5</scale>
  601. </mesh>
  602. </geometry>
  603. <max_contacts>10</max_contacts>
  604. <surface>
  605. <bounce/>
  606. <friction>
  607. <ode/>
  608. </friction>
  609. <contact>
  610. <ode/>
  611. </contact>
  612. </surface>
  613. </collision>
  614. <visual name='visual'>
  615. <geometry>
  616. <mesh>
  617. <uri>model://cube_20k/meshes/cube_20k.stl</uri>
  618. <scale>0.5 0.5 0.5</scale>
  619. </mesh>
  620. </geometry>
  621. </visual>
  622. <velocity_decay>
  623. <linear>0</linear>
  624. <angular>0</angular>
  625. </velocity_decay>
  626. <self_collide>0</self_collide>
  627. <inertial>
  628. <inertia>
  629. <ixx>1</ixx>
  630. <ixy>0</ixy>
  631. <ixz>0</ixz>
  632. <iyy>1</iyy>
  633. <iyz>0</iyz>
  634. <izz>1</izz>
  635. </inertia>
  636. <mass>1</mass>
  637. </inertial>
  638. <kinematic>0</kinematic>
  639. <gravity>1</gravity>
  640. </link>
  641. <pose>1.41131 -1 0 0 -0 0.9</pose>
  642. <static>0</static>
  643. </model>
  644. </world>
  645. </sdf>

3)车体urdf建模与控制程序

非常建议阅读该篇文章后再阅读下面内容

ROS ArbotiX控制+xacro机器人仿真模型设计 实现初级建模与车体控制

或下载

urdf描述包:https://gitee.com/alen2020/mbot_description.git

车体控制包:https://gitee.com/alen2020/mbot_teleop.git

4)launch文件

在加载机器人模型描述参数这里引入了功能包,若没有该功能包需要看上一节给出的链接文件,里面介绍到xacro文件的编写,或有自己的一套车体模型,则引入自己的,注意命名。

  1. <launch>
  2. <!-- 设置launch文件的参数 -->
  3. <arg name="world_name" value="$(find mbot_gazebo)/worlds/playground.world"/>
  4. <arg name="paused" default="false"/>
  5. <arg name="use_sim_time" default="true"/>
  6. <arg name="gui" default="true"/>
  7. <arg name="headless" default="false"/>
  8. <arg name="debug" default="false"/>
  9. <!-- 运行gazebo仿真环境 -->
  10. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  11. <arg name="world_name" value="$(arg world_name)" />
  12. <arg name="debug" value="$(arg debug)" />
  13. <arg name="gui" value="$(arg gui)" />
  14. <arg name="paused" value="$(arg paused)"/>
  15. <arg name="use_sim_time" value="$(arg use_sim_time)"/>
  16. <arg name="headless" value="$(arg headless)"/>
  17. </include>
  18. <!-- 加载机器人模型描述参数 -->
  19. <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_with_camera_gazebo.xacro'" />
  20. <!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
  21. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
  22. <!-- 运行robot_state_publisher节点,发布tf -->
  23. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" >
  24. <param name="publish_frequency" type="double" value="50.0" />
  25. </node>
  26. <!-- 在gazebo中加载机器人模型-->
  27. <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  28. args="-urdf -model mrobot -param robot_description"/>
  29. </launch>

5)执行launch文件运行程序

开启三个终端,执行下三条指令

  1. $ roslaunch test1 view_mbot_with_camera_gazebo.launch
  2. $ roslaunch mbot_teleop mbot_teleop.launch
  3. $ rqt_image_view

在rqt_image_view中选择订阅/camera/image_raw话题,移动车体,即可看到实时视图

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NrNzg0MTAxNzc3_size_16_color_FFFFFF_t_70

使用Gazepo 实现雷达仿真

1)Launch文件

使用雷达仿真修改launch文件即可,前提是有车体urdf建模这个包,我在上一节给出

与摄像头不同的是xacro的引入文件

  1. <launch>
  2. <!-- 设置launch文件的参数 -->
  3. <arg name="world_name" value="$(find mbot_gazebo)/worlds/playground.world"/>
  4. <arg name="paused" default="false"/>
  5. <arg name="use_sim_time" default="true"/>
  6. <arg name="gui" default="true"/>
  7. <arg name="headless" default="false"/>
  8. <arg name="debug" default="false"/>
  9. <!-- 运行gazebo仿真环境 -->
  10. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  11. <arg name="world_name" value="$(arg world_name)" />
  12. <arg name="debug" value="$(arg debug)" />
  13. <arg name="gui" value="$(arg gui)" />
  14. <arg name="paused" value="$(arg paused)"/>
  15. <arg name="use_sim_time" value="$(arg use_sim_time)"/>
  16. <arg name="headless" value="$(arg headless)"/>
  17. </include>
  18. <!-- 加载机器人模型描述参数 -->
  19. <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_with_laser_gazebo.xacro'" />
  20. <!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
  21. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
  22. <!-- 运行robot_state_publisher节点,发布tf -->
  23. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" >
  24. <param name="publish_frequency" type="double" value="50.0" />
  25. </node>
  26. <!-- 在gazebo中加载机器人模型-->
  27. <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  28. args="-urdf -model mrobot -param robot_description"/>
  29. </launch>

2) 执行

开启三个终端,执行下三条指令

  1. $ roslaunch test1 view_mbot_with_laser_gazebo.launch
  2. $ roslaunch mbot_teleop mbot_teleop.launch
  3. $ rviz

可以看到单线激光雷达的点云数据,控制车体移动,点云数据实时变动

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NrNzg0MTAxNzc3_size_16_color_FFFFFF_t_70 1

使用Gazepo 实现Kinect仿真

1)launch文件

使用Kinect仿真修改launch文件即可,前提是有车体urdf建模这个包,我在第一节给出

与摄像头和激光雷达不同的是xacro的引入文件

  1. <launch>
  2. <!-- 设置launch文件的参数 -->
  3. <arg name="world_name" value="$(find mbot_gazebo)/worlds/playground.world"/>
  4. <arg name="paused" default="false"/>
  5. <arg name="use_sim_time" default="true"/>
  6. <arg name="gui" default="true"/>
  7. <arg name="headless" default="false"/>
  8. <arg name="debug" default="false"/>
  9. <!-- 运行gazebo仿真环境 -->
  10. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  11. <arg name="world_name" value="$(arg world_name)" />
  12. <arg name="debug" value="$(arg debug)" />
  13. <arg name="gui" value="$(arg gui)" />
  14. <arg name="paused" value="$(arg paused)"/>
  15. <arg name="use_sim_time" value="$(arg use_sim_time)"/>
  16. <arg name="headless" value="$(arg headless)"/>
  17. </include>
  18. <!-- 加载机器人模型描述参数 -->
  19. <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_with_kinect_gazebo.xacro'" />
  20. <!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
  21. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
  22. <!-- 运行robot_state_publisher节点,发布tf -->
  23. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" >
  24. <param name="publish_frequency" type="double" value="50.0" />
  25. </node>
  26. <!-- 在gazebo中加载机器人模型-->
  27. <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  28. args="-urdf -model mrobot -param robot_description"/>
  29. </launch>

2)执行

  1. $ roslaunch test1 view_mbot_with_laser_gazebo.launch
  2. $ roslaunch mbot_teleop mbot_teleop.launch
  3. $ rqt_image_view
  4. $ rviz

kinect既可以看到点云数据,也可以看到摄像头信息,相对于激光雷达来说,Kinect的点云扫射访问很窄(通常不超过180度)

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NrNzg0MTAxNzc3_size_16_color_FFFFFF_t_70 2

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NrNzg0MTAxNzc3_size_16_color_FFFFFF_t_70 3

发表评论

表情:
评论列表 (有 0 条评论,73人围观)

还没有评论,来说两句吧...

相关阅读