当前位置:   article > 正文

ROS学习笔记之——gazebo模型(URDF)_gazebo urdf

gazebo urdf

最近在学习gazebo仿真。在之前博文里面《学习笔记之——gazebo仿真》,在介绍深度相机的ROS插件的时候,涉及到了gazebo里面的一些模型文件架构的定义。本博文主要是对模型文件的定义做学习记录

 

目录

Model

URDF

参考资料


 

Model

首先介绍一下怎么在gazebo的模型库里面添加模型(之前博客已经试过修改已有模型了《学习笔记之——gazebo仿真》)

Create a directory for your model under the gazebo_models directory. For this tutorial, we will assume that this directory is called mymodel, but you should give the directory an informative name about the model.

That directory must include the file model.config and at least one .sdf file. It may include other files as well (meshes, textures, templates, etc.)如下图所示

Also make sure you add the model directory to the CMakeLists.txt file.

The model.config file provides information necessary to pick the proper SDF file, information on authorship of the model, and a textual description of the model.

A sample model.config looks like this:

  1. <?xml version="1.0"?>
  2. <model>
  3. <name>Wedge juggler</name>
  4. <version>1.0</version>
  5. <sdf version="1.5">model.sdf</sdf>
  6. <author>
  7. <name>Evan Drumwright</name>
  8. <email>drum@gwu.edu</email>
  9. </author>
  10. <description>
  11. A ball-in-wedge juggler.
  12. </description>
  13. </model>

如下图所示。基本就是模型的名称、作者信息,包括的.sdf文件

若有其他.sdf文件,则如下图所示

This model.config file indicates that the simulator's definition of the model (i.e., visual, inertial, kinematic, and geometric properties, among others), is located in model.sdf, and follows SDF standard 1.5. It is possible to define multiple versions of your model, which may be useful if you intend for your model to be used with different versions of Gazebo. For example, we now change the contents of the file above, to support three different versions of SDF:

  1. <?xml version="1.0"?>
  2. <model>
  3. <name>Wedge juggler</name>
  4. <version>1.0</version>
  5. <sdf version="1.5">model.sdf</sdf>
  6. <sdf version="1.4">model-1.4.sdf</sdf>
  7. <author>
  8. <name>Evan Drumwright</name>
  9. <email>drum@gwu.edu</email>
  10. </author>
  11. <description>
  12. A ball-in-wedge juggler.
  13. </description>
  14. </model>

 

URDF

URDF的全称是Universal Robotic Description Format ,通用机器人描述格式。是一个XML文件,用于描述ROS中机器人的各个单元

This tutorial explains the necessary steps to successfully use your URDF-based robot in Gazebo, saving you from having to create a separate SDF file from scratch and duplicating description formats. Under the hood, Gazebo will then convert the URDF to SDF automatically.

URDF只能单独指定单个机器人的运动学和动力学特性。URDF无法指定机器人在一个世界中的姿势。它也不是一种通用的描述格式,因为它不能指定关节回路(并联机构),而且它缺乏摩擦力和其他特性。此外,它不能指定非机器人的东西,如灯光、高度图等。而且可扩展性也比较差。

因此,在gazebo中采用SDF(Simulation Description Format)格式来解决URDF的缺点。SDF是从世界级到机器人级的所有内容的完整描述。它是可伸缩的,并且可以方便地添加和修改元素。SDF格式本身是使用XML描述的,这有助于使用简单的升级工具将旧版本迁移到新版本。它也是自我描述的。

There are several steps to get a URDF robot properly working in Gazebo. 

Required

  • An <inertia> element within each <link> element must be properly specified and configured.

Optional

  • Add a <gazebo> element for every <link>
    • Convert visual colors to Gazebo format
    • Convert stl files to dae files for better textures
    • Add sensor plugins
  • Add a <gazebo> element for every <joint>
    • Set proper damping dynamics
    • Add actuator control plugins
  • Add a <gazebo> element for the <robot> element
  • Add a <link name="world"/> link if the robot should be rigidly attached to the world/base_link

The <gazebo> element is an extension (延伸) to the URDF used for specifying additional properties (指定其他属性) needed for simulation purposes in Gazebo. It allows you to specify the properties found in the SDF format that are not included in the URDF format. None of the elements within a <gazebo> element are required because default values will be automatically included. There are three different types of <gazebo> elements - one for the <robot> tag, one for <link> tags, and one for <joint> tags. 

这个连接详细的讲述了构建URDF(https://wiki.ros.org/urdf/Tutorials)

这里采用RRBot(''Revolute-Revolute Manipulator Robot'', is a simple 3-linkage, 2-joint arm)

首先,配置相关软件包(https://github.com/ros-simulation/gazebo_ros_demos

  1. cd ~/catkin_ws/src/
  2. git clone https://github.com/ros-simulation/gazebo_ros_demos.git
  3. cd ..
  4. catkin_make

然后通过运行下面命令在rviz中打开

roslaunch rrbot_description rrbot_rviz.launch

 

控制滑动条可以控制机械臂

It is important that while converting your robot to work in Gazebo, you don't break Rviz or other ROS-application functionality, so its nice to occasionally test your robot in Rviz to make sure everything still works.

use Rviz to monitor the state of your simulated robot by publishing /joint_states directly from Gazebo. In the previous example, the RRBot in Rviz is getting its /joint_states from a fake joint_states_publisher node (the window with the slider bars).

关于rviz监控gazebo中的机器人,可以参考博文《 学习笔记之——使用rviz来监控gazebo中的机器人

接下来看看RRBot的URDF文件

通过gazebo打开RRBot机器人

roslaunch rrbot_gazebo rrbot_world.launch

如下图所示

In the launched Gazebo window you should see the robot standing straight up. Despite there being no intentional disturbances in the physics simulator by default, numerical errors should start to build up and cause the double inverted pendulum to fall after a few seconds.

整个机器人文档如下所示(在rrbot_description/ rrbot.xacro)在上面加了些注释,由于本人不会设计机器人,所以对于其大概的结构,了解即可

  1. <?xml version="1.0"?>
  2. <!-- Revolute-Revolute Manipulator -->
  3. <robot name="rrbot" xmlns:xacro="http://www.ros.org/wiki/xacro">
  4. <!-- Constants for robot dimensions -->
  5. <xacro:property name="PI" value="3.1415926535897931"/>
  6. <xacro:property name="mass" value="1" /> <!-- arbitrary value for mass -->
  7. <xacro:property name="width" value="0.1" /> <!-- Square dimensions (widthxwidth) of beams -->
  8. <xacro:property name="height1" value="2" /> <!-- Link 1 -->
  9. <xacro:property name="height2" value="1" /> <!-- Link 2 -->
  10. <xacro:property name="height3" value="1" /> <!-- Link 3 -->
  11. <xacro:property name="camera_link" value="0.05" /> <!-- Size of square 'camera' box -->
  12. <xacro:property name="axel_offset" value="0.05" /> <!-- Space btw top of beam and the each joint -->
  13. <!-- Import all Gazebo-customization elements, including Gazebo colors -->
  14. <xacro:include filename="$(find rrbot_description)/urdf/rrbot.gazebo" />
  15. <!-- Import Rviz colors -->
  16. <xacro:include filename="$(find rrbot_description)/urdf/materials.xacro" />
  17. ######################################################################
  18. 如果希望将URDF模型永久附着到世界框架(地平面),则必须创建“世界”链接和将其固定到模型基础的关节。RRBot通过以下操作完成此任务:
  19. <!-- Used for fixing robot to Gazebo 'base_link' -->
  20. <link name="world"/>
  21. <joint name="fixed" type="fixed">
  22. <parent link="world"/>
  23. <child link="link1"/>
  24. </joint>
  25. 但是,如果是一个移动基地或其他移动机器人,您不需要这个链接或关节。
  26. ######################################################################
  27. <!-- Base Link -->
  28. <link name="link1">
  29. <collision>#########碰撞
  30. <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>
  31. <geometry>
  32. <box size="${width} ${width} ${height1}"/>
  33. </geometry>
  34. </collision>
  35. <visual>##########可视化
  36. <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>
  37. <geometry>
  38. <box size="${width} ${width} ${height1}"/>
  39. </geometry>
  40. <material name="orange"/>####颜色
  41. </visual>
  42. <inertial>############惯性
  43. <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>##代表质心的位置
  44. <mass value="${mass}"/>
  45. <inertia
  46. ixx="${mass / 12.0 * (width*width + height1*height1)}" ixy="0.0" ixz="0.0"
  47. iyy="${mass / 12.0 * (height1*height1 + width*width)}" iyz="0.0"
  48. izz="${mass / 12.0 * (width*width + width*width)}"/>
  49. </inertial>
  50. </link>
  51. #########################################
  52. <joint name="joint1" type="continuous">
  53. <parent link="link1"/>###连接的父link和子link
  54. <child link="link2"/>
  55. <origin xyz="0 ${width} ${height1 - axel_offset}" rpy="0 0 0"/>
  56. <axis xyz="0 1 0"/>
  57. <dynamics damping="0.7"/>
  58. </joint>
  59. #########################################
  60. <!-- Middle Link -->
  61. <link name="link2">
  62. <collision>
  63. <origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/>
  64. <geometry>
  65. <box size="${width} ${width} ${height2}"/>
  66. </geometry>
  67. </collision>
  68. <visual>
  69. <origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/>
  70. <geometry>
  71. <box size="${width} ${width} ${height2}"/>
  72. </geometry>
  73. <material name="black"/>
  74. </visual>
  75. <inertial>
  76. <origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/>
  77. <mass value="${mass}"/>
  78. <inertia
  79. ixx="${mass / 12.0 * (width*width + height2*height2)}" ixy="0.0" ixz="0.0"
  80. iyy="${mass / 12.0 * (height2*height2 + width*width)}" iyz="0.0"
  81. izz="${mass / 12.0 * (width*width + width*width)}"/>
  82. </inertial>
  83. </link>
  84. #########################################
  85. <joint name="joint2" type="continuous">
  86. <parent link="link2"/>
  87. <child link="link3"/>
  88. <origin xyz="0 ${width} ${height2 - axel_offset*2}" rpy="0 0 0"/>
  89. <axis xyz="0 1 0"/>
  90. <dynamics damping="0.7"/>
  91. </joint>
  92. #########################################
  93. <!-- Top Link -->
  94. <link name="link3">
  95. <collision>
  96. <origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/>
  97. <geometry>
  98. <box size="${width} ${width} ${height3}"/>
  99. </geometry>
  100. </collision>
  101. <visual>
  102. <origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/>
  103. <geometry>
  104. <box size="${width} ${width} ${height3}"/>
  105. </geometry>
  106. <material name="orange"/>
  107. </visual>
  108. <inertial>
  109. <origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/>
  110. <mass value="${mass}"/>
  111. <inertia
  112. ixx="${mass / 12.0 * (width*width + height3*height3)}" ixy="0.0" ixz="0.0"
  113. iyy="${mass / 12.0 * (height3*height3 + width*width)}" iyz="0.0"
  114. izz="${mass / 12.0 * (width*width + width*width)}"/>
  115. </inertial>
  116. </link>
  117. #########################################
  118. <joint name="hokuyo_joint" type="fixed">
  119. <axis xyz="0 1 0" />
  120. <origin xyz="0 0 ${height3 - axel_offset/2}" rpy="0 0 0"/>
  121. <parent link="link3"/>
  122. <child link="hokuyo_link"/>
  123. </joint>
  124. #########################################
  125. <!-- Hokuyo Laser -->
  126. <link name="hokuyo_link">
  127. <collision>
  128. <origin xyz="0 0 0" rpy="0 0 0"/>
  129. <geometry>
  130. <box size="0.1 0.1 0.1"/>
  131. </geometry>
  132. </collision>
  133. <visual>
  134. <origin xyz="0 0 0" rpy="0 0 0"/>
  135. <geometry>
  136. <mesh filename="package://rrbot_description/meshes/hokuyo.dae"/>
  137. </geometry>
  138. </visual>
  139. <inertial>
  140. <mass value="1e-5" />
  141. <origin xyz="0 0 0" rpy="0 0 0"/>
  142. <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
  143. </inertial>
  144. </link>
  145. #########################################
  146. <joint name="camera_joint" type="fixed">
  147. <axis xyz="0 1 0" />
  148. <origin xyz="${camera_link} 0 ${height3 - axel_offset*2}" rpy="0 0 0"/>
  149. <parent link="link3"/>
  150. <child link="camera_link"/>
  151. </joint>
  152. <!-- Camera -->
  153. <link name="camera_link">
  154. <collision>
  155. <origin xyz="0 0 0" rpy="0 0 0"/>
  156. <geometry>
  157. <box size="${camera_link} ${camera_link} ${camera_link}"/>
  158. </geometry>
  159. </collision>
  160. <visual>
  161. <origin xyz="0 0 0" rpy="0 0 0"/>
  162. <geometry>
  163. <box size="${camera_link} ${camera_link} ${camera_link}"/>
  164. </geometry>
  165. <material name="red"/>
  166. </visual>
  167. <inertial>
  168. <mass value="1e-5" />
  169. <origin xyz="0 0 0" rpy="0 0 0"/>
  170. <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
  171. </inertial>
  172. </link>
  173. <!-- generate an optical frame http://www.ros.org/reps/rep-0103.html#suffix-frames
  174. so that ros and opencv can operate on the camera frame correctly -->
  175. <joint name="camera_optical_joint" type="fixed">
  176. <!-- these values have to be these values otherwise the gazebo camera image
  177. won't be aligned properly with the frame it is supposedly originating from -->
  178. <origin xyz="0 0 0" rpy="${-pi/2} 0 ${-pi/2}"/>
  179. <parent link="camera_link"/>
  180. <child link="camera_link_optical"/>
  181. </joint>
  182. <link name="camera_link_optical">
  183. </link>
  184. <transmission name="tran1">
  185. <type>transmission_interface/SimpleTransmission</type>
  186. <joint name="joint1">
  187. <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
  188. </joint>
  189. <actuator name="motor1">
  190. <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
  191. <mechanicalReduction>1</mechanicalReduction>
  192. </actuator>
  193. </transmission>
  194. <transmission name="tran2">
  195. <type>transmission_interface/SimpleTransmission</type>
  196. <joint name="joint2">
  197. <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
  198. </joint>
  199. <actuator name="motor2">
  200. <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
  201. <mechanicalReduction>1</mechanicalReduction>
  202. </actuator>
  203. </transmission>
  204. </robot>

 

 

 

参考资料

http://gazebosim.org/tutorials?cat=connect_ros

http://gazebosim.org/tutorials?tut=model_contrib&cat=build_robot

http://gazebosim.org/tutorials?tut=ros_urdf&cat=connect_ros

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/517499
推荐阅读
相关标签
  

闽ICP备14008679号