# 仿真描述格式

**仿真描述格式**（Simulation Description Format，SDFormat，常缩写为SDF）是一种XML文件格式，用于为机器人仿真器、可视化和控制描述对象与环境。它最初是作为Gazebo机器人仿真器的一部分开发的，面向科学机器人应用而设计；随着时间推移，它已发展成为一种可扩展的格式，能够描述机器人、静态与动态对象、光照、地形乃至物理本身。<sup>[1](https://sdformat.org/)</sup>

| 关键事实 | 详情 |
|---|---|
| 它是什么 | 一种XML格式，用于为机器人仿真器、可视化和控制描述对象与环境；最初作为Gazebo的一部分开发<sup>[1](https://sdformat.org/)</sup> |
| 顶层元素 | `<sdf>`根元素可包含一个模型、actor、光源，或一个或多个世界；规范版本在`version`属性中声明<sup>[2](https://sdformat.org/spec/1.12/)</sup> |
| 位姿语法 | `<pose>x y z roll pitch yaw</pose>`，等价于URDF的`<origin rpy='roll pitch yaw' xyz='x y z'/>`<sup>[3](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.5/)</sup> |
| 框架语义 | SDFormat 1.5为`<pose>`和`<frame>`元素新增了`frame`属性；位姿框架语义提案在SDFormat 1.7（libsdformat 9.x）中实现<sup>[3](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.5/)</sup> |
| 与URDF的互操作 | Gazebo加载URDF文件时，首先将其转换为SDFormat；URDF文件中的`<gazebo>`标签用于注入SDFormat特有的内容<sup>[4](https://sdformat.org/tutorials/specification/sdformat_urdf_extensions/)</sup> |
| 当前版本 | libsdformat 16.0.0，发布于2025年9月30日<sup>[5](https://sdformat.org/download/)</sup> |
| 许可证 | 以Apache 2.0开源<sup>[1](https://sdformat.org/)</sup> |

## 目的与范围

SDFormat在多个细节层次上描述机器人。对于机器人——无论是简单的轮式底盘还是人形机器人——该格式涵盖运动学与动力学属性，以及传感器、表面属性、纹理、关节摩擦和其他属性，因此同一个文件可服务于仿真、可视化、运动规划和机器人控制。<sup>[1](https://sdformat.org/)</sup>

对于环境，SDFormat定义的世界可包含多个模型、多个光源、地形（虚构的或基于数字高程模型的）、源自[OpenStreetMap](https://www.edgepedia.org/zh/openstreetmap)的街道，以及来自The Prop Shop等模型仓库的模型。<sup>[1](https://sdformat.org/)</sup> 世界文件以带版本号的`<sdf>`元素和`<world>`元素开头；其中的`<physics>`元素设定物理引擎类型及`<max_step_size>`、`<real_time_factor>`等属性。<sup>[6](https://gazebosim.org/docs/dome/sdf_worlds/)</sup>

## 文件的结构

该规范围绕一棵元素树组织：`Sdf`、`World`、`Scene`、`State`、`Physics`、`Light`、`Actor`、`Model`、`Link`、`Sensor`、`Joint`、`Collision`、`Visual`、`Material`和`Geometry`。<sup>[2](https://sdformat.org/spec/1.12/)</sup> 一个SDFormat文件可以只由一个模型构成，而一个世界可以包含许多模型；`<model>`元素定义一个完整的机器人或任何其他物理对象。<sup>[7](https://sdformat.org/spec/1.12/model/)</sup>

**模型与连杆。** 模型带有一个`name`，它必须在同一作用域内所有定义框架的元素中唯一，也就是说，不能与该作用域内另一个模型、框架、关节或连杆重名。`canonical_link`属性指定模型的隐式坐标框架所依附的连杆；若未设置，则选择作为模型直接子元素列出的第一个连杆。将`<static>`元素设为true可使模型不可移动，动力学引擎便不会更新其位置。<sup>[7](https://sdformat.org/spec/1.12/model/)</sup>

**组合。** `<include>`元素通过引用指向目录或文件的URI来嵌套模型；被包含的资源只能含有一个模型元素。可选的`merge`属性将被包含的嵌套模型合并到顶层模型中，`<name>`、`<static>`和`<placement_frame>`元素则可覆盖被包含模型的属性。<sup>[7](https://sdformat.org/spec/1.12/model/)</sup>

**插件。** `<plugin>`元素是一段动态加载的代码，可作为世界、模型和传感器元素的子元素存在；其`filename`属性指定要加载的共享库，它接受任意子元素用于配置。<sup>[7](https://sdformat.org/spec/1.12/model/)</sup>

## 位姿与框架

`<pose>`元素表示一个平移和旋转，默认写作六个值`x y z roll pitch yaw`。`rotation_format`属性还接受`quat_xyzw`，即七值四元数形式，而`degrees`属性可将[欧拉角](https://www.edgepedia.org/zh/euler-angles)从弧度切换为角度。<sup>[7](https://sdformat.org/spec/1.12/model/)</sup> 此语法直接对应URDF的`<origin>`标签，后者使用相同的滚转、俯仰、偏航角定义。<sup>[8](https://sdformat.org/tutorials/specification/specify_pose/)</sup>

框架语义随规范版本而变。在1.4及更早版本中，`<pose>`表示一个框架与其父框架之间的相对变换，其中连杆框架相对于模型框架定义，关节框架相对于其子连杆框架定义。1.5版为`<pose>`元素新增了`frame`属性字符串，允许相对于任意命名框架定义位姿，并新增了`<frame>`元素，用于在既有连杆和关节框架之外定义命名坐标框架。<sup>[3](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.5/)</sup> 为此行为提出的重新设计语义在SDFormat 1.7中实现，随libsdformat 9.x发布。<sup>[3](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.5/)</sup> 在1.7中，空的`//pose`被视为恒等变换，因此`<pose relative_to="tip"/>`可将实体与`tip`框架置于同一位置。<sup>[9](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.7/)</sup>

`relative_to`属性指明表达位姿所用的参考框架；若缺省，则位姿在父XML元素的框架中表达。从1.8版起，`relative_to`可用`::`作为分隔符引用嵌套作用域的框架，例如`nested_model_A::nested_model_B::awesome_frame`。<sup>[7](https://sdformat.org/spec/1.12/model/)</sup>

## 与URDF的关系

URDF，即统一机器人描述格式（Unified Robot Description Format），仍是常见的机器人描述格式，但两种格式在结构上有所不同。URDF用`<origin>`属性而非`<pose>`值来表达坐标变换，且URDF的连杆和机器人本身没有`<origin>`标签。<sup>[3](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.5/)</sup>

当Gazebo——无论是Gazebo-classic还是较新的Gazebo——加载URDF文件时，内容会先转换为SDFormat再进行处理。用户可在原始URDF文件中放置`<gazebo>`标签来修改转换得到的SDFormat输出；这被称为URDF规范的Gazebo扩展。不带`reference`属性的`<gazebo>`标签作用于生成的SDFormat `<model>`，其所有子元素被插入该模型；带`reference`属性的标签则作用于指定名称的连杆。`<visual>`和`<collision>`扩展标签在转换过程中更新既有的visual和collision，而非插入新的，并且它们会影响所引用连杆中的所有visual或collision。<sup>[4](https://sdformat.org/tutorials/specification/sdformat_urdf_extensions/)</sup>

由于转换通常自动发生、用户看不到SDFormat结果，命令`gz sdf -p <urdf文件路径>`可将URDF文件转换为SDFormat，以便检查并诊断转换问题。<sup>[4](https://sdformat.org/tutorials/specification/sdformat_urdf_extensions/)</sup>

**固定关节合并。** 在URDF向SDFormat转换期间，固定关节合并（fixed joint lumping，亦称关节归约）会取固定关节的子连杆，将其全部内容合并进父连杆。这一优化通过减少仿真模型所需的约束数量，使最大坐标物理引擎受益。在此过程中，两连杆的合计质量保持不变，并计算所得连杆的质心和转动惯量；属于子连杆的每个visual和collision元素都以适当的位姿偏移重新安置到父连杆，而固定关节本身则被丢弃。自libsdformat 9.9.0起，会为被丢弃的关节和子连杆生成`frame`元素，以保留其位姿信息。<sup>[4](https://sdformat.org/tutorials/specification/sdformat_urdf_extensions/)</sup>

合并默认启用，但可通过将`preserveFixedJoint`或`disableFixedJointLumping`设为true来禁用。两个参数行为相似，但`preserveFixedJoint=true`产生一个`fixed`类型的关节，而`disableFixedJointLumping=true`产生一个位置限位设为0的转动关节。<sup>[4](https://sdformat.org/tutorials/specification/sdformat_urdf_extensions/)</sup>

## 版本与发布

规范版本号与libsdformat发布版本号不同，后者包含C++解析库；路线图文档将规范版本映射到libsdformat版本。<sup>[2](https://sdformat.org/spec/1.12/)</sup> 例如，libsdformat12用于Gazebo Fortress，而SDFormat 13对应Garden发布版。<sup>[10](https://sdformat.org/tutorials/developers/roadmap/)</sup> 发布历史从libsdformat 1.4.9（2014年7月）延续至16.0.0（2025年9月30日），其间有9.x（2019年至2022年）、12.x（2021年至2023年）和13.x（2022年起）等系列。<sup>[5](https://sdformat.org/download/)</sup>

Gazebo-classic和较新的Gazebo（原名Ignition）均以SDFormat作为其世界描述格式，因此在一个中可用的世界和模型可以移植到另一个。<sup>[11](https://classic.gazebosim.org/)</sup> Gazebo classic已于2025年1月停止维护，鼓励用户迁移到新的Gazebo。<sup>[12](https://get.gazebosim.org/distributions/sdformat/releases/)</sup>

## References

1. [SDFormat Specification, sdformat.org](https://sdformat.org/)
2. [SDFormat Specification 1.12, sdformat.org](https://sdformat.org/spec/1.12/)
3. [Pose frame semantics (1.5), SDFormat Documentation](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.5/)
4. [SDFormat extensions to URDF (the gazebo tag), SDFormat Documentation](https://sdformat.org/tutorials/specification/sdformat_urdf_extensions/)
5. [libsdformat Download, sdformat.org](https://sdformat.org/download/)
6. [SDF worlds, Gazebo dome documentation](https://gazebosim.org/docs/dome/sdf_worlds/)
7. [SDFormat Specification 1.12: Model, sdformat.org](https://sdformat.org/spec/1.12/model/)
8. [Specifying pose, SDFormat Documentation](https://sdformat.org/tutorials/specification/specify_pose/)
9. [Pose frame semantics (1.7), SDFormat Documentation](https://sdformat.org/tutorials/specification/pose_frame_semantics/1.7/)
10. [Roadmap, SDFormat Documentation](https://sdformat.org/tutorials/developers/roadmap/)
11. [Gazebo classic](https://classic.gazebosim.org/)
12. [Gazebo Distributions, get.gazebosim.org](https://get.gazebosim.org/distributions/sdformat/releases/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 工程与制造 › 机器人技术与自动化 › Robot software, AI, and methods › Simulation, physics engines, and digital twins

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/simulation-description-format

English original: https://www.edgepedia.org/simulation-description-format
