# 硬件在环仿真

**硬件在环仿真**（Hardware-in-the-loop simulation，简称HIL，亦称HWIL或HiL）是一种实时测试技术，将物理控制器（如嵌入式控制单元）通过其真实的输入输出接口连接到实时仿真器上，由仿真器对被控对象——即控制器所要操作的物理系统——进行建模。控制器接收仿真的传感器信号并返回执行器指令，形成一个闭环，使真实硬件的行为如同安装在真实机器中一样。<sup>[1](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)</sup><sup> • </sup><sup>[2](https://doi.org/10.3390/electronics11152462)</sup>

| 关键事实 | 详情 |
|---|---|
| 何为真实，何为仿真 | 控制器硬件及其软件是真实的；被控对象及其传感器和负载则通过实时仿真，经由真实的模拟与数字I/O及通信总线连接。<sup>[1](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)</sup> |
| 在开发流程中的位置 | HIL测试是V模型开发工作流中的硬件/软件集成步骤，位于编码和软件集成之后、完整系统集成与标定之前。<sup>[1](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)</sup> |
| 电力电子的速度要求 | 电机HIL仿真必须以约1微秒量级执行模型；25微秒步长对8 kHz PWM信号的响应会产生高达20%的相对误差，而1微秒步长可将误差降至0.75%。<sup>[3](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hil-testing-for-power-electronics-systems.html)</sup> |
| 核心系统要素 | 被测设备、I/O与总线接口、用于模型执行的确定性实时计算、仿真模型，以及用于配置、执行和分析测试的应用软件。<sup>[4](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hardware-in-the-loop--hil--test-system-architectures.html)</sup> |
| 主要优势 | 成本效益、快速原型、可重复性与稳定性、无损测试、安全性、参数研究、并行工程和自动化测试。<sup>[2](https://doi.org/10.3390/electronics11152462)</sup> |
| 主要不足 | 缺乏标准方案且集成缓慢；仿真器作为黑箱运行，无法直接获取被测系统的内部状态信息；准备故障和异常工况测试场景往往比运行测试本身更耗时。<sup>[2](https://doi.org/10.3390/electronics11152462)</sup> |
| 标准化 | IEEE 2004-2025《基于HIL仿真的电力设备与控制测试推荐实践》于2025年8月29日发布，提供了稳定性、精度和灵敏度评估框架。<sup>[5](https://standards.ieee.org/ieee/2004/11300/)</sup> |

## 工作原理

HIL装置将物理控制器——即被测设备（DUT）——与运行被控对象数学模型的实时计算机配对。连接方式是控制器实际的模拟与数字信号，通常辅以CAN、UDP、TCP及行业专用标准等通信协议。由于接线、时序和信号电平都是真实的，纯仿真环境中无法复现的接口特性得以像在现场一样被检验。<sup>[1](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)</sup>

**实时执行是决定性约束。** 被控对象模型必须以与物理世界相同的节奏推进，在每个时间步内读取控制器的输出并更新仿真传感器值，且延迟和抖动极小。如果模型运行慢于实时，闭环就不再代表物理系统。这一要求决定了硬件形态：基于处理器的仿真器受限于处理器与I/O之间的通信总线，因此高速应用将模型迁移到FPGA（可重构芯片，支持微秒级快速仿真）上，将处理节点和I/O节点共置于单一器件可使通信延迟降至可忽略的水平。<sup>[3](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hil-testing-for-power-electronics-systems.html)</sup><sup> • </sup><sup>[4](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hardware-in-the-loop--hil--test-system-architectures.html)</sup>

典型的测试台还包括信号调理、传感器与负载仿真、能够断开电路或注入错误信号的故障插入单元，以及测试自动化软件——后者运行测试用例并记录结果，以便日后审查而无需重复测量。<sup>[2](https://doi.org/10.3390/electronics11152462)</sup><sup> • </sup><sup>[4](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hardware-in-the-loop--hil--test-system-architectures.html)</sup>

## 与MIL、SIL和PIL测试的关系

HIL是“X在环”验证技术家族中的一员，这些技术的区别在于系统中真实部分的比例不同。在模型在环（MIL）测试中，控制器和被控对象均以高层次模型进行仿真，支持控制逻辑的早期设计。在软件在环（SIL）测试中，编译后的控制代码在开发计算机上的仿真环境中运行，验证软件执行时行为是否正确。处理器在环（PIL）测试在实际目标处理器或等效处理器上执行代码，连接到非实时仿真环境，可暴露代码生成、时序和处理器特有问题。HIL则更进一步，使用完整的控制器硬件及真实I/O连接实时仿真的被控对象，在四者中为硬件-软件集成提供最高的保真度。<sup>[1](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)</sup>

这一递进关系具有实际意义：一次构建的单一被控对象模型可以先后复用于SIL仿真、HIL测试，最终与物理系统的现场数据对比，使团队能够早期基于虚拟表征验证控制逻辑，并将物理硬件测试推迟到后期阶段。<sup>[4](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hardware-in-the-loop--hil--test-system-architectures.html)</sup>

## 应用

HIL仿真适用于嵌入式控制器需要针对昂贵、危险或不可获取的物理系统进行验证的所有场合。有文献记载的应用领域包括汽车与过程控制系统、医疗器械、工业机械、发电系统、家用电器、航空航天电力系统和航空电子设备。<sup>[6](https://doi.org/10.1201/b10605-38)</sup>

**汽车。** HIL已成为原始设备制造商和供应商电子控制单元（ECU）软件开发中不可或缺的环节，在许多公司中，成功的HIL测试是系统批准的前提条件。<sup>[7](https://onlinelibrary.wiley.com/doi/abs/10.1002/9781118354179.auto193)</sup> 一个典型例子是让[发动机控制单元](https://www.edgepedia.org/zh/engine-control-unit)针对仿真的发动机和车辆进行测试，从而无需多次制造整车或在实验室中复现极端条件即可验证ECU。<sup>[8](https://www.ni.com/docs/en-US/bundle/labview-control-design-and-simulation-module/page/lvsimconcepts/sim_c_config.html)</sup> HIL平台还支持实时故障注入，[ISO 26262](https://www.edgepedia.org/zh/iso-26262)汽车功能安全标准强烈推荐将其作为评估故障影响的测试方法；HIL仿真广泛用于汽车、铁路和航空航天行业实时嵌入式系统的验证与确认。<sup>[9](https://www.mdpi.com/1424-8220/22/4/1360)</sup>

**电力电子与电驱动。** 电机控制器以高PWM频率开关，因此被控对象模型必须以微秒级时间步长运行，通常在FPGA硬件上执行。高保真仿真使工程师能够测试在真实硬件上具有破坏性或不切实际的瞬态和故障工况，如超速或馈线故障，并减少对昂贵的测功机或现场测试的依赖。<sup>[3](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hil-testing-for-power-electronics-systems.html)</sup><sup> • </sup><sup>[10](https://www.sciencedirect.com/topics/computer-science/hardware-in-the-loop)</sup>

**电力系统与功率HIL。** 在功率硬件在环（PHIL）仿真中，仿真电网通过功率放大器与真实物理电力设备连接，使被测硬件能够在实际功率条件下接受测试。闭环稳定性和仿真精度是运行安全的两个核心问题，接口算法的选择对二者均有可测量的影响；基于系统环路传递函数的稳定性分析用于选择合适的算法。<sup>[11](https://ieeexplore.ieee.org/document/4578805/)</sup> HIL技术还用于验证可再生能源及其在网络物理能源系统中的交互，在这些场景中，仅测试单个设备而大幅简化系统其余部分已不再足够。<sup>[12](https://arxiv.org/abs/1710.02306)</sup>

**认证与研究。** HIL测试支持基于需求的测试——这是ISO 26262汽车功能安全和DO-178机载系统等认证标准的关键组成部分——通过对照规定需求（包括故障条件）评估每个系统功能，并提供合规的文件化证据。<sup>[1](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)</sup> 研究实验室利用HIL环境弥合仿真与全尺寸部件测试之间的差距；例如，美国国家航空航天局（NASA）格伦研究中心的混合推进仿真装置提供小规模HIL环境，以低成本、低风险测试电气化飞机推进控制技术。<sup>[13](https://www.nasa.gov/eap-labs-and-testbeds/hyper/)</sup>

## 优势与局限

HIL测试的优势源于将真实硬件与可控虚拟环境相结合。危险或破坏性场景——如故障、超速和边缘工况——可以安全且可重复地执行；温度和湿度等环境变化不影响结果，因此回归测试可以验证软件更改不会引入新问题。在真实系统上触发特定错误十分困难，而HIL测试台可以按需复现，且录制的测试可在日后审查和评估而无需额外测量。<sup>[2](https://doi.org/10.3390/electronics11152462)</sup><sup> • </sup><sup>[14](https://www.electronicsguide.net/systems-and-technologies/embedded-systems/development-tools-and-methodologies/hardware-in-the-loop-testing/)</sup>

局限性同样具体。仿真的精度取决于模型，真实系统中未建模的效应可能无法被检测到；模型验证需要与物理系统对比，而物理系统在开发早期可能尚不可用。HIL基础设施需要在实时计算机、信号调理和测试自动化方面大量投资，还需要持续的维护和模型开发专业知识。<sup>[14](https://www.electronicsguide.net/systems-and-technologies/embedded-systems/development-tools-and-methodologies/hardware-in-the-loop-testing/)</sup> HIL仿真器充当嵌入式系统的黑箱测试器：它只读取系统的输出，因此当嵌入式软件行为异常时，这些输出中可能（也可能不）包含足够信息来确定软件正在执行哪部分或内部变量持有什么值。准备异常和故障工况的测试场景——调校从模型到实时信号执行的整条链路——往往比测试执行本身更耗时，且随着模型和集成工具日益复杂，上传到执行硬件的时间也在延长。<sup>[2](https://doi.org/10.3390/electronics11152462)</sup>

## 标准化与当前实践

该领域已从临时实践走向正式指南。IEEE 2004-2025《基于HIL仿真的电力设备与控制测试推荐实践》为设计、建立和执行实时HIL装置提供了建议，并附有稳定性、精度和灵敏度评估的分析框架及实验案例研究；该标准由IEEE电力电子学会制定，于2025年8月29日发布。<sup>[5](https://standards.ieee.org/ieee/2004/11300/)</sup> 在道路车辆领域，ISO/PAS 34506涉及自动驾驶系统虚拟测试环境的鉴定，涵盖模型在环和软件在环方法，并延伸至硬件在环和车辆在环测试等混合技术。<sup>[15](https://www.iso.org/standard/89865.html?browse=tc)</sup> 各大学也在将HIL概念纳入工程学课程，该方法已成为支持各行业开发活动的最先进实践。<sup>[2](https://doi.org/10.3390/electronics11152462)</sup>

## References

1. [What Is Hardware-in-the-Loop (HIL)?, MathWorks](https://www.mathworks.com/discovery/hardware-in-the-loop-hil.html)
2. [Hardware-in-the-Loop Simulations: A Historical Overview of Engineering Challenges, Electronics 11(15):2462, MDPI (2022)](https://doi.org/10.3390/electronics11152462)
3. [HIL Testing for Power Electronics Systems, NI](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hil-testing-for-power-electronics-systems.html)
4. [The NI Hardware-in-the-Loop (HIL) Test System Architecture, NI](https://www.ni.com/en/solutions/transportation/hardware-in-the-loop/hardware-in-the-loop--hil--test-system-architectures.html)
5. [IEEE 2004-2025: IEEE Recommended Practice for Hardware-in-the-Loop (HIL) Simulation-Based Testing of Electric Power Apparatus and Controls, IEEE SA](https://standards.ieee.org/ieee/2004/11300/)
6. [Hardware-in-the-Loop Simulation (2015), R. T. Ogan](https://doi.org/10.1201/b10605-38)
7. [Hardware-in-the-Loop Simulation, Köhl, Wiley Major Reference Works](https://onlinelibrary.wiley.com/doi/abs/10.1002/9781118354179.auto193)
8. [Offline, RCP, and HIL Configurations, LabVIEW Control Design and Simulation Module, NI](https://www.ni.com/docs/en-US/bundle/labview-control-design-and-simulation-module/page/lvsimconcepts/sim_c_config.html)
9. [Hardware-in-the-Loop-Based Real-Time Fault Injection Framework for Dynamic Behavior Analysis of Automotive Software Systems, Sensors 22(4):1360, MDPI (2022)](https://www.mdpi.com/1424-8220/22/4/1360)
10. [Hardware-in-the-Loop, ScienceDirect Topics overview](https://www.sciencedirect.com/topics/computer-science/hardware-in-the-loop)
11. [Improve the Stability and the Accuracy of Power Hardware-in-the-Loop Simulation by Selecting Appropriate Interface Algorithms, IEEE Transactions on Industry Applications 44(4) (2008)](https://ieeexplore.ieee.org/document/4578805/)
12. [Real-Time Simulation and Hardware-in-the-Loop Approaches for Integrating Renewable Energy Sources into Smart Grids, arXiv:1710.02306](https://arxiv.org/abs/1710.02306)
13. [Hybrid Propulsion Emulation Rig (HyPER), NASA Glenn Research Center](https://www.nasa.gov/eap-labs-and-testbeds/hyper/)
14. [Hardware-in-the-Loop Testing, Electronics Guide](https://www.electronicsguide.net/systems-and-technologies/embedded-systems/development-tools-and-methodologies/hardware-in-the-loop-testing/)
15. [ISO/PAS 34506: Road vehicles — Test scenarios for automated driving systems — Qualification of virtual test environments, ISO](https://www.iso.org/standard/89865.html?browse=tc)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Embedded & soft processors › Embedded systems › Embedded testing, debugging, and verification

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/hardware-in-the-loop-simulation

English original: https://www.edgepedia.org/hardware-in-the-loop-simulation
