本人所用的是ubuntu20.04,Noetic
在《ROS机器人开发实践》的P128中
1.将xacro文件转化为URDF文件时:
运行
$ rosrun xacro xacro.py mrobot.urdf.xacro > mrobot.urdf
产生的mrobot.urdf内容为:
[rosrun] Couldn't find executable named xacro.py below /opt/ros/noetic/share/xacro
解决方法:
rosrun xacro xacro mrobot.urdf.xacro > mrobot.urdf
2.运行launch文件
roslaunch mrobot_description display_mrobot.launch
出现:
[ERROR] [1692858420.387138318]: No link elements found in urdf file...
原因:Noetic版本的ROS在xacro宏定义语法中与之前版本不同调用宏的时候需要在开头添加xacro:
,修改mrobot.urdf.xacro
文件中调mrobot_body.urdf.xacro的语句::
将
<!-- MRobot机器人平台 -->
<mrobot_body />
改为:
<!-- MRobot机器人平台 -->
<xacro:mrobot_body />
3.在Rviz中显示xacro模型没有报错,但是缺失部件(小车的八根支柱没有显示)
原因:同上,版本不同导致宏调用语法的不同。需要调用宏时在开头添加xacro:
,具体是在mrobot_body.urdf.xacro
文件中调用支柱宏定义处,如图
<mrobot_standoff_2in parent="base_link" number="1" x_loc="-${standoff_x/2 + 0.03}" y_loc="-${standoff_y - 0.03}" z_loc="${plate_height/2}"/>
改为:
<xacro:mrobot_standoff_2in parent="base_link" number="1" x_loc="-${standoff_x/2 + 0.03}" y_loc="-${standoff_y - 0.03}" z_loc="${plate_height/2}"/>
一共八处需要更改:
<xacro:mrobot_standoff_2in parent="base_link" number="1" x_loc="-${standoff_x/2 + 0.03}" y_loc="-${standoff_y - 0.03}" z_loc="${plate_height/2}"/>
<xacro:mrobot_standoff_2in parent="base_link" number="2" x_loc="-${standoff_x/2 + 0.03}" y_loc="${standoff_y - 0.03}" z_loc="${plate_height/2}"/>
<xacro:mrobot_standoff_2in parent="base_link" number="3" x_loc="${standoff_x/2}" y_loc="-${standoff_y}" z_loc="${plate_height/2}"/>
<xacro:mrobot_standoff_2in parent="base_link" number="4" x_loc="${standoff_x/2}" y_loc="${standoff_y}" z_loc="${plate_height/2}"/>
<xacro:mrobot_standoff_2in parent="standoff_2in_1_link" number="5" x_loc="0" y_loc="0" z_loc="${plate_height}"/>
<xacro:mrobot_standoff_2in parent="standoff_2in_2_link" number="6" x_loc="0" y_loc="0" z_loc="${plate_height}"/>
<xacro:mrobot_standoff_2in parent="standoff_2in_3_link" number="7" x_loc="0" y_loc="0" z_loc="${plate_height}"/>
<xacro:mrobot_standoff_2in parent="standoff_2in_4_link" number="8" x_loc="0" y_loc="0" z_loc="${plate_height}"/>