在前面小车底盘基础之上,添加摄像头和雷达传感器。
1.步骤
编写摄像头和雷达的 xacro 文件
→然后再编写一个组合文件,组合底盘、摄像头与雷达
→通过 launch 文件启动 Rviz 并显示模型
2.Xacro
摄像头Xacro:
<robot name="mycar" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- 摄像头部件 -->
<!-- 1. 参数 -->
<!--
参数:
连杆属性:厚度、宽度、高度
关节属性:x y z
-->
<xacro:property name="camera_length" value="0.02" /> <!-- 摄像头长度(x) -->
<xacro:property name="camera_width" value="0.05" /> <!-- 摄像头宽度(y) -->
<xacro:property name="camera_height" value="0.05" /> <!-- 摄像头高度(z) -->
<xacro:property name="joint_camera_x" value="0.08" /> <!-- 摄像头安装的x坐标 -->
<xacro:property name="joint_camera_y" value="0.0" /> <!-- 摄像头安装的y坐标 -->
<xacro:property name="joint_camera_z" value="${base_length / 2 + camera_height / 2}" /> <!-- 摄像头安装的z坐标:底盘高度 / 2 + 摄像头高度 / 2 -->
<!-- 摄像头关节以及link -->
<link name="camera">
<visual>
<geometry>
<box size="${camera_length} ${camera_width} ${camera_height}" />
</geometry>
<material name="black" >
<color rgba = "0 0 0 0.8" />
</material>
</visual>
</link>
<joint name="camera2base" type="fixed">
<parent link="base_link" />
<child link="camera" />
<origin xyz="${joint_camera_x} ${joint_camera_y} ${joint_camera_z}" rpy="0 0 0" />
</joint>
</robot>
雷达Xacro
<robot name="mycar" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- 雷达部件 -->
<!--参数-->
<!--
1. 支架
支架尺寸:半径 高度
关节偏移量
1.雷达
雷达尺寸:半径 高度
关节偏移量
-->
<xacro:property name="support_length" value="0.15" /> <!-- 支架长度 -->
<xacro:property name="support_radius" value="0.01" /> <!-- 支架半径 -->
<xacro:property name="joint_support_x" value="0.0" /> <!-- 支架安装的x坐标 -->
<xacro:property name="joint_support_y" value="0.0" /> <!-- 支架安装的y坐标 -->
<!-- z=车体高度/2 + 支架高度/2 -->
<xacro:property name="joint_support_z" value="${base_length / 2 + support_length / 2}" /> <!-- 支架安装的z坐标:底盘高度 / 2 + 支架高度 / 2 -->
<!-- 雷达属性 -->
<xacro:property name="laser_length" value="0.05" /> <!-- 雷达长度 -->
<xacro:property name="laser_radius" value="0.03" /> <!-- 雷达半径 -->
<xacro:property name="joint_laser_x" value="0.0" /> <!-- 雷达安装的x坐标 -->
<xacro:property name="joint_laser_y" value="0.0" /> <!-- 雷达安装的y坐标 -->
<!-- z= 支架高度/2 雷达高度/2-->
<xacro:property name="joint_laser_z" value="${support_length / 2 + laser_length / 2}" /> <!-- 雷达安装的z坐标:支架高度 / 2 + 雷达高度 / 2 -->
<!-- 支架 -->
<link name="support">
<visual>
<geometry>
<cylinder radius="${support_radius}" length="${support_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="yellow">
<color rgba="0.8 0.5 0.0 0.5" />
</material>
</visual>
</link>
<joint name="support2base" type="fixed">
<parent link="base_link" />
<child link="support" />
<origin xyz="${joint_support_x} ${joint_support_y} ${joint_support_z}" />
</joint>
<!-- 雷达关节以及link -->
<link name="laser">
<visual>
<geometry>
<cylinder radius="${laser_radius}" length="${laser_length}" />
</geometry>
<material name="black" >
<color rgba="0 0 0 0.5" />
</material>
</visual>
</link>
<joint name="laser2support" type="fixed">
<parent link="support" />
<child link="laser" />
<origin xyz="${joint_laser_x} ${joint_laser_y} ${joint_laser_z}" />
</joint>
</robot>
3. 组合底盘摄像头与雷达的 xacro 文件
<robot name="mycar" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- 包含底盘 -->
<xacro:include filename="demo05_car_base.urdf.xacro" />
<xacro:include filename="demo06_car_camera.urdf.xacro" />
<xacro:include filename="demo07_car_laser.urdf.xacro" />
</robot>
4. launch 文件
<launch>
<!-- 1.将 urdf 文件内容设置进参数服务器 -->
<param name="robot_description" command="$(find xacro)/xacro $(find urdf01_rviz)/urdf/xacro/car.urdf.xacro" />
<!-- 2.启动 rivz -->
<node pkg="rviz" type="rviz" name="rviz" args="-d $(find urdf01_rviz)/config/show_mycar.rviz" />
<!-- 3.启动机器人状态和关节状态发布节点 -->
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" />
<node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher" />
<!-- 4.启动图形化的控制关节运动节点 -->
<node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui" />
</launch>