ROS机器人高效编程(原书第3版)封面
$ roslaunch chapter5_tutorials display_xacro.launch model:="`rospack find chapter5_tutorials`/urdf/robot1_base_04.xacro"
下图为GitHub上的本书的源代码, chapter5_tutorials并没有 display_xacro.launch (两年没更新,也是醉了,本书代码问题不少)
第五章 导航功能包集入门中缺少display_xacro.launch解决办法:
在相关目录下创建文件/chapter5_tutorials/launch/display_xacro.launch:(注意此处注释了rviz启动)
<launch>
<arg name="model" />
<arg name="gui" default="False" />
<param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" />
<param name="use_gui" value="$(arg gui)"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="odometry" pkg="chapter5_tutorials" type="odometry" />
<!-- <node name="rviz" pkg="rviz" type="rviz" args="-d $(find chapter5_tutorials)/launch/display.rviz" /> -->
</launch>
执行下面命令:
$ roslaunch chapter5_tutorials display_xacro.launch model:="`rospack find chapter5_tutorials`/urdf/robot1_base_04.xacro"
$ rviz
运行结果:
在rviz中左侧Add TF 和 RobotModel,然后将rviz文件另存到/chapter5_tutorials/launch/display.rviz
在相关目录下创建文件/chapter5_tutorials/launch/display_xacro.launch:(注意此处取消注释了rviz启动)
<launch>
<arg name="model" />
<arg name="gui" default="False" />
<param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" />
<param name="use_gui" value="$(arg gui)"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="odometry" pkg="chapter5_tutorials" type="odometry" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find chapter5_tutorials)/launch/display.rviz" />
</launch>
直接执行下面命令:
$ roslaunch chapter5_tutorials display_xacro.launch model:="`rospack find chapter5_tutorials`/urdf/robot1_base_04.xacro"
实验效果:(rviz自动启动并加装设置)
大功告成!!!!!
注:
也可以直接启动节点,只发布里程计(Odometry)消息并在rviz中显示
$ rosrun chapter5_tutorials odometry
$ rviz
实验效果: