You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装ros-foxy-image-transport-plugins后Odom无法发布求助

问题

ROS 2 Foxy(Ubuntu 20.04)环境下开发差速驱动四轮机器人,原本在Gazebo和Rviz2中可视化、TF变换、odom发布均正常,接入相机xacro后也能正常显示相机。但安装ros-foxy-image-transport-plugins插件后出现以下异常:

  • /odom话题停止发布
  • 机器人启动时提示“Frame Odom不存在”
  • 轮子关节、相机关节的TF变换提示“未映射到odom”
    卸载该插件后所有功能完全恢复。

相关代码

camera.xacro

<?xml version="1.0" ?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
  <joint name="camera_joint" type="fixed">
    <parent link="chassis" />
    <child link="camera_link" />
    <origin xyz="0.14 0 0.045" rpy="0 0 0" />
  </joint>

  <link name="camera_link">
    <visual>
      <geometry>
        <box size="0.010 0.03 0.03"/>
      </geometry>
      <material name="red">
      </material>
    </visual>
  </link>

  <joint name="camera_optical_joint" type="fixed">
    <parent link="camera_link"/>
    <child link="camera_link_optical"/>
    <origin xyz="0.0 0.0 0.0" rpy="${-pi/2} 0.0 ${-pi/2}"/>
  </joint>

  <link name="camera_link_optical"></link>

  <gazebo reference="camera_link">
      <material>Gazebo/Red</material>
      <sensor name="camera" type="camera">
          <pose> 0 0 0 0 0 0 </pose>
          <visualize>true</visualize>
          <update_rate>10</update_rate>
            <camera>
              <horizontal_fov>1.809</horizontal_fov>
              <image>
                <format>R8G8B8</format>
                <width>640</width>
                <height>480</height>
              </image>
              <clip>
                <near>0.05</near>
                <far>8.0</far>
              </clip>
            </camera>
          <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
              <frame_name>camera_link_optical</frame_name>
          </plugin>
      </sensor>
  </gazebo>
</robot>

camera.launch.py

import os

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='v4l2_camera',
            executable='v4l2_camera_node',
            output='screen',
            parameters=[{
                'image_size': [640,480],
                'camera_frame_id': 'camera_link_optical'
                }]
        )
    ])

gazebo_control.xacro

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

  <gazebo>
    <plugin name='diff_drive' filename='libgazebo_ros_diff_drive.so'>
        <!-- WHEEL INFORMATION -->
        <num_wheel_pairs>2</num_wheel_pairs>

        <right_joint>front_right_joint</right_joint>
        <left_joint>front_left_joint</left_joint>
        <right_joint>back_right_joint</right_joint>
        <left_joint>back_left_joint</left_joint>

        <wheel_separation>0.24</wheel_separation>   
        <wheel_separation>0.24</wheel_separation>   

        <wheel_diameter>0.13</wheel_diameter>
        <wheel_diameter>0.13</wheel_diameter>

        <!-- LIMITS -->
        <max_wheel_torque>200</max_wheel_torque>
        <max_wheel_acceleration>10.0</max_wheel_acceleration>

        <!-- OUTPUT -->
        <odometry_topic>odom</odometry_topic>
        <odometry_frame>odom</odometry_frame>
        <robot_base_frame>base_link</robot_base_frame>

        <publish_odom>true</publish_odom>
        <publish_odom_tf>true</publish_odom_tf>
        <publish_wheel_tf>true</publish_wheel_tf>
    </plugin>

    <plugin name="gazebo_ros_joint_state_publisher" filename="libgazebo_ros_joint_state_publisher.so">
      <updateRate>20</updateRate>
      <joint_name>front_right_joint</joint_name>
      <joint_name>front_left_joint</joint_name>
      <joint_name>back_right_joint</joint_name>
      <joint_name>back_left_joint</joint_name>
    </plugin>
  </gazebo>
</robot>
排查与解决方法
  1. 修复帧命名大小写问题
    ROS 2的TF帧名区分大小写,错误提示中的“Frame Odom”(大写O)与配置里的odom(小写)不匹配会导致TF查找失败。统一所有配置和代码中的帧名为小写odom,确保路径一致。

  2. 解决插件依赖冲突
    image-transport-plugins可能引入了与gazebo_ros_diff_drive冲突的TF相关依赖,尝试清理后重新安装插件:

sudo apt purge ros-foxy-image-transport-plugins
sudo apt autoremove
sudo apt install ros-foxy-image-transport-plugins --no-install-recommends
  1. 调整相机插件TF配置
    在camera.xacro的相机插件中显式指定TF发布参数,避免插件自动修改TF树逻辑:
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
    <frame_name>camera_link_optical</frame_name>
    <publish_tf>true</publish_tf>
    <tf_prefix></tf_prefix>
</plugin>
  1. 调整节点启动顺序
    确保发布odom TF的差速驱动插件在相机节点之前启动。修改机器人主启动文件,将包含gazebo_control.xacro的启动逻辑放在相机启动节点之前,保证TF树根节点odom先被创建。

  2. 检查TF树完整性
    启动机器人后,用以下命令查看TF树,确认odom到base_link的变换存在:

ros2 run tf2_tools view_frames.py

如果odom未出现,检查diff_drive插件日志,确认是否有初始化失败的错误。

内容的提问来源于stack exchange,提问作者Praveen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 12:05:08