1.引言
上一章中我们成功导出了URDF文件,这章中我们将学习如何在Rviz和Gazebo下显示我们创建的三维模型。
2.预备
首先,我们需要对导出的URDF文件进行下修改。
(1)package.xml文件中将“me2email.com”改为“[email protected]”
<package>
<name>smartcar</name>
<version>1.0.0</version>
<description>
<p>URDF Description package for smartcar</p>
<p>This package contains configuration data, 3D models and launch files
for smartcar robot</p>
</description>
<author>me</author>
<maintainer email="[email protected]" />
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roslaunch</build_depend>
<run_depend>robot_state_publisher</run_depend>
<run_depend>rviz</run_depend>
<run_depend>joint_state_publisher</run_depend>
<run_depend>gazebo</run_depend>
<export>
<architecture_independent />
</export>
</package>
(2)launch下display.launch文件修改
<launch>
<arg
name="model" />
<arg
name="gui"
default="False" />
<param
name="robot_description"
textfile="$(find smartcar)/urdf/smartcar.urdf" />
<param
name="use_gui"
value="$(arg gui)" />
<node
name="joint_state_publisher"
pkg="joint_state_publisher"
type="joint_state_publisher" />
<node
name="robot_state_publisher"
pkg="robot_state_publisher"
type="state_publisher" />
<node
name="rviz"
pkg="rviz"
type="rviz"
args="-d $(find smartcar)/urdf.rviz" />
</launch>
(3)launch下gazebo.launch文件修改
<launch>
<include
file="$(find gazebo_ros)/launch/empty_world.launch" />
<node
name="spawn_model"
pkg="gazebo_ros"
type="spawn_model"
args="-file $(find smartcar)/urdf/smartcar.urdf -urdf -model smartcar"
output="screen" />
<node
name="fake_joint_calibration"
pkg="rostopic"
type="rostopic"
args="pub /calibrated std_msgs/Bool true" />
</launch>
3.Rviz中显示
(1)将导出的整个文件夹移动到工作空间下。打开终端输入指令:
roslaunch smartcar display.launch
(2)选择Fixed Frame并添加机器人模型
(3)显示成功
3.Gazebo中显示
(1)打开终端输入指令:
roslaunch smartcar gazebo.launch
(2)显示结果如下:
(3)接下来我们可以在urdf文件夹的smartcar.urdf中添加代码,赋予模型Gazebo中的显示颜色。也可以根据自己需求修改不同的颜色。
<gazebo reference="base_link">
<material>Gazebo/Yellow </material>
</gazebo>
<gazebo reference="sensor_link">
<material>Gazebo/Blue </material>
</gazebo>
<gazebo reference="wheel1_link">
<material>Gazebo/Black </material>
</gazebo>
<gazebo reference="wheel2_link">
<material>Gazebo/Black </material>
</gazebo>
<gazebo reference="wheel3_link">
<material>Gazebo/Black </material>
</gazebo>
<gazebo reference="wheel4_link">
<material>Gazebo/Black </material>
</gazebo>
最后结果如下: