前面已经使用urdf文件搭建小车模型,并在rviz下进行显示,今天用更容易维护的xacro文件来搭建
1. 新建xacro模型文件
- 在之前已经创建完毕的smartcar功能包下建立xacro文件夹存放模型文件
cd smartcat
mkdir xacro
cd xacro
touch car01.xacro
- 在car01.xacro文件填入以下内容
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="test_robot">
<xacro:property name="body_size" value=".2 .3 .1" />
<xacro:property name="body_pos" value="0 0 0.05" />
<xacro:property name="wheel_radius" value="0.05" />
<xacro:property name="wheel_length" value="0.05" />
<xacro:property name="wheel1_pos" value="0.1 0.1 0" />
<xacro:property name="wheel2_pos" value="-0.1 0.1 0" />
<xacro:property name="wheel3_pos" value="0.1 -0.1 0" />
<xacro:property name="wheel4_pos" value="-0.1 -0.1 0" />
<xacro:macro name="wheel" params="wheelname position">
<link name="${wheelname}">
<visual>
<geometry>
<cylinder length="${wheel_length}" radius="${wheel_radius}"/>
</geometry>
<origin rpy="0 1.5 0" xyz="${position}"/>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
<joint name="joint_base_${wheelname}" type="fixed">
<parent link="base_link"/>
<child link="${wheelname}"/>
</joint>
</xacro:macro>
<xacro:wheel wheelname="wheel1" position="${wheel1_pos}"/>
<xacro:wheel wheelname="wheel2" position="${wheel2_pos}"/>
<xacro:wheel wheelname="wheel3" position="${wheel3_pos}"/>
<xacro:wheel wheelname="wheel4" position="${wheel4_pos}"/>
<link name="base_link">
<visual>
<geometry>
<box size="${body_size}"/>
</geometry>
<origin rpy="0 0 0" xyz="${body_pos}"/>
<material name="white">
<color rgba="1 1 1 1"/>
</material>
</visual>
</link>
</robot>
2. 创建对应launch文件
cd smartcar/launch
touch car01_xacro.launch
- 在car01.xacro文件填入以下内容 (rviz配置文件)
<!-- -->
<launch>
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find little_car)/xacro/car01.xacro" />
<!-- 运行robot_state_publisher节点,发布tf坐标系变换 -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<!-- 运行rviz可视化界面 -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find little_car)/rviz/car01.rviz" respawn="false" output="screen"/>
</launch>
3. 终端启动
roslaunch smartcar car01_xacro.launch
完成