![Mastering ROS for Robotics Programming(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/200/36700200/b_36700200.jpg)
上QQ阅读APP看书,第一时间看更新
Visualizing the 3D robot model in RViz
After designing the URDF, we can view it on RViz. We can create a view_demo.launch launch file and put the following code into the launch folder. Navigate to the mastering_ros_robot_description_pkg/launch directory for the code:
<launch> <arg name="model" /> <param name="robot_description" textfile="$(find mastering_ros_robot_description_pkg)/urdf/pan_tilt.urdf" /> <param name="use_gui" value="true"/> <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 mastering_ros_robot_description_pkg)/urdf.rviz" required="true" /> </launch>
We can launch the model using the following command:
$ roslaunch mastering_ros_robot_description_pkg view_demo.launch
If everything works fine, we will get a pan-and-tilt mechanism in RViz, as shown here:
![](https://epubservercos.yuewen.com/1D30EC/19470397401586306/epubprivate/OEBPS/Images/7b1c7c72-ec5b-4cb4-8b26-5559af11997d.png?sign=1738891277-2M3SaXZleC9QTHm8HIw9bvziZe2Qn86H-0-7056ea7ed80b81a5ad61290c8fb47402)
Figure 6: Joint level of pan-and-tilt mechanism