What Is Hardware-in-the-Loop (HIL)? - MATLAB & Simulink

Hardware-in-the-Loop (HIL)

What Is Hardware-in-the-Loop (HIL)?

How it works, why it is important, and getting started

Hardware-in-the-loop (HIL) simulation is a technique for developing and testing embedded systems. It involves connecting the real input and output (I/O) interfaces of the controller hardware to a virtual environment that simulates the physical system. Hardware-in-the-loop testing is used for validating hardware-software integration and is part of certification processes in aerospace, automotive, and other industries. One of the key advantages of HIL simulation is that it enables early testing of control algorithms on hardware, mitigating risks and accelerating development by allowing engineers to evaluate scenarios and test I/O connectivity before all physical components are available, confirming system robustness without jeopardizing expensive equipment.

How Hardware-in-the-Loop Simulation Works

Hardware-in-the-loop simulation works by interfacing real controller hardware with a simulated physical system, known as the plant. The connections between the real controller and the simulated plant are real analog and digital I/O. They often include communication protocols such as UDP, TCP, CAN, and other industry-specific standards. Communication interfaces, with their real-world settings, timing, and wiring, are a key component of HIL testing. These aspects cannot be accurately replicated in model-in-the-loop (MIL) or software-in-the-loop (SIL) simulations.

Closed-loop control system for HIL testing showing a real controller connected to the simulated plant, which provides feedback to the controller. The test suite provides the input to the controller, and a verification element is connected at the output of the system.

In a typical hardware-in-the-loop testing setup, the real controller with real I/O interfaces is connected to the real-time system.

Steps in HIL Testing

Hardware-in-the-loop testing involves:

  1. Modeling the plant: The first step is creating a mathematical model of the physical system or plant. This model replicates the dynamics of the actual system. To model complex physical systems, including electrical and mechanical components, fluids, and thermodynamics, engineers use Simscape™ products, in conjunction with Simulink®.
  2. Real-time simulation: The plant model is then executed on a real-time test system, which simulates the plant’s behavior in response to inputs from the controller hardware. This real-time simulation verifies that the system reacts as it would in a real-world scenario. Real-time test systems are industrial computers with I/O boards to interface with the device under test; vendors of such systems include Speedgoat, dSPACE, OPAL-RT, and NI.
  3. Connecting the controller: The controller hardware, which contains the control algorithms, is connected to the real-time simulator. This connection allows the controller to interact with the virtual plant as if it were controlling the real system. Analog and digital signals, as well as communication protocols such as Ethernet, CAN, and ARINC, are used for connecting the real-time test system and the actual embedded controller. HIL testbenches might include thousands of input and output lines and emulate physical behaviors, sensors, and electric faults.
  4. Data acquisition and feedback: The system continuously acquires data from the controller and the simulated plant. This data is used to provide feedback to the controller, enabling it to adjust its actions based on the plant’s simulated responses. Real-time test systems log data that can be analyzed during and after the hardware-in-the-loop test execution.
  5. Testing and validation: Engineers can conduct a wide range of tests, from normal operating conditions to fault scenarios, to validate the controller’s performance and robustness. HIL simulation enables iterative testing and refinement, helping verify that the control algorithms meet the required specifications and standards.

Differences Between MIL, SIL, PIL, and HIL

Model-in-the-loop (MIL), software-in-the-loop (SIL), processor-in-the-loop (PIL), and hardware-in-the-loop (HIL) are key techniques used in the verification and validation process of embedded systems. Each technique serves a distinct purpose in the development cycle, with different fidelities of the simulation environment.

Model-in-the-Loop (MIL)

Model-in-the-loop is used at the initial stages of development to verify control algorithms using a high-level simulation model. This approach facilitates design and iterative testing of control logic without the need for actual hardware or software. Both the controller and the physical plants are simulated with correspondent models.

Software-in-the-Loop (SIL)

Software-in-the-loop focuses on testing the compiled control algorithm code within a simulated environment. This step verifies that the software behaves correctly when executed, providing a bridge between model simulations and real-world applications.

SIL is evolving into virtual testing, where additional controller software services are simulated. This approach can include the emulation of the entire operating system of the embedded controller and communication between multiple nodes simulating service-oriented architecture (SOA) components.

Processor-in-the-Loop (PIL)

Processor-in-the-loop involves executing the control algorithms on the actual processor or a similar target connected to the non-real-time simulated environment. This technique checks for potential issues related to code generation, execution timing, and processor-specific behavior, confirming that the software will perform as intended on the target hardware.

Hardware-in-the-Loop (HIL)

Hardware-in-the-loop is used to validate the integration of control algorithms with real hardware components. By connecting the actual controller hardware to a real-time simulated plant, HIL testing provides a high-fidelity environment to test the system under realistic conditions and scenarios.

Comparison of In-the-Loop Techniques
Technique Controller Connections Plant Related Products
MIL Simulated (model) Virtual Simulated Simulink
SIL Compiled code (software) Virtual Simulated Simulink, Simulink Coder™, Embedded Coder®
PIL Real processor TCP/IP or serial Simulated Simulink, Simulink Coder, Embedded Coder
HIL Real controller hardware Analog and digital signals Simulated in real time Simulink, Simulink Coder, Embedded Coder, Simulink Real-Time™

HIL Testing Applications

Hardware-in-the-Loop Simulation for Embedded Systems

Hardware-in-the-loop simulation plays an important role in the early development phases of embedded systems. By integrating real controller hardware with a virtual environment that simulates the physical system, HIL testing enables the validation of control algorithms and system interactions before deployment. This early validation helps engineers identify and address design issues, reducing the risk of costly revisions later in the development cycle.

One of the key advantages of HIL simulation is the ability to test control algorithms on hardware components even before the entire physical hardware is available. This is valuable for complex systems with components with long lead times, where waiting for all hardware components could delay development. HIL testing mitigates the risk of damage to expensive equipment by enabling engineers to test scenarios and edge cases in a controlled virtual environment. This approach not only accelerates development but also confirms that the system is robust and ready for real-world operation without jeopardizing valuable hardware.

Control and software engineers can use MATLAB® and Simulink to create and execute HIL simulations. Real-time applications can be generated from Simulink and deployed on the real-time test systems.

Hardware-in-the-Loop Testing for Validation and Certification

Hardware-in-the-loop testing is useful for validation and certification of safety-critical embedded systems, such as automotive and aerospace applications. Certification standards such as ISO 26262 for automotive functional safety and DO-178 for airborne systems mandate rigorous testing to verify reliable system performance under all expected conditions.

One aspect of HIL testing is its support for requirements-based testing, a key component of certification standards. This testing approach evaluates every system function against its specified requirements, providing traceability and verification of intended system behavior. Hardware-in-the-loop testing supports hardware-software integration testing, enabling engineers to validate that the control algorithms meet all defined requirements across a variety of scenarios, including fault conditions. This methodical approach not only aids in the certification process by providing documented evidence of compliance but also provides a framework for increasing dependability and safety of the final product, preparing it for deployment in challenging operational environments.

In the V diagram, the typical development workflow steps are the definition of system requirements, system and software design, coding, software integration, hardware/software integration (including HIL testing), and system integration and calibration.

Hardware-in-the-loop testing is part of the hardware/software integration step in the development workflow.

Hardware-in-the-Loop Simulation of Power Electronics Systems

Power converters and inverters contain semiconductor switching electronics driven by high-frequency pulse-width modulation (PWM) signals. Real-time simulation of these devices requires precise modeling and simulation, often running at 100 times the cycle frequency of the actual device. To simulate the characteristics of these high-frequency signals, simulation environments must be capable of executing very fast sample steps, often requiring the use of FPGA hardware to achieve the required performance.

Three analog signal plots from hardware-in-the-loop testing showing sample resolution progressing from seconds to milliseconds to microseconds.

FPGA hardware acceleration generates samples at the required resolution of ~100 times faster than the closed-loop sampling frequency (plotted with MATLAB).

Simulink and Simscape Electrical™ provide modeling libraries to simulate complex power electronics systems that capture the nuances of high-frequency operation. Simulink and Simscape Electrical generate HDL code to deploy these models onto FPGA hardware, enabling real-time simulation and testing. This direct transition from model-in-the-loop to hardware-in-the-loop enables engineers to validate the embedded software for power converter and motor inverter control.

Hardware-in-the-Loop Simulation of Electrical Power Systems

Simulating electrical power systems requires an appropriately detailed representation of the electrical network to accurately capture the interactions between various components, such as power equipment, inverters, and supervisory controller logic.

A hardware-in-the-loop testbench setup with terminals for routing cables to emulate grid networks.

Terminals for routing cables to emulate grid networks at the DLR Grid Lab.

Electromagnetic transients (EMT) can be simulated with Simscape Electrical. The same electric models can be deployed on real-time test systems for hardware-in-the-loop simulation.

The HIL testbench might require the ability to communicate with supervisory logic and controllers using industrial communication protocols such as Modbus and IEC 61850, as well as to interact with high-voltage equipment for power hardware-in-the-loop testing.

Hardware-in-the-Loop Testing of Battery Management System (BMS) Software

Battery management systems control the operation of batteries in electric vehicles, aircraft, and energy storage systems. When testing the C code for a BMS, a common approach is to use battery cell emulators as part of the hardware-in-the-loop system. Battery cell emulators drive the actual voltage and current levels experienced by battery cells and packs, facilitating the testing of BMS software for state of charge (SOC) and state of health (SOH) estimation and other BMS functions.

The use of emulated batteries with realistic power levels helps engineers test the ability of the BMS software to cope with scenarios such as over-voltage, extreme temperature, and other fault conditions. This approach enables the aspects of BMS software, including battery management, cell monitoring, and power distribution units, to be thoroughly tested and validated. Typical HIL tests include:

  • Drive cycle testing: Test the state estimation during the whole drive cycle
  • Fault conditions: Inject faults into the battery and verify that the BMS can handle the fault conditions
  • Cell balancing: Test if the balancing strategies are working effectively

Simscape Battery™ provides models of battery packs that can be included in real-time applications to perform hardware-in-the-loop testing of battery management systems.

A battery HIL testbench diagram including a real-time HIL simulator and a battery cell emulator, which is connected to the battery management system (device under test). The battery model runs on the real-time HIL simulator.

A battery HIL testbench.

Power Hardware-in-the-Loop (P-HIL)

In a typical HIL testbench, the HIL simulator interfaces with the controller hardware using low-current and low-voltage signals, typically up to 10 V. These voltage levels are generated and acquired from the I/O boards installed on the real-time system. This setup is suitable for testing control algorithms and most system behaviors. It is also called controller hardware-in-the-loop (C-HIL).

However, some devices, such as solar inverters and electric machines, may use higher voltages and currents. In that case, it may be necessary to accurately replicate real-world operating conditions. In such cases, power hardware-in-the-loop (P-HIL) testing is employed. P-HIL introduces power equipment, such as power amplifiers, to convert the low-voltage signals from the real-time system into the high voltages of the emulated device. This approach enables engineers to conduct comprehensive testing of the power components of the control system, providing a framework to test that they perform reliably under actual operating conditions.

A power HIL testbench diagram showing a real-time simulator and a power amplifier. Between the power amplifier and the device under test there is a power connection. The model of the power system runs on the real-time HIL simulator.

Power hardware-in-the-loop testbench components, including a power system model created in Simulink.

Hardware-in-the-Loop Testing of Multidomain Systems

Hardware-in-the-loop testing for multidomain systems enables engineers to validate complex interactions between different physical domains, such as mechanical, electrical, and software components, in a real environment with actual hardware.

The Simscape product family facilitates this process by helping engineers simulate multidomain system dynamic behavior, which can be integrated into HIL setups. For example, in the aerospace industry, hardware-in-the-loop testing of an aircraft’s flight control system using Simscape models enables engineers to simulate aerodynamic forces, hydraulic actuators, and electronic control responses. This process optimizes control algorithms and confirms safe operation across various flight conditions.

Multinode Hardware-in-the-Loop Simulation

In certain scenarios, hardware-in-the-loop simulation extends beyond a single control system to encompass multiple control systems or nodes. This approach involves not only simulating the plant but also incorporating real hardware that may include an entire node, comprising both the controller and the plant.

Communication between real and simulated nodes is typically achieved using industrial protocols or middleware solutions such as Data Distribution Service (DDS), Message Queuing Telemetry Transport (MQTT), and Scalable service-Oriented Middleware over IP (SOME/IP). These protocols facilitate the exchange of data and control signals. In the automotive industry, this methodology is often referred to as rest bus simulation. In rest bus simulation, one or more real electronic control units (ECUs) are connected to a HIL simulator, which emulates the “rest of the bus” and the remaining ECUs. This setup enables engineers to test and validate individual ECUs within the context of the entire vehicle network, confirming the ECUs function correctly when integrated into the larger system. By simulating the complete network environment, rest bus simulation provides a comprehensive platform for testing the interoperability and performance of automotive control systems.

Hardware-in-the-loop testing diagram showing two simulated nodes with test suite and verification elements, as well as a real node. Each node is a control system with a controller and a plant.

Multinode HIL simulation with real and simulated nodes.

HIL Testing with MATLAB and Simulink

Simulink offers an effective platform for designing and building real-time applications, making it an ideal choice for hardware-in-the-loop testing. By using Simulink, engineers can create complex models that simulate real-world conditions and test their systems in a controlled environment. Simulink simplifies the process of developing real-time applications, enabling users to visualize and adjust parameters easily, which is particularly beneficial during the design and testing phases.

Screenshot of the Simulink toolstrip highlighting the “Run on Target” button, which can be used to build the real-time application and automatically deploy to the Speedgoat system. The application starts automatically, interfacing with the device under test.

Using Simulink Real-Time, you can generate and deploy real-time applications from Simulink to Speedgoat systems with the click of a button.

Simulink Real-Time, in conjunction with Speedgoat hardware, offers a robust platform for verifying and validating embedded software. This setup enables you to connect hardware for comprehensive testing, using MATLAB scripts to control real-time HIL applications and design custom instrumentation panels with App Designer. The Simulation Data Inspector enables developers and test engineers to monitor and analyze data, ensuring they have the insights needed to make informed decisions. Additionally, you can manage real-time applications directly from the Simulink canvas, accelerating prototyping and iterative development.

Real-time applications designed with Simulink can also be executed on third-party HIL systems, such as dSPACE, OPAL-RT, and NI.

Resources

Expand your knowledge through documentation, examples, videos, and more.