<?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[关于我自制了一个ROS小车的仿真模型，Gazebo车轮陷入地下]]></title><description><![CDATA[<h1>我自制了一个ROS小车的仿真模型，Gazebo车轮陷入地下</h1>
<p dir="auto">求大佬帮我看看</p>
<h2>主要问题</h2>
<p dir="auto">在rviz中的显示为<img src="/forum/assets/uploads/files/1769436557356-65d6063c-9168-4cc9-9138-6e8fb37d803b-image-resized.png" alt="65d6063c-9168-4cc9-9138-6e8fb37d803b-image.png" class=" img-fluid img-markdown" /><br />
在Gazebo中的显示为：<br />
<img src="/forum/assets/uploads/files/1769436515308-ddaae488-3054-4dd9-a942-065585ae192b-image.png" alt="ddaae488-3054-4dd9-a942-065585ae192b-image.png" class=" img-fluid img-markdown" /></p>
<h2>相关代码</h2>
<p dir="auto">URDF文件如下：</p>
<pre><code class="language-xml">&lt;?xml version="1.0"?&gt;
&lt;robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="ros_car"&gt;

	&lt;!-- 坐标系：x前、y左、z上。单位：米 --&gt;
	&lt;!-- 总质量约 1.6kg；这里把轮子质量估为 0.08kg/个，底盘质量自动补齐 --&gt;
	&lt;xacro:property name="total_mass" value="1.6"/&gt;
	&lt;xacro:property name="wheel_mass" value="0.044"/&gt;
	&lt;xacro:property name="base_mass" value="${total_mass - 4.0*wheel_mass}"/&gt;

	&lt;!-- 车体长方体：150*200*100mm。按常见约定我取：长度x=200mm，宽度y=150mm，高度z=100mm --&gt;
	&lt;!-- 如果你确实想 x=150,y=200，交换 base_length/base_width 即可 --&gt;
	&lt;xacro:property name="base_length" value="0.200"/&gt;
	&lt;xacro:property name="base_width" value="0.150"/&gt;
	&lt;xacro:property name="base_height" value="0.100"/&gt;

	&lt;!-- 麦轮：直径60mm，宽24.5mm --&gt;
	&lt;xacro:property name="wheel_radius" value="0.030"/&gt;
	&lt;xacro:property name="wheel_width" value="0.0245"/&gt;

	&lt;!-- 轮中心相对 base_link：|x|=60mm, |y|=87.5mm --&gt;
	&lt;xacro:property name="wheel_x" value="0.060"/&gt;
	&lt;xacro:property name="wheel_y" value="0.0875"/&gt;

	&lt;!-- 为了Gazebo不穿地：轮中心相对 base_link 的 z 取 -base_height/2 (= -50mm) --&gt;
	&lt;!-- 如果你只想严格按你描述（z=0），把下面改成 0 --&gt;
	&lt;xacro:property name="wheel_z_in_base" value="${-base_height/2.0}"/&gt;

	&lt;!-- 传感器安装（相对 base_link） --&gt;
	&lt;!-- A1：(-40mm, 0, 65mm)；D435i：(80mm, 0, 62.5mm) --&gt;
	&lt;xacro:property name="lidar_x" value="-0.040"/&gt;
	&lt;xacro:property name="lidar_y" value="0.000"/&gt;
	&lt;xacro:property name="lidar_z" value="0.065"/&gt;

	&lt;xacro:property name="camera_x" value="0.080"/&gt;
	&lt;xacro:property name="camera_y" value="0.000"/&gt;
	&lt;xacro:property name="camera_z" value="0.0625"/&gt;

	&lt;!-- D435i 形状：100*25*25mm --&gt;
	&lt;xacro:property name="camera_box_x" value="0.100"/&gt;
	&lt;xacro:property name="camera_box_y" value="0.025"/&gt;
	&lt;xacro:property name="camera_box_z" value="0.025"/&gt;

	&lt;!-- A1 底座：100*100*30mm；雷达本体：圆柱直径70mm，高25mm --&gt;
	&lt;xacro:property name="lidar_base_xy" value="0.100"/&gt;
	&lt;xacro:property name="lidar_base_z" value="0.030"/&gt;
	&lt;xacro:property name="lidar_cyl_d" value="0.070"/&gt;
	&lt;xacro:property name="lidar_cyl_z" value="0.025"/&gt;

	&lt;!-- ================= 惯量宏（够用，后续可精修） ================= --&gt;
	&lt;xacro:macro name="inertial_box" params="m x y z"&gt;
		&lt;inertial&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;mass value="${m}"/&gt;
			&lt;inertia ixx="${(m/12.0) * (y*y + z*z)}" iyy="${(m/12.0) * (x*x + z*z)}" izz="${(m/12.0) * (x*x + y*y)}" ixy="0" ixz="0" iyz="0"/&gt;
		&lt;/inertial&gt;
	&lt;/xacro:macro&gt;

	&lt;xacro:macro name="inertial_cylinder_y" params="m r h"&gt;
		&lt;inertial&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;mass value="${m}"/&gt;
			&lt;inertia ixx="${(m/12.0) * (3*r*r + h*h)}" iyy="${(m/2.0)  * (r*r)}" izz="${(m/12.0) * (3*r*r + h*h)}" ixy="0" ixz="0" iyz="0"/&gt;
		&lt;/inertial&gt;
	&lt;/xacro:macro&gt;

	&lt;!-- ================= TF 根：base_footprint 在地面投影点 ================= --&gt;
	&lt;link name="base_footprint"/&gt;

	&lt;!-- base_link 放在底盘几何中心；为了让轮子落在地面，base_link 高度=轮半径+底盘高度/2 --&gt;
	&lt;joint name="base_footprint_to_base_link" type="fixed"&gt;
		&lt;origin xyz="0 0 ${wheel_radius + base_height/2.0}" rpy="0 0 0"/&gt;
		&lt;parent link="base_footprint"/&gt;
		&lt;child link="base_link"/&gt;
	&lt;/joint&gt;

	&lt;!-- ================= 底盘（简单长方体） ================= --&gt;
	&lt;link name="base_link"&gt;
		&lt;xacro:inertial_box m="${base_mass}" x="${base_length}" y="${base_width}" z="${base_height}"/&gt;

		&lt;visual&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;box size="${base_length} ${base_width} ${base_height}"/&gt;
			&lt;/geometry&gt;
			&lt;material name="Gray"&gt;
				&lt;color rgba="0.6 0.6 0.6 1.0"/&gt;
			&lt;/material&gt;
		&lt;/visual&gt;

		&lt;collision&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;box size="${base_length} ${base_width} ${base_height}"/&gt;
			&lt;/geometry&gt;
		&lt;/collision&gt;
	&lt;/link&gt;

	&lt;!-- ================= 轮子（四个连续关节） ================= --&gt;
	&lt;xacro:macro name="wheel" params="prefix x y"&gt;
		&lt;link name="${prefix}_wheel_link"&gt;
			&lt;xacro:inertial_cylinder_y m="${wheel_mass}" r="${wheel_radius}" h="${wheel_width}"/&gt;

			&lt;!-- URDF cylinder 默认沿 z 轴；转 90° 让它沿 y 轴（轮子自转轴是 y） --&gt;
			&lt;visual&gt;
				&lt;origin xyz="0 0 0" rpy="1.57079632679 0 0"/&gt;
				&lt;geometry&gt;
					&lt;cylinder radius="${wheel_radius}" length="${wheel_width}"/&gt;
				&lt;/geometry&gt;
				&lt;material name="Black"&gt;
					&lt;color rgba="0.1 0.1 0.1 1.0"/&gt;
				&lt;/material&gt;
			&lt;/visual&gt;

			&lt;collision&gt;
				&lt;origin xyz="0 0 0" rpy="1.57079632679 0 0"/&gt;
				&lt;geometry&gt;
					&lt;cylinder radius="${wheel_radius}" length="${wheel_width}"/&gt;
				&lt;/geometry&gt;
			&lt;/collision&gt;
		&lt;/link&gt;

		&lt;!-- 轮子关节的坐标是“相对 base_link”，x/y 用你给的，z 用 wheel_z_in_base --&gt;
		&lt;joint name="${prefix}_wheel_joint" type="continuous"&gt;
			&lt;origin xyz="${x} ${y} ${wheel_z_in_base}" rpy="0 0 0"/&gt;
			&lt;parent link="base_link"/&gt;
			&lt;child link="${prefix}_wheel_link"/&gt;
			&lt;axis xyz="0 1 0"/&gt;
			&lt;dynamics damping="0.2" friction="0.2"/&gt;
		&lt;/joint&gt;
	&lt;/xacro:macro&gt;

	&lt;!-- LF 左前、RF 右前、LR 左后、RR 右后 --&gt;
	&lt;xacro:wheel prefix="lf" x="${ wheel_x}" y="${ wheel_y}"/&gt;
	&lt;xacro:wheel prefix="rf" x="${ wheel_x}" y="${-wheel_y}"/&gt;
	&lt;xacro:wheel prefix="lr" x="${-wheel_x}" y="${ wheel_y}"/&gt;
	&lt;xacro:wheel prefix="rr" x="${-wheel_x}" y="${-wheel_y}"/&gt;

	&lt;!-- ================= D435i（用长方体表示，放在 camera_link） ================= --&gt;
	&lt;link name="camera_link"&gt;
		&lt;visual&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;box size="${camera_box_x} ${camera_box_y} ${camera_box_z}"/&gt;
			&lt;/geometry&gt;
			&lt;material name="Blue"&gt;
				&lt;color rgba="0.2 0.3 0.9 1.0"/&gt;
			&lt;/material&gt;
		&lt;/visual&gt;
		&lt;collision&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;box size="${camera_box_x} ${camera_box_y} ${camera_box_z}"/&gt;
			&lt;/geometry&gt;
		&lt;/collision&gt;
	&lt;/link&gt;

	&lt;joint name="camera_joint" type="fixed"&gt;
		&lt;origin xyz="${camera_x} ${camera_y} ${camera_z}" rpy="0 0 1.57079632679"/&gt;
		&lt;parent link="base_link"/&gt;
		&lt;child link="camera_link"/&gt;
	&lt;/joint&gt;

	&lt;!-- 可选：相机光学坐标系（ROS常用约定：z向前，x向右，y向下） --&gt;
	&lt;link name="camera_optical_frame"/&gt;
	&lt;joint name="camera_optical_joint" type="fixed"&gt;
		&lt;origin xyz="0 0 0" rpy="-1.57079632679 0 -1.57079632679"/&gt;
		&lt;parent link="camera_link"/&gt;
		&lt;child link="camera_optical_frame"/&gt;
	&lt;/joint&gt;

	&lt;!-- ================= A1 雷达（雷达本体圆柱是 lidar_link；底座单独做成 child link） ================= --&gt;
	&lt;link name="lidar_link"&gt;
		&lt;visual&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;cylinder radius="${lidar_cyl_d/2.0}" length="${lidar_cyl_z}"/&gt;
			&lt;/geometry&gt;
			&lt;material name="White"&gt;
				&lt;color rgba="0.9 0.9 0.9 1.0"/&gt;
			&lt;/material&gt;
		&lt;/visual&gt;
		&lt;collision&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;cylinder radius="${lidar_cyl_d/2.0}" length="${lidar_cyl_z}"/&gt;
			&lt;/geometry&gt;
		&lt;/collision&gt;
	&lt;/link&gt;

	&lt;joint name="lidar_joint" type="fixed"&gt;
		&lt;origin xyz="0 0 ${lidar_cyl_z/2.0 + lidar_base_z/2.0}" rpy="0 0 0"/&gt;
		&lt;parent link="lidar_base_link"/&gt;
		&lt;child link="lidar_link"/&gt;
	&lt;/joint&gt;

	&lt;!-- 底座放在雷达圆柱正下方：偏移 z = -(圆柱半高 + 底座半高) --&gt;
	&lt;joint name="lidar_base_joint" type="fixed"&gt;
		&lt;origin xyz="${lidar_x} ${lidar_y} ${lidar_z}" rpy="0 0 0"/&gt;
		&lt;parent link="base_link"/&gt;
		&lt;child link="lidar_base_link"/&gt;
	&lt;/joint&gt;

	&lt;link name="lidar_base_link"&gt;
		&lt;visual&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;box size="${lidar_base_xy} ${lidar_base_xy} ${lidar_base_z}"/&gt;
			&lt;/geometry&gt;
			&lt;material name="DarkGray"&gt;
				&lt;color rgba="0.25 0.25 0.25 1.0"/&gt;
			&lt;/material&gt;
		&lt;/visual&gt;
		&lt;collision&gt;
			&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
			&lt;geometry&gt;
				&lt;box size="${lidar_base_xy} ${lidar_base_xy} ${lidar_base_z}"/&gt;
			&lt;/geometry&gt;
		&lt;/collision&gt;
	&lt;/link&gt;

	&lt;!-- IMU 坐标系（先给一个标准 link，后续你接真IMU/仿真IMU都方便） --&gt;
	&lt;link name="imu_link"/&gt;
	&lt;joint name="imu_joint" type="fixed"&gt;
		&lt;origin xyz="0 0 0" rpy="0 0 0"/&gt;
		&lt;parent link="base_link"/&gt;
		&lt;child link="imu_link"/&gt;
	&lt;/joint&gt;

&lt;/robot&gt;
</code></pre>
<p dir="auto">gazebo的launch文件如下：</p>
<pre><code class="language-py">from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, LaunchConfiguration
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import os


def generate_launch_description():
    use_sim_time = LaunchConfiguration("use_sim_time")
    world = LaunchConfiguration("world")
    gui = LaunchConfiguration("gui")
    verbose = LaunchConfiguration("verbose")

    # 你的 xacro
    desc_pkg = get_package_share_directory("ros_car_description")
    xacro_file = os.path.join(desc_pkg, "urdf", "ros_car.urdf.xacro")

    # Gazebo Classic 的官方 launch（来自 gazebo_ros）
    gazebo_ros_pkg = get_package_share_directory("gazebo_ros")
    gazebo_launch = os.path.join(gazebo_ros_pkg, "launch", "gazebo.launch.py")

    # 获取worlds文件夹路径
    worlds_dir = os.path.join(desc_pkg, "worlds")
    default_world = os.path.join(worlds_dir, "custom_room.world")

    # robot_description
    robot_description = Command(["xacro", " ", xacro_file])

    return LaunchDescription(
        [
            DeclareLaunchArgument("use_sim_time", default_value="true"),
            # world 参数现在默认指向 worlds 文件夹中的 custom_room.world
            DeclareLaunchArgument("world", default_value=default_world),
            DeclareLaunchArgument("gui", default_value="true"),
            DeclareLaunchArgument("verbose", default_value="false"),
            # 启动 Gazebo Classic
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource(gazebo_launch),
                launch_arguments={
                    "world": world,
                    "gui": gui,
                    "verbose": verbose,
                }.items(),
            ),
            # 发布 TF（RViz / TF 树用）
            Node(
                package="robot_state_publisher",
                executable="robot_state_publisher",
                parameters=[
                    {
                        "use_sim_time": use_sim_time,
                        "robot_description": robot_description,
                    }
                ],
                output="screen",
            ),
            # 没有 ros2_control 的情况下，让关节至少有默认 0 值（轮子连续关节不至于缺 joint_states）
            Node(
                package="joint_state_publisher",
                executable="joint_state_publisher",
                parameters=[{"use_sim_time": use_sim_time}],
                output="screen",
            ),
            # 把模型从 robot_description 生成到 Gazebo 里
            # -z 给个高度避免初始穿地（根据你模型尺寸 0.2 基本够）
            Node(
                package="gazebo_ros",
                executable="spawn_entity.py",
                arguments=[
                    "-entity",
                    "ros_car",
                    "-topic",
                    "robot_description",
                    "-x",
                    "0",
                    "-y",
                    "0",
                    "-z",
                    "0.2",
                ],
                output="screen",
            ),
        ]
    )
</code></pre>
<p dir="auto">rviz2的launch文件如下：</p>
<pre><code class="language-py">from launch import LaunchDescription
from launch.substitutions import Command
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import os


def generate_launch_description():
    pkg = get_package_share_directory("ros_car_description")
    xacro_file = os.path.join(pkg, "urdf", "ros_car.urdf.xacro")
    robot_description = {"robot_description": Command(["xacro", " ", xacro_file])}

    rviz_config = os.path.join(pkg, "config", "display_robot.rviz")

    return LaunchDescription(
        [
            Node(
                package="robot_state_publisher",
                executable="robot_state_publisher",
                parameters=[robot_description],
                output="screen",
            ),
            Node(
                package="joint_state_publisher",
                executable="joint_state_publisher",
                output="screen",
            ),
            Node(
                package="rviz2",
                executable="rviz2",
                arguments=["-d", rviz_config],
                output="screen",
            ),
        ]
    )
</code></pre>
]]></description><link>https://fishros.org.cn/forum/topic/4714/关于我自制了一个ros小车的仿真模型-gazebo车轮陷入地下</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 17:01:49 GMT</lastBuildDate><atom:link href="https://fishros.org.cn/forum/topic/4714.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Jan 2026 01:13:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 关于我自制了一个ROS小车的仿真模型，Gazebo车轮陷入地下 on Thu, 29 Jan 2026 05:38:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fishros.org.cn/forum/uid/30258">@1402485721</a> gazebo 的kp kd 太小</p>
]]></description><link>https://fishros.org.cn/forum/post/19468</link><guid isPermaLink="true">https://fishros.org.cn/forum/post/19468</guid><dc:creator><![CDATA[374200573 0]]></dc:creator><pubDate>Thu, 29 Jan 2026 05:38:48 GMT</pubDate></item></channel></rss>