继续完整软件包解读
这次看另一个模型文件
mrobot_with_camera.urdf.xacro
这个文件是一个总的模型文件。文件内部又调用了其他的模型文件。我们来具体看看它的结构。
代码不长,先贴在这里
<?xml version="1.0"?>
<robot name="mrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="$(find mrobot_gazebo)/urdf/mrobot_body.urdf.xacro" />
<xacro:include filename="$(find mrobot_gazebo)/urdf/camera.xacro" />
<xacro:property name="camera_offset_x" value="0.1" />
<xacro:property name="camera_offset_y" value="0" />
<xacro:property name="camera_offset_z" value="0.02" />
<!-- Body of mrobot, with plates, standoffs and Create (including sim sensors) -->
<mrobot_body/>
<!-- Attach the Kinect -->
<joint name="camera_joint" type="fixed">
<origin xyz="${camera_offset_x} ${camera_offset_y} ${camera_offset_z}" rpy="0 0 0" />
<parent link="plate_2_link"/>
<child link="camera_link"/>
</joint>
<xacro:usb_camera prefix="camera"/>
</robot>
首先需要声明该文件使用XML描述<?xml version="1.0"?>
然后定义机器人的模型名称为mrobot
xacro声明也要记得xmlns:xacro=“http://www.ros.org/wiki/xacro”>
这里可以看出它所包含的子xacro文件
<xacro:include filename="$(find mrobot_gazebo)/urdf/mrobot_body.urdf.xacro" />
<xacro:include filename="$(find mrobot_gazebo)/urdf/camera.xacro" />
包含了讲解(一)中的机器人body文件和一个摄像机模型文件camera.xacro
所以我们首先来看相机模型文件
camera.xacro
首先宏定义usb_camera模块,params为prefix,默认值为camera
<xacro:macro name="usb_camera" params="prefix:=camera">
camera_link
然后是定义相机的link,把几何形状和位姿和碰撞检测拿到,老生常谈
形状为box,这里有个疑问
<material name="black"/>
这个为什么不是Black?在body文件中的宏定义材料属性是Black呀,这个小写的从哪里来的?存疑
<link name="${prefix}_link">
<inertial>
<mass value="0.1" />
<origin xyz="0 0 0" />
<inertia ixx="0.01" ixy="0.0" ixz="0.0"
iyy="0.01" iyz="0.0"
izz="0.01" />
</inertial>
<visual>
<origin xyz=" 0 0 0 " rpy="0 0 0" />
<geometry>
<box size="0.01 0.04 0.04" />
</geometry>
<material name="black"/>
</visual>
<collision>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
<geometry>
<box size="0.01 0.04 0.04" />
</geometry>
</collision>
</link>
两个gazebo标签
第一个为设置相机在gazebo中的material,设置了颜色参数
<gazebo reference="${prefix}_link">
<material>Gazebo/Black</material>
</gazebo>
第二个为设置摄像头插件的gazebo标签,也就是是这个简单的小box摇身一变变成一个传感器sensor。
在这里使用<sensor>
标签包含传感器的各种属性设置。
包括传感器的命名name,图像的更新频率为30Hz,水平视场1.39…,图像分辨率1280*720,编码格式为RGB(一个点的一个分量为8字节,所以是R8G8B8)。图像范围near-far = 0.02-300m,高斯噪声。
最后使用<plugin>
标签加载摄像头插件 libgazebo_ros_camera.so 。
包括命名空间/camera,图像话题消息的名称image_raw ,相机信息的话题名称camera_info,camera_link为framename可能是将camera_link的坐标系看做参考系生成图像。hackBaseline是什么暂时存疑。 最后是一系列的旋转和平移,类似于相机的外参。
<gazebo reference="${prefix}_link">
<sensor type="camera" name="camera_node">
<update_rate>30.0</update_rate>
<camera name="head">
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>1280</width>
<height>720</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
</camera>
<plugin name="gazebo_camera" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>/camera</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>camera_link</frameName>
<hackBaseline>0.07</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
</plugin>
</sensor>
</gazebo>```
所以camera.xacro就是单纯做了一个相机的link。
然后回到主文件
mrobot_with_camera.urdf.xacro
<?xml version="1.0"?>
<robot name="mrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="$(find mrobot_gazebo)/urdf/mrobot_body.urdf.xacro" />
<xacro:include filename="$(find mrobot_gazebo)/urdf/camera.xacro" />
<xacro:property name="camera_offset_x" value="0.1" />
<xacro:property name="camera_offset_y" value="0" />
<xacro:property name="camera_offset_z" value="0.02" />
<!-- Body of mrobot, with plates, standoffs and Create (including sim sensors) -->
<mrobot_body/>
<!-- Attach the Kinect -->
<joint name="camera_joint" type="fixed">
<origin xyz="${camera_offset_x} ${camera_offset_y} ${camera_offset_z}" rpy="0 0 0" />
<parent link="plate_2_link"/>
<child link="camera_link"/>
</joint>
<xacro:usb_camera prefix="camera"/>
</robot>
首先是include两个文件,引用这两个命名空间。
然后宏定义三个相机的位置偏移系数
接下来定义一个joint,连接最上方的二号平台plate_2_link和相机camera_link。
捋一下,这个joint的位置由父级link也就是平台plate_2_link的坐标系决定。x偏移0.1,也就是往前进方向0.1m,y方向为0指的是相机在中心线上,z方向为0.02是比平台稍微高一点。
这个link相当于横跨了两个文件,所以要include两个文件。
至此,模型文件解读完毕