RobotGuide

Engineering practice · topic F3 · 30 hours

HIL & bench testing

Full-robot testing is expensive and dangerous. HIL lets you test control logic and fault handling before the full machine exists.

Engineering stage · Hardcore
Algorithm · Aware System software · Proficient Embedded & controls · Proficient Mechanical · Aware

Tools
Tools

What to learn

  • The parts of a HIL rig: real-time simulator, I/O boards, the controller under test, fault injection
  • Test case design: three classes — normal paths, boundaries, fault injection
  • Report metrics: beyond pass rate, worst-case latency and failure modes
  • How to reproduce field problems on a bench

The lesson · plain words

HIL (hardware-in-the-loop) is «a real controller + a fake world»: the controller is real hardware, the controlled plant runs in simulation. It exposes latency, timing, and exception-handling problems without burning a real machine.

Closing the loop: a real controller against a fake world

Look at the figure: the real controller sends PWM, the simulated world computes «what would happen if the real plant received it», and feeds sensor signals back to the controller — the loop is closed. Any delay in any link of that loop eats phase margin.

Drag the latency slider: push feedback latency past 20 ms and the loop starts ringing, then diverges. This is HIL's signature test: inject latency on purpose and verify the system survives the «worst case» — an experiment you would not dare run on real hardware.

Interactive figure · drag it and see

What this figure shows: a closed loop between a real controller and a simulated plant — PWM/commands flow one way, sampled feedback returns the other with an injected-latency slider in milliseconds; the loop state reads stable, marginal (ringing), or diverging as latency grows. Takeaway: latency injection is the HIL signature test — add delay on purpose and see whether the system survives its worst case.

The ladder: SIL, HIL, real robot

SIL (software-in-the-loop): the controller is also code, an all-software environment — it tests algorithm logic. HIL: the controller is real hardware — it tests timing, drivers, interfaces. Real robot: everything real — it tests calibration and performance. Three rungs with rising cost; the earlier a problem is found, the cheaper.

The engineering rhythm: algorithms converge in SIL → HIL verifies timing and exceptions → the real robot does only final calibration and acceptance. Time saved by skipping rungs comes back tenfold at the hardware stage.

Bench build essentials

The simulated world must run on a real-time system (not your laptop): RT Linux or a dedicated real-time machine, otherwise the 1 kHz loop beat never lands. The interface must be real: the controller's PWM / bus signals connect into the real-time machine's I/O — digital signals in and out is HIL's proper job.

The fault-injection checklist: sensor disconnection (constant output / NaN), bus packet loss, sudden latency spikes, load steps. Every fault needs an «expected behavior» written as a script — HIL's high value is running these dangerous scenarios automatically.

How deep to go

You can build a minimal loop of «real controller + real-time simulator»; explain how latency erodes stability (phase margin); and design plus automate a fault-injection checklist. These three are the shared language of control engineers and systems integration engineers.

Three questions — do you really get it?

1. What is the difference between HIL and SIL?

  • ANo difference
  • BHIL uses a real controlled plant
  • CHIL uses real controller hardware; SIL is all software
Show answer

C. The «H» in HIL is hardware: controller real, world fake. Only then can real timing problems surface.

2. What is deliberately increasing the feedback latency in HIL actually testing?

  • ASimulation accuracy
  • BThe system's tolerance to latency and worst-case stability
  • CRendering performance
Show answer

B. Latency eats phase margin. Injecting latency proves «alive even at worst»; doing this experiment on hardware is dangerous.

3. Where should the HIL simulated world run?

  • AA real-time system (RT Linux / real-time machine) that guarantees the loop beat
  • BAn ordinary laptop
  • CA cloud virtual machine
Show answer

A. The 1 kHz beat must land on time. Jitter on a non-real-time system turns the «fake world» into a noise source.

Keep going deeper

Links without a marker stay on this site; the rest point to the Chinese edition until its translation batch lands.

How it fails in the field

  • The bench only tests the normal path; not a single field problem can be reproduced on it
  • No fault injection, and the first encoder disconnection happens at the customer's site

You have learned enough when

You can build a minimal HIL setup (even just an MCU + a simulation model) and run through three fault-injection cases.

The Chinese edition carries the full topic page for HIL & bench testing, including the complete outline, depth requirements per career track, and further derivations: robotguide.dev/k/F3/.