<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Gazebo仿真时小车在自动旋转]]></title><description><![CDATA[<p dir="auto">我做了一个简易的两轮差速小车模型，启动仿真后没有发出任何控制指令，两个驱动轮莫名旋转。</p>
<h1>环境：</h1>
<p dir="auto">Ubuntu 22.04 + ROS2 Humble + Gazebo Classic</p>
<h1>尝试了这些方式，问题依然存在：</h1>
<ul>
<li>起初以为是惯性张量问题，在solidwork建模(模型没有用到URDF中)并设置材料密度后，把软件计算的质量和惯性张量复制到URDF文件中，无法解决问题</li>
<li>为left_wheel_joint和right_wheel_joint都添加了dynamics，无法解决问题</li>
<li>增加摩擦系数到2.0，无法解决问题</li>
<li>调整轮子与底面接触距离，无法解决问题</li>
</ul>
<p dir="auto"><strong>注：在Gazebo中将重力调为0后模型飘在空中，但是点击JOINTS查看left_wheel_joint和right_wheel_joint时有个属性angle_0在不断变化</strong><br />
<img src="/forum/assets/uploads/files/1777023540475-2f6fa84f-1afb-4526-ada9-f20185576e8f.png" alt="2f6fa84f-1afb-4526-ada9-f20185576e8f.png" class=" img-fluid img-markdown" /></p>
<h1>仿真图片</h1>
<p dir="auto"><img src="/forum/assets/uploads/files/1777023742642-ba94f9fe-a024-4850-8013-6e3f4b78c95c.png" alt="ba94f9fe-a024-4850-8013-6e3f4b78c95c.png" class=" img-fluid img-markdown" /><br />
<img src="/forum/assets/uploads/files/1777023752943-38d628dd-d5a1-4967-8b8e-8e650f42f8f1.png" alt="38d628dd-d5a1-4967-8b8e-8e650f42f8f1.png" class=" img-fluid img-markdown" /></p>
<h1>URDF文件内容：</h1>
<pre><code>&lt;?xml version="1.0"?&gt;
&lt;robot name="test_robot"&gt;
    &lt;link name="base_footprint" &gt;
    &lt;/link&gt;

    &lt;link name="base_link"&gt;
        &lt;visual&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;box size="0.4 0.2 0.1"/&gt;
            &lt;/geometry&gt;
            &lt;material name="red"&gt;
                &lt;color rgba="1.0 0.0 0.0 1.0"/&gt;
            &lt;/material&gt;
        &lt;/visual&gt;
        &lt;collision&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;box size="0.4 0.2 0.1"/&gt;
            &lt;/geometry&gt;
            &lt;material name="red"&gt;
                &lt;color rgba="1.0 0.0 0.0 1.0"/&gt;
            &lt;/material&gt;
        &lt;/collision&gt;
        &lt;inertial&gt;
            &lt;mass value="4.0"/&gt;
            &lt;inertia ixx="0.016667" ixy="0" ixz="0" iyy="0.056667" iyz="0" izz="0.066667"/&gt;
        &lt;/inertial&gt;
    &lt;/link&gt;
    &lt;joint name="base_joint" type="fixed"&gt;
        &lt;origin xyz="0.0 0.0 0.075" rpy="0.0 0.0 0.0"/&gt;
        &lt;parent link="base_footprint"/&gt;
        &lt;child link="base_link"/&gt;
    &lt;/joint&gt;

    &lt;link name="left_wheel_link"&gt;
        &lt;visual&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="1.570796327 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;cylinder radius="0.025" length="0.01"/&gt;
            &lt;/geometry&gt;
            &lt;density&gt;1000.0&lt;/density&gt;
            &lt;material name="green"&gt;
                &lt;color rgba="0.0 1.0 0.0 1.0"/&gt;
            &lt;/material&gt;
        &lt;/visual&gt;
        &lt;collision&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="1.570796327 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;cylinder radius="0.025" length="0.01"/&gt;
            &lt;/geometry&gt;
        &lt;/collision&gt;
        &lt;inertial&gt;
            &lt;mass value="0.019635"/&gt;
            &lt;inertia ixx="3.232e-6" iyy="6.136e-6" izz="3.232e-6" ixy="0" ixz="0" iyz="0"/&gt;
        &lt;/inertial&gt;
    &lt;/link&gt;
    &lt;joint name="left_wheel_joint" type="continuous"&gt;
        &lt;origin xyz="-0.15 0.105 -0.051" rpy="0.0 0.0 0.0"/&gt;
        &lt;parent link="base_link"/&gt;
        &lt;child link="left_wheel_link"/&gt;
        &lt;axis xyz="0.0 1.0 0.0" /&gt;
        &lt;dynamics damping="1.0" friction="0.2"/&gt;
        &lt;limit lower="0.0" upper="0.0" effort="10.0" velocity="0.0"/&gt;
    &lt;/joint&gt;

    &lt;link name="right_wheel_link"&gt;
        &lt;visual&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="1.570796327 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;cylinder radius="0.025" length="0.01"/&gt;
            &lt;/geometry&gt;
            &lt;density&gt;1000.0&lt;/density&gt;
            &lt;material name="blue"&gt;
                &lt;color rgba="0.0 0.0 1.0 1.0"/&gt;
            &lt;/material&gt;
        &lt;/visual&gt;
        &lt;collision&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="1.570796327 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;cylinder radius="0.025" length="0.01"/&gt;
            &lt;/geometry&gt;
            &lt;density&gt;1000.0&lt;/density&gt;
        &lt;/collision&gt;
        &lt;inertial&gt;
            &lt;mass value="0.019635"/&gt;
            &lt;inertia ixx="3.232e-6" iyy="6.136e-6" izz="3.232e-6" ixy="0" ixz="0" iyz="0"/&gt;
        &lt;/inertial&gt;
    &lt;/link&gt;
    &lt;joint name="right_wheel_joint" type="continuous"&gt;
        &lt;origin xyz="-0.15 -0.105 -0.051" rpy="0.0 0.0 0.0"/&gt;
        &lt;parent link="base_link"/&gt;
        &lt;child link="right_wheel_link"/&gt;
        &lt;axis xyz="0.0 1.0 0.0" /&gt;
        &lt;dynamics damping="1.0" friction="0.2"/&gt;
        &lt;limit lower="0.0" upper="0.0" effort="10.0" velocity="0.0"/&gt;
    &lt;/joint&gt;

    &lt;link name="front_wheel_link"&gt;
        &lt;visual &gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;sphere radius="0.025"/&gt;
            &lt;/geometry&gt;
            &lt;density&gt;1000.0&lt;/density&gt;
            &lt;material name="yellow"&gt;
                &lt;color rgba="1.0 1.0 0.0 1.0"/&gt;
            &lt;/material&gt;
        &lt;/visual&gt;
        &lt;collision&gt;
            &lt;origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/&gt;
            &lt;geometry&gt;
                &lt;sphere radius="0.025"/&gt;
            &lt;/geometry&gt;
            &lt;density&gt;1000.0&lt;/density&gt;
        &lt;/collision&gt;
        &lt;inertial&gt;
            &lt;mass value="0.06545"/&gt;
            &lt;inertia ixx="1.636e-5" iyy="1.636e-5" izz="1.636e-5" ixy="0" ixz="0" iyz="0"/&gt;
        &lt;/inertial&gt;
    &lt;/link&gt;
    &lt;joint name="front_wheel_joint" type="fixed"&gt;
        &lt;origin xyz="0.15 0.0 -0.051" rpy="0.0 0.0 0.0"/&gt;
        &lt;parent link="base_link"/&gt;
        &lt;child link="front_wheel_link"/&gt;
        &lt;axis xyz="0.0 0.0 0.0"/&gt;
        &lt;limit lower="0.0" upper="0.0" effort="0.0" velocity="0.0"/&gt;
    &lt;/joint&gt;


    &lt;!--Gazebo材质与颜色--&gt;
    &lt;gazebo reference="base_link"&gt;
        &lt;material&gt;Gazebo/Red&lt;/material&gt;
    &lt;/gazebo&gt;
    &lt;gazebo reference="left_wheel_link"&gt;
        &lt;material&gt;Gazebo/Green&lt;/material&gt;
    &lt;/gazebo&gt;
    &lt;gazebo reference="right_wheel_link"&gt;
        &lt;material&gt;Gazebo/Blue&lt;/material&gt;
    &lt;/gazebo&gt;
    &lt;gazebo reference="front_wheel_link"&gt;
        &lt;material&gt;Gazebo/Yellow&lt;/material&gt;
    &lt;/gazebo&gt;

    &lt;!--Gazebo摩擦系数--&gt;
    &lt;gazebo reference="left_wheel_link"&gt;
        &lt;mu1&gt;0.8&lt;/mu1&gt;
        &lt;mu2&gt;0.8&lt;/mu2&gt;
    &lt;/gazebo&gt;
    &lt;gazebo reference="right_wheel_link"&gt;
        &lt;mu1&gt;0.8&lt;/mu1&gt;
        &lt;mu2&gt;0.8&lt;/mu2&gt;
    &lt;/gazebo&gt;

    &lt;!--ROS2控制框架(ros2_control)--&gt;
    &lt;ros2_control name="GazeboSim" type="system"&gt;
        &lt;hardware&gt;
            &lt;plugin&gt;gazebo_ros2_control/GazeboSystem&lt;/plugin&gt;
        &lt;/hardware&gt;
        &lt;joint name="left_wheel_joint"&gt;
            &lt;command_interface name="velocity"&gt;
                &lt;param name="min"&gt;-10.0&lt;/param&gt;
                &lt;param name="max"&gt;10.0&lt;/param&gt;
            &lt;/command_interface&gt;
            &lt;state_interface name="position"/&gt;
            &lt;state_interface name="velocity"/&gt;
        &lt;/joint&gt;
        &lt;joint name="right_wheel_joint"&gt;
            &lt;command_interface name="velocity"&gt;
                &lt;param name="min"&gt;-10.0&lt;/param&gt;
                &lt;param name="max"&gt;10.0&lt;/param&gt;
            &lt;/command_interface&gt;
            &lt;state_interface name="position"/&gt;
            &lt;state_interface name="velocity"/&gt;
        &lt;/joint&gt;
    &lt;/ros2_control&gt;

    &lt;!--Gazebo仿真插件:加载控制框架--&gt;
    &lt;gazebo&gt;
        &lt;plugin name="gazebo_ros2_control" filename="libgazebo_ros2_control.so"&gt;
            &lt;parameters&gt;/home/yahboom/wheeltec_ros2/install/wheeltec_robot_urdf/share/wheeltec_robot_urdf/configs/diff_drive_controller.yaml&lt;/parameters&gt;
            &lt;robot_param&gt;robot_description&lt;/robot_param&gt;
        &lt;/plugin&gt;
    &lt;/gazebo&gt;

&lt;/robot&gt;
</code></pre>
<h1>差速控制器配置文件：</h1>
<pre><code>## configs/diff_drive.yaml
/controller_manager:
  ros__parameters:
    update_rate: 100
    # 声明使用的控制器
    joint_state_broadcaster:
      type: joint_state_broadcaster/JointStateBroadcaster
    diff_drive_controller:
      type: diff_drive_controller/DiffDriveController

# 关节状态广播器配置
joint_state_broadcaster:
  ros__parameters:
    joints:
      - left_wheel_joint
      - right_wheel_joint

# 差速控制器核心配置
diff_drive_controller:
  ros__parameters:
    use_stamped_vel: false
    cmd_vel_topic: "/cmd_vel_unstamped"
    odom_topic: "/odom"
    # 输入/输出话题
    left_wheel_names: ["left_wheel_joint"]
    right_wheel_names: ["right_wheel_joint"]
    
    wheel_separation: 0.21          # 左右轮间距，单位米
    wheel_radius: 0.025             # 轮子半径，单位米
    
    # 控制与里程计参数
    publish_rate: 50.0              # 里程计发布频率
    odom_frame_id: odom
    base_frame_id: base_footprint
    
    # 开放控制回路
    open_loop: false
    enable_odom_tf: true
    
    # 命令接口
    cmd_vel_timeout: 0.5
    # 速度指令限制
    linear:
      x:
        has_velocity_limits: true
        max_velocity: 0.5
        has_acceleration_limits: true
        max_acceleration: 1.0
    angular:
      z:
        has_velocity_limits: true
        max_velocity: 1.0
        has_acceleration_limits: true
        max_acceleration: 2.0
</code></pre>
<h2>启动文件：</h2>
<pre><code>import os
import launch
import launch.launch_description_sources
from ament_index_python import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python import get_package_share_path
from launch.actions import ExecuteProcess,RegisterEventHandler
from launch.event_handlers import OnProcessExit

def generate_launch_description():

    pkg_share = get_package_share_directory('wheeltec_robot_urdf')
    urdf_file_path = os.path.join(pkg_share,'test','test_diff_robot.urdf')
    with open(urdf_file_path,'r') as f:
        urdf_description_context = f.read()

    gazebo_pkg_share = get_package_share_path('gazebo_ros')
    gazebo_world_path = os.path.join(pkg_share,'world','room2.world')

    # 机器人状态发布器
    action_robot_state_pubilsher = Node(
        package = 'robot_state_publisher',
        executable = 'robot_state_publisher',
        name = 'robot_state_publisher',
        parameters=[{'robot_description':urdf_description_context}]
    )

    # 启动Gazebo仿真器(包含gzserver和gzclient)
    action_launch_gazebo = launch.actions.IncludeLaunchDescription(
        launch.launch_description_sources.PythonLaunchDescriptionSource(
            os.path.join(gazebo_pkg_share,'launch','gazebo.launch.py')
        ),
        launch_arguments={
            'world':gazebo_world_path,
            'verbose':'true',
            'use_sim_time': 'true'
        }.items()
    )

    # 将机器人模型生成到Gazebo世界中
    action_spawn_entity = Node(
        package='gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-topic', 'robot_description', '-entity', 'test_robot'],
        output='screen'
    )

    # 在spawn_entity启动后再启动joint_state_broadcaster和diff_drive_controller
    action_load_joint_state_controller = ExecuteProcess(
        cmd = 'ros2 control load_controller joint_state_broadcaster --set-state active'.split(' '),
        output = 'screen'
    )

    action_load_diff_drive_controller = ExecuteProcess(
        cmd = 'ros2 control load_controller diff_drive_controller --set-state active'.split(' '),
        output = 'screen'
    )

    delay_controllers = RegisterEventHandler(
        event_handler=OnProcessExit(
            target_action=action_spawn_entity,
            on_exit=[action_load_joint_state_controller, action_load_diff_drive_controller]
        )
    )

    return LaunchDescription([
        action_robot_state_pubilsher,
        action_launch_gazebo,
        action_spawn_entity,
        delay_controllers,
    ])
</code></pre>
]]></description><link>https://fishros.org.cn/forum/topic/4765/gazebo仿真时小车在自动旋转</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 22:29:12 GMT</lastBuildDate><atom:link href="https://fishros.org.cn/forum/topic/4765.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 24 Apr 2026 09:45:20 GMT</pubDate><ttl>60</ttl></channel></rss>