ros2-6.4.4 两轮差速控制机器人的问题

遇到一个问题。本节开始尝试在gazebo中仿真上一节构建的模型。

先贴一下现象,启动launch之后,gazebo显示正常移动。但是在rviz中查看就是有问题的:

fixedframe:选择odom.显示添加机器人,按topic 选择。提示:

no transform from left wheel to odom

No transform from right_wheel_link to odom

可以通过键盘控制小车移动,对比视频:不能显示小车两个轮子TF转动。

如果 fixedframe切回base_link ,在rviz显示是正常的,轮子部件都在。

在gazebo显示正常

TF tree对比视频不太一样,视频里面左右轮子right_wheel_link都是在 base_footprint下。

关键代码:

启动脚本

python 复制代码
import launch
import launch.launch_description_sources
import launch_ros
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    # 获取功能包默认路径
    urdf_tutorial_path = get_package_share_directory('fishbot_description')
    default_model_path = urdf_tutorial_path + '/urdf/fishbot/fish_robot.urdf.xacro'
    default_world_path = urdf_tutorial_path + '/world/custom_room.world'
    # 为 Launch 声明参数
    action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument(
        name='model', default_value=str(default_model_path),
        description='加载模型文件的绝对路径')
    # 获取文件内容生成新的参数
    robot_description = launch_ros.parameter_descriptions.ParameterValue(
        launch.substitutions.Command(
            ['xacro ', launch.substitutions.LaunchConfiguration('model')]),
        value_type=str)
    # 状态发布节点
    robot_state_publisher_node = launch_ros.actions.Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        parameters=[{'robot_description': robot_description}]
    )


    # 通过 IncludeLaunchDescription 包含另外一个 launch 文件
    launch_gazebo = launch.actions.IncludeLaunchDescription(
        launch.launch_description_sources.PythonLaunchDescriptionSource([get_package_share_directory(
            'gazebo_ros'), '/launch', '/gazebo.launch.py']),
      	# 传递参数
        launch_arguments=[('world', default_world_path),('verbose','true')]
    )
    #请求gazebo 加载机器人
    action_spawn_entity = launch_ros.actions.Node(
        package= 'gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-topic', '/robot_description','-entity', 'fishbot']
    )

    return launch.LaunchDescription([
        action_declare_arg_mode_path,
        robot_state_publisher_node,
        launch_gazebo,
        action_spawn_entity,
    ])

定义模型

XML 复制代码
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="fishbot">
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/base.urdf.xacro" />
    <!-- 传感器组件 -->
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/imu.urdf.xacro" />
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/laser.urdf.xacro" />
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/camera.urdf.xacro" />
    <!-- 执行器组件 -->
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/wheel.urdf.xacro" />
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/caster.urdf.xacro" />
    <!--gazebo插件-->
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_control_plugin.xacro" />
    
    <xacro:base_xacro length="0.12" radius="0.1" />
    <!-- 传感器 -->
    <xacro:imu_xacro xyz="0 0 0.02" />
    <xacro:laser_xacro xyz="0 0 0.10" />
    <xacro:camera_xacro xyz="0.10 0 0.075" />
       <!-- 执行器主动轮+从动轮 -->
    <xacro:wheel_xacro wheel_name="left_wheel" xyz="0 0.10 -0.06" />
    <xacro:wheel_xacro wheel_name="right_wheel" xyz="0 -0.10 -0.06" />
    <xacro:caster_xacro caster_name="front_caster" xyz="0.08 0.0 -0.076" />
    <xacro:caster_xacro caster_name="back_caster" xyz="-0.08 0.0 -0.076" />

    <xacro:gazebo_control_plugin />
</robot>

轮子定义:

XML 复制代码
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
   <xacro:include filename="$(find fishbot_description)/urdf/fishbot/common_inertia.xacro" />
    <xacro:macro name="wheel_xacro" params="wheel_name xyz">
        <link name="${wheel_name}_link">
            <visual>
                <origin xyz="0 0 0" rpy="1.57079 0 0" />
                <geometry>
                    <cylinder length="0.04" radius="0.032" />
                </geometry>
                <material name="yellow">
                    <color rgba="1.0 1.0 0.0 0.8"/>
                </material>
            </visual>
           <collision>
                <origin xyz="0 0 0" rpy="1.57079 0 0" />
                <geometry>
                    <cylinder length="0.04" radius="0.032" />
                </geometry>
                <material name="yellow">
                    <color rgba="1.0 1.0 0.0 0.8"/>
                </material>
            </collision>
             <xacro:cylinder_inertia m="0.1" h="0.04" r="0.032"/>
        </link>
        <gazebo reference="${wheel_name}_link">
            <mu1 value="20.0" />
            <mu2 value="20.0" />
            <kp value="1000000000.0" />
            <kd value="1.0" />
        </gazebo>

        <joint name="${wheel_name}_joint" type="continuous">
            <parent link="base_link" />
            <child link="${wheel_name}_link" />
            <origin xyz="${xyz}" />
            <!--轮子绕那个轴旋转-->
            <axis xyz="0 1 0" />
        </joint>
    </xacro:macro>
</robot>

差速控制:

XML 复制代码
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
    <xacro:macro name="gazebo_control_plugin">
        <gazebo>
            <plugin name='diff_drive' filename='libgazebo_ros_diff_drive.so'>
                <ros>
                    <namespace>/</namespace>
                    <remapping>cmd_vel:=cmd_vel</remapping>
                    <remapping>odom:=odom</remapping>
                </ros>
                <update_rate>30</update_rate>
                <!-- wheels -->
                <left_joint>left_wheel_joint</left_joint>
                <right_joint>right_wheel_joint</right_joint>
                <!-- kinematics -->
                <wheel_separation>0.2</wheel_separation>
                <wheel_diameter>0.064</wheel_diameter>
                <!-- limits -->
                <max_wheel_torque>20</max_wheel_torque>
                <max_wheel_acceleration>1.0</max_wheel_acceleration>
                <!-- output -->
                <publish_odom>true</publish_odom>
                <publish_odom_tf>true</publish_odom_tf>
                <publish_wheel_tf>true</publish_wheel_tf>

                <odometry_frame>odom</odometry_frame>
                <robot_base_frame>base_footprint</robot_base_frame>
            </plugin>
        </gazebo>
   </xacro:macro>
</robot>
相关推荐
GlobalInfo4 小时前
机器人线缆用无卤TPU料市场分析报告深度版:产业洞察、技术演进与路径
大数据·人工智能·机器人
AiNightVision5 小时前
电力巡检夜视方案选型指南——无人机/机器人/固定监测三种场景怎么选
人工智能·科技·车载系统·机器人·无人机·边缘计算·视频
咕泡科技6 小时前
AI前沿速递:Gemini双连发+混元双档落地!智元发布首个机器人工时KPI,具身智能分出工厂与客厅两条赛道
人工智能·机器人·腾讯混元·智元机器人·gemini4carbon·巴布机器人
天树星智源7 小时前
静态物理满分、交互 11.54%:3D 场景生成系统的幻觉
论文阅读·人工智能·3d·机器人
咬代码的兽7 小时前
智元创新日拆解:机器人开始按工时结算,Token之后有了Worken
机器人
趣味科技v7 小时前
具身智能从“演示”走向“部署”:智元把机器人送进真实工位
机器人·具身智能·智元
Wanda12147 小时前
机器人与机电一体化3D数字孪生机器-Day9
人工智能·3d·unity·机器人·数字孪生
超级架构师8 小时前
让 Fortran 模型自己调用 Agent:原生 Fortran 2008 实现深度剖析
人工智能·python·架构·机器人·开源·fortran
JIAOZHANZHISHIKU15 小时前
机器人外壳粘接性价比怎么选?3M VHB 胶带与结构胶解决方案
经验分享·机器人·工业胶粘剂·3m胶粘剂
GlobalInfo16 小时前
2026年机器人多指灵巧手市场分析报告——涵盖行业调查、趋势分析与发展前景
大数据·人工智能·microsoft·微服务·机器人