6.4.7机器人建模时在rviz中相机模块有质量和TF但是模块不可见
-
camera_link的TF坐标和质量都能正常表示但是外观和惯性无法在rviz中观察到,鱼哥帮忙看下是什么问题
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="$(find fishbot_description)/urdf/fishbot/common_intertia.xacro"/>
<xacro:macro name="camera_xacro" params="xyz">
<link name="camera_link">
<!-- 部件外观描述 -->
<visual>
<!-- 沿着自己几何中心的偏移旋转 -->
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<!-- 几何形状 -->
<geometry>
<!-- 正方体 -->
<box size="0.02 0.10 0.02"/>
</geometry>
<!-- 材质颜色 -->
<material name="green">
<color rgba="0.0 1.0 0.0 0.8"/>
</material>
</visual>
<collision>
<!-- 沿着自己几何中心的偏移旋转 -->
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<!-- 几何形状 -->
<geometry>
<!-- 正方体 -->
<box size="0.02 0.10 0.02"/>
</geometry>
<!-- 材质颜色 -->
<material name="green">
<color rgba="0.0 1.0 0.0 0.8"/>
</material>
</collision>
<xacro:box_interia m="0.1" w="0.02" h="0.10" d="0.02" />
</link>
<link name="camera_optical_link">
</link>
<!--机器人关节-->
<joint name="camera_joint" type="fixed">
<origin xyz="${xyz}" rpy="0.0 0.0 0.0"/>
<parent link="base_link"/>
<child link="camera_link"/>
</joint>
<joint name="camera_optical_link" type="fixed">
<origin xyz="0 0 0" rpy="${-pi/2} 0.0 ${-pi/2}"/>
<parent link="camera_link"/>
<child link="camera_optical_link"/>
</joint>
</xacro:macro>
</robot>日志输出:
chen@chen-virtual-machine:~/Program/Chapt6/chapt6_ws$ ros2 launch fishbot_description dispalay_robot.launch.py model:=/home/chen/Program/Chapt6/chapt6_ws/install/fishbot_description/share/fishbot_
description/urdf/fishbot/fishbot.urdf.xacro
[INFO] [launch]: All log files can be found below /home/chen/.ros/log/2025-01-08-17-21-35-353117-chen-virtual-machine-2740
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [2742]
[INFO] [joint_state_publisher-2]: process started with pid [2744]
[INFO] [rviz2-3]: process started with pid [2746]
[rviz2-3] qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
[robot_state_publisher-1] Error: Inertial: inertia element izz is not a valid double
[robot_state_publisher-1] at line 334 in ./urdf_parser/src/link.cpp
[robot_state_publisher-1] Error: Could not parse inertial element for Link [camera_link]
[robot_state_publisher-1] at line 435 in ./urdf_parser/src/link.cpp
[robot_state_publisher-1] Error: Inertial: inertia element izz is not a valid double
[robot_state_publisher-1] at line 334 in ./urdf_parser/src/link.cpp
[robot_state_publisher-1] Error: Could not parse inertial element for Link [imu_link]
[robot_state_publisher-1] at line 435 in ./urdf_parser/src/link.cpp
[robot_state_publisher-1] [INFO] [1736328095.667699306] [robot_state_publisher]: got segment back_caster_link
[robot_state_publisher-1] [INFO] [1736328095.667924554] [robot_state_publisher]: got segment base_footprint
[robot_state_publisher-1] [INFO] [1736328095.667944890] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1736328095.667953666] [robot_state_publisher]: got segment camera_link
[robot_state_publisher-1] [INFO] [1736328095.667959129] [robot_state_publisher]: got segment camera_optical_link
[robot_state_publisher-1] [INFO] [1736328095.667964040] [robot_state_publisher]: got segment front_caster_link
[robot_state_publisher-1] [INFO] [1736328095.667968629] [robot_state_publisher]: got segment imu_link
[robot_state_publisher-1] [INFO] [1736328095.667973430] [robot_state_publisher]: got segment laser_cylinder_link
[robot_state_publisher-1] [INFO] [1736328095.667978059] [robot_state_publisher]: got segment laser_link
[robot_state_publisher-1] [INFO] [1736328095.667982387] [robot_state_publisher]: got segment left_wheel_link
[robot_state_publisher-1] [INFO] [1736328095.667986896] [robot_state_publisher]: got segment right_wheel_link
[rviz2-3] [INFO] [1736328096.051481139] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-3] [INFO] [1736328096.051679395] [rviz2]: OpenGl version: 4.3 (GLSL 4.3)
[joint_state_publisher-2] [INFO] [1736328096.065208564] [joint_state_publisher]: Waiting for robot_description to be published on the robot_description topic...
[rviz2-3] [INFO] [1736328096.105255489] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-3] Error: Inertial: inertia element izz is not a valid double
[rviz2-3] at line 334 in ./urdf_parser/src/link.cpp
[rviz2-3] Error: Could not parse inertial element for Link [camera_link]
[rviz2-3] at line 435 in ./urdf_parser/src/link.cpp
[rviz2-3] Error: Inertial: inertia element izz is not a valid double
[rviz2-3] at line 334 in ./urdf_parser/src/link.cpp
[rviz2-3] Error: Could not parse inertial element for Link [imu_link]
[rviz2-3] at line 435 in ./urdf_parser/src/link.cpp日志显示惯性数据不是双精度但是检查了下代码没什么问题
惯性设置xacro文件代码:
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:macro name="box_interia" params="m w h d">
<inertial>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<mass value="${m}"/>
<inertia ixx="${(m/12)(hh+dd)}" ixy="0.0" ixz="0.0" iyy="${(m/12.0)(ww+dd)}" iyz="0.0" izz="{(m/12.0)(ww+h*h)}"/>
</inertial>
</xacro:macro><xacro:macro name="cylinder_interia" params="m r h"> <inertial> <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/> <mass value="${m}"/> <inertia ixx="${(m/12)*(3*r*r+h*h)}" ixy="0.0" ixz="0.0" iyy="${(m/12.0)*(3*r*r+h*h)}" iyz="0.0" izz="${(m/2.0)*(r*r)}"/> </inertial> </xacro:macro> <xacro:macro name="sphere_interia" params="m r"> <inertial> <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/> <mass value="${m}"/> <inertia ixx="${(2/5)*m*(r*r)}" ixy="0.0" ixz="0.0" iyy="${(2.0/5.0)*m*(r*r)}" iyz="0.0" izz="${(2.0/5.0)*m*(r*r)}"/> </inertial> </xacro:macro>
</robot>
-
从你提供的日志和代码来看,问题主要出在惯性(inertia)的计算和表示上。这里有几个关键点需要注意:
-
惯性公式中的变量表示:
在你的box_interia
宏中,惯性计算公式使用了变量hh
,dd
,ww
,但这些变量并没有在宏的参数或宏内部被定义。你应该使用传入的参数h
,d
,w
来计算惯性。 -
变量替换和计算:
在 XACRO 中,你需要确保所有的变量替换都正确无误,并且计算表达式也是正确的。在 XACRO 中,你可以直接使用数学表达式,但需要注意表达式的正确性和变量的准确性。 -
XACRO 的语法:
在 XACRO 文件中,确保所有的 XML 标签都正确闭合,并且 XACRO 的宏定义和调用都符合语法规则。
针对你的问题,你可以修改
box_interia
宏如下:<xacro:macro name="box_interia" params="m w h d"> <inertial> <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/> <mass value="${m}"/> <inertia ixx="${(m/12.0)*(h*h + d*d)}" ixy="0.0" ixz="0.0" iyy="${(m/12.0)*(w*w + d*d)}" iyz="0.0" izz="${(m/12.0)*(w*w + h*h)}"/> </inertial> </xacro:macro>
这里我做了以下修改:
- 使用
${(m/12.0)*(h*h + d*d)}
替换原来的${(m/12)(hh+dd)}
,确保使用正确的参数h
和d
。 - 类似地,对
iyy
和izz
也进行了修改。
确保在你的主 URDF 文件中正确调用了这个宏,并且传入了正确的参数。
另外,你的
camera_xacro
宏中的camera_optical_link
链接定义不完整,它缺少<visual>
,<collision>
, 和<inertial>
元素。如果camera_optical_link
只是一个虚拟链接,用于定位相机的光学中心,并且不需要在 RViz 中显示,你可以忽略这些元素。但如果你希望在 RViz 中看到它,你需要为它添加相应的视觉和碰撞属性。最后,确保你的
dispalay_robot.launch.py
文件中正确设置了 URDF 文件的路径,并且所有必要的 ROS 节点和组件都已正确启动。如果问题仍然存在,你可能需要检查 ROS 2 的日志以获取更多信息。
以上为生成回答,仅供参考~
-
-
我还发现了一个神奇的事情哥。我每次启动在rviz中会出现两个robotmodel,其中一个只包含机器人主体和惯性单元,另一个除了IMU和相机为外都包含,都没有相机的外观,但是TF坐标却都是完整的,这是啥情况
-
@2118561423 你添加了两个robotomodel插件了
-
@小鱼 感谢鱼哥,我又仔细检查了下应该是正方体惯性数据定义的时候少了一个dollar符导致rviz2启动经常出错误,修改后已经恢复正常了,感谢鱼哥答复
-
@小鱼 在 6.4.7机器人建模时在rviz中相机模块有质量和TF但是模块不可见 中说:
@2118561423 你添加了两个robotomodel插件了