Professional Documents
Culture Documents
JIM A. LEDIN
f e a t u r e
Hardware-in-the-Loop
Simulation
Hardware-in-the-loop (HIL) simulation is a technique for performing system-level testing of embedded systems
in a comprehensive, cost-effective, and repeatable manner. This article provides an overview of the techniques of
HIL simulation, along with hardware and software requirements, implementation methods, algorithms, and rules
of thumb.
S
ystem level testing is one of the major expenses for performing system-level testing of embedded systems in
in developing a complex product that incorpo- a comprehensive, cost effective, and repeatable manner.
rates embedded computing. The need to mini- HIL simulation is most often used in the development and
mize time to market while simultaneously pro- testing of embedded systems, when those systems cannot be
ducing a thoroughly tested product presents tested easily, thoroughly, and repeatably in their opera-
tremendous challenges. Increasing levels of com- tional environments.
plexity in system hardware and software are making this HIL simulation requires the development of a real-time
problem more severe with each new generation of prod- simulation that models some parts of the embedded system
ucts. Additionally, any significant changes made to an exist- under test (SUT) and all significant interactions with its
ing product’s hardware or software must be thoroughly operational environment. The simulation monitors the
regression-tested to confirm that the changes do not pro- SUT’s output signals and injects synthetically generated
duce unintended effects. input signals into the SUT at appropriate points. Output
Embedded computing is becoming more pervasive in signals from the SUT typically include actuator commands
systems that are safety-critical, which makes the need for and operator display information. Inputs to the SUT might
thorough testing even more acute. Clearly, there is an include sensor signals and commands from an operator.
urgent need to accelerate and automate system-level testing The outputs from the embedded system serve as inputs to
as much as possible within the constraints of test system cost the simulation and the simulation generates outputs that
and development effort. become inputs to the embedded system. Figure 1 shows a
Hardware-in-the-loop (HIL) simulation is a technique high-level view of an example HIL simulation.
In the figure, the SUT is represent- product development phase, HIL sim- ment. This step can be performed
ed as having interfaces to sensors and ulation is a valuable tool for perform- before a prototype of the SUT has
actuators, as well as an operator inter- ing design optimization and hard- even been developed. Verification is
face that displays information and ware/software debugging. typically performed by comparing HIL
accepts command inputs. In this However, for an HIL simulation (or simulation results with the results of
example, operator commands are syn- any simulation, for that matter) to pro- analytical calculations or results from
thetically generated by the simulation duce reliable outputs, it is critical to independently developed simulations
to stimulate the SUT during testing. demonstrate that the simulated envi- of the SUT. Other techniques such as
The use of synthetically generated ronment is an adequate representa- source code peer reviews can be effec-
operator commands allows the tion of reality. This is where the con- tive verification tools.
automation of test sequences and per- cepts of simulation verification and Validation consists of demonstrat-
mits precise repeatability of tests. It validation must come into play. ing that the HIL simulation models
may also be possible to run the simu-
lation in a mode in which humans
observe the operator displays and gen- FIGURE 1 Example HIL simulation
erate inputs. This mode may be valu-
able for usability testing and operator
training, but the ability to precisely
Embedded
repeat test sequences is lost. System
You can apply the HIL simulation (SUT)
test concept to a wide variety of sys-
tems, from relatively simple devices Sensor input signals Actuator control signals
Operator commands Operator displays
such as a room temperature controller
to complex systems like an aircraft
flight control system. HIL simulation Real-Time
has historically been used in the devel- Simulation
opment and testing of complex and
costly systems such as military tactical
missiles, aircraft flight control systems,
satellite control systems, and nuclear
reactor controllers. Simulation verification and the embedded system and the real
Ongoing performance advances validation world operational environment with
and price reductions in computer Before the HIL simulation can be acceptable accuracy. A standard
hardware have made it possible to used to produce useful results, there approach to validation is to use the
develop cost-effective HIL simulations must first be a demonstration that the results of system operational tests for
for a much wider range of products. SUT and its simulated environment in comparison against simulation results.
This article is intended to promote the the HIL simulation sufficiently repre- This type of validation test involves
application of HIL simulation to areas sent the operational system and envi- running the embedded system in the
where this technique may not have ronment. The major steps in the HIL simulation through a test sce-
been used in the past. process of demonstrating and docu- nario that is identical to one that was
HIL simulation can help you to menting that the correctness and performed by an actual system in an
develop products more quickly and fidelity of the simulation are adequate operational environment. The results
cost effectively with improved test are called verification and validation. of the two tests are compared and any
thoroughness. Another benefit of HIL Verification is the process of differences are analyzed to determine
simulation is that it significantly demonstrating that the HIL simula- if they represent a significant devia-
BEN FISHMAN
reduces the possibility of serious prob- tion contains an accurate implementa- tion between the simulation and the
lems being discovered after a product tion of the conceptual mathematical real world.
has gone into production. During the models of the SUT and its environ- If the operational test results don’t
Simulation computer
hardware
In addition to the SUT, the hardware
used in an HIL simulation must
include:
In an HIL simulation, an I/O device overly complex, an ordinary PC run- low I/O rate HIL simulation. This
must be installed in the simulation ning a non real-time operating system condition may necessitate the use of
computer that connects to each SUT such as Windows NT may be capable an RTOS or a dedicated real-time soft-
I/O port of interest. I/O interfaces of running a valid and useful HIL sim- ware environment on the simulation
are available from several sources that ulation. For complex, high I/O rate computer.
support signal types, such as: SUTs, a high-performance computer A summary of requirements for a
system is essential. In these applica- high-performance real-time simula-
• Analog (DACs and ADCs) tions, you’ll need more than just raw tion computer system includes:
• Discrete digital (for example, TTL CPU speed. The simulation computer
or differential) must also have well-defined and • High-performance CPUs
• Serial (for example, RS-232 or RS- repeatable real-time performance • Support for real-time operations
422) characteristics. A high-performance • High data transfer rates
• Real-time data bus (for example, simulation might require that the soft- • Support for a variety of I/O devices
MIL-STD-1553, CAN, or ARINC- ware update all the simulation models
429) and perform I/O at precise intervals In years past, these requirements
• Instrumentation bus (IEEE-488, for of a few hundred microseconds. were met by specially designed,
example) The simulation computer must extremely expensive simulation com-
• Network (Ethernet, for example) provide system-level software that sup- puters. While more recently, many
• Device simulators (for simulating ports real-time computing and doesn’t HIL simulation developers have
LVDT transducers, thermocouples, allow code execution to be blocked in turned to the VME bus as the basis for
and the like) inappropriate ways. Most general-pur- their simulation computer systems. In
pose operating systems don’t provide the future, newer buses such as
For an SUT with low I/O rates and sufficient support of real-time features CompactPCI may provide a lower cost
a simulated environment that isn’t to be useful in anything other than a foundation for developers of real-time
simulations.
Simulation software
structure
The simulation software contains sec-
tions of code that perform the tasks
needed during real-time simulation. A
diagram of the basic software flow of
an HIL simulation is shown in Figure
2.
As examination of the flow diagram
reveals, the HIL simulation software
can be separated into three basic
parts:
must be short enough to maintain sim- In this formula, ts is the shortest Faster frame rate models that use
ulation model accuracy and numerical time constant in seconds of the simu- values computed by slower models
stability. At the same time, it must be lated dynamic system and h is the may need to use interpolation or
long enough to tolerate the worst-case frame time in seconds. As h is extrapolation techniques to compute
time to complete all the calculations increased above the range given by the input values appropriate for the cur-
and I/O operations in the dynamic formula, the accuracy of the simula- rent time. State variables in a slow
loop. A shorter frame time require- tion will begin to suffer and eventually frame are suitable for interpolation,
ment implies higher performance it will become numerically unstable. and algebraic variables must be
requirements for the simulation com- extrapolated. The interpolation or
puter hardware. Alternatively, a short- Multiframing extrapolation may be done using
er frame time may require simplifica- Some subsystems modeled in a simula- methods of first or higher order.
tion of the simulation models so that tion may have time constants that vary If the simulation computer sup-
their calculations can complete in the significantly from those of other sub- ports multithreading, a scheduling
available time. As the frame time is systems. When this occurs, improving technique such as Rate Monotonic
lengthened, simulation accuracy simulation performance is possible by Scheduling can manage the execution
degrades. At a certain point, the using the technique of multiframing. of the models and their I/O opera-
numerical integration algorithm A multiframe simulation has more tions at the different frame rates (see
becomes unstable. The following for- than one frame rate. The frame times the sidebar on Rate Monotonic
mula is a rule of thumb for determin- h1, h2, and so forth are generally set at Scheduling). Appropriate inter-thread
ing the longest acceptable frame time integer multiples of a common factor, communication techniques must be
for a simulation model: with the fastest frame time called hf. used to allow data to be passed among
The simulation updates each model at the models in a controlled manner. A
ts the times appropriate for that model’s multiframe simulation can provide
h£
20 frame rate. comparable accuracy to a single frame
rate simulation that updates all its
models at the hf rate while requiring
far less CPU power.
Simulation programming
languages and environ-
ments
Over the years, a number of special-
ized programming languages and
environments have been developed to
ease the task of developing simula-
tions of dynamic systems. Some simu-
lation languages are text-based while
other development environments are
graphical. Graphical tools allow the
user to construct diagrams describing
the system to be simulated. Many of
these tools are intended for use only
in non real-time applications, and
therefore aren’t suitable for develop-
ing HIL simulations. In addition,
many of these languages and tools are
either proprietary or are supported by
only a single company.
Common attributes of full-featured
dynamic simulation languages and
graphical development environments
include:
• Support for multidimensional • Perform simulation runs ical integration, interpolation func-
interpolation functions • Collect and store simulation data tion generation, coordinate transfor-
• Support for matrix and vector data • Analyze, display, and print simula- mation, and so forth.
types and mathematical operations tion results
• A library of simulation component • Debug and optimize the simulation Developing simulation
models such as transfer functions, models
limiters, or quaternions In addition to the specialized simu- Developing simulation models is a
lation languages and graphical devel- field unto itself. For a relatively simple
For a simulation language or opment tools, it is common to use gen- application, it may be possible to
graphical programming tool to be use- eral purpose programming languages develop a model that consists of a few
ful for HIL simulation, it must be able such as Fortran and C to develop HIL equations describing the physics of the
to generate code optimized for use on simulations. Many HIL simulations subsystem or phenomenon being
a real-time simulation computer. It have been written from scratch, using modeled. For a more complex system,
should also provide a simulation oper- only the tools and libraries supplied a model might be based on a large
ator interface that allows the user to: with the target system compiler. While number of complex mathematical
this approach can succeed, it requires algorithms and voluminous tables of
• Examine and modify simulation a great deal of effort developing effi- experimentally measured data.
variables cient and correct methods for numer- A real-time simulation model of a
continuous dynamic system is usually
implemented as a set of simultaneous,
FIGURE 2 HIL simulation software flow nonlinear, first-order ordinary differ-
ential equations. These equations are
supplemented by algebraic equations
that are used to compute intermediate
Initialize simulation
Initialization and other miscellaneous values. This
and hardware
entire set of equations is used to com-
pute the derivatives of the state vari-
Read from input ables during each simulation frame.
devices After evaluating the derivatives, the
state variables are integrated numeri-
cally to produce the state variable val-
Evaluate simulation
ues that will be valid at the start of the
models
next frame.
For subsystems that operate in a
Write to output discrete-time manner, models can be
Dynamic Loop devices developed in terms of difference equa-
tions. In a difference equation, the
next-frame value of a state is comput-
Yes
End of run? ed during the evaluation of the cur-
rent frame. At the end of the frame,
No
the discrete states are updated to their
Integrate state
next-frame values. Discrete states can
variables be used to implement algorithms such
as digital filters and to model subsys-
tems such as DAC output signals.
Delay until time to Continuous-system models and dis-
start next frame
crete-system models can be combined
in a simulation as long as integration
algorithms are used for the continu-
Shut down simulation
Shutdown ous system that can accommodate the
and hardware
discontinuities introduced by the dis-
crete time model.
In general, simulation models are
not precise representations of their
physical counterparts. Assumptions Many techniques have been lation may be faster than evaluating
and simplifications must be made to employed in HIL simulations to imple- an expression containing several
develop simulation models. The fewer ment models of adequate fidelity transcendental function calls, float-
assumptions made, the more complex while remaining within simulation ing point divisions, or other time-
a model must be. Some major limita- computer execution time and memo- consuming operations
tions on model complexity are: ry limits. Some of these techniques • In a real-time simulation, the worst-
include: case execution time for a model is
• The time it takes to design, devel- all that matters, rather than the
op, verify, and validate the simula- • Precompute as much as possible average time. Therefore, focus on
tion model during program initialization. optimizing only those execution
• The effort required to collect and Although the compiler’s optimizer paths that contribute to the worst-
analyze experimental data needed can help with techniques such as case execution time. Good profil-
to develop the model common subexpression elimina- ing and debugging tools are invalu-
• The execution time and memory tion, you can enhance perfor- able during this process
space that the model’s implementa- mance further by removing calcula-
tion consumes on the simulation tions that produce unchanging val- Although developing and validat-
computer ues from the simulation dynamic ing a simulation model that meets the
frame requirements discussed above is chal-
The developer must design and • Use interpolation functions to lenging, the model can then be used
implement a model that has adequate approximate the evaluation of in a variety of applications in addition
fidelity for its intended purpose while complex expressions. Doing a mul- to real-time simulation. For example,
remaining within these constraints. tidimensional lookup and interpo- the model can be used by product
This allows the entire subsystem to be Finally, you could use a simulated select the appropriate points at which
tested, including the video camera, or real production line to create the to interface the system under test to
image processor, and production line scene viewed by the video camera in the simulation computer. Selection of
control computer. Drawbacks to this real time. This method may or may the proper interface point depends on
approach, besides the hardware cost not be feasible, depending on consid- the simulation purpose, the adequacy
and development expense, include erations such as whether such produc- of models of subsystems that might be
the need to align and calibrate the tion lines exist, how complex it would simulated rather than implemented as
projected image so that it appears real- be to build a simulated line, and so real hardware in the simulation, and
istic to the system. Although this tech- forth. funding available to develop the HIL
nique may seem farfetched for this This example demonstrates how simulation.
application, it is used effectively in the important it is to identify the require-
test of some tactical missile sensors. ments for an HIL simulation and Budget realistically for simulation develop-
ment and ongoing operations. An HIL
simulation can be an expensive propo-
Rate Monotonic Scheduling in real-time simulations sition. Its value will be realized,
Rate Monotonic Scheduling (RMS) is a method for scheduling real-time tasks so that though, if overall project cost and risk
each task’s deadlines will always be met. The technique is applicable to run-time envi- can be reduced compared to the cost
ronments that support prioritized, preemptive multitasking or multithreading. Here, we if the simulation had not been used.
use the term task to mean either a task or a thread. The mathematical basis of RMS The initial development of an HIL
has been rigorously developed and analyzed (visit the Software Engineering Institute at simulation can be quite expensive and
www.sei.cmu.edu and search for “Rate Monotonic Analysis”). this must be understood during pro-
To use RMS, the execution frequency of each task must first be identified. In our ject planning. Continuing operation
HIL simulation application, this frequency will be the inverse of the task’s integration of the simulation will also require
step size, h. The scheduling priority of the tasks is then assigned so that the highest fre- competent technical staffing to imple-
quency task has the highest priority on down to the lowest frequency task, which has ment upgrades and troubleshoot
the lowest priority. This assignment of priorities as a monotonic function of task exe- problems.
cution rate is what gives RMS its name. The project phase at which the HIL
The execution time of each task cannot be so long that it causes itself or any lower- is brought on-line can have a signifi-
priority tasks to miss deadlines. Upper bounds for each task’s execution time can be cant impact on overall product devel-
determined such that the entire system will be guaranteed to not miss any deadlines as opment cost. The availability of an
long as all tasks stay within their allotted execution time. HIL simulation early in the project
Applying RMS to real-time simulation must involve consideration of the following can be invaluable to system designers
elements: who need a tool for studying alterna-
tives and refining their designs.
• Task switch overhead must be accommodated in developing timing requirements
• Data must be passed among the tasks in a properly timed manner Consider in advance how to deal with
• Extrapolation and interpolation may need to be performed on data passed between unexpected results. Inevitably, there will
different-rate tasks be times when a simulation doesn’t
• I/O operation timing must be considered when selecting integration time step sizes produce the expected results. If this
• State variable integration must be coordinated with the intertask data transfers occurs while a deadline is creating
severe time pressures, these results
If these items are properly handled, RMS can provide significant benefits in multi- may be ignored. This situation is espe-
frame real-time simulations. Multiframe simulation is used when subsystems must be cially likely to occur if the simulation
simulated at different frame rates. Using RMS allows these different frame rates to run hasn’t gone through a thorough vali-
on a single CPU while I/O operations occur at the correct times for each different frame dation process and won the support of
rate. all interested parties.
If the RMS-based multiframe simulation is carefully designed, it should be possible Some preplanning should be done
to move tasks to different CPUs with relative ease as new CPUs are added to the sys- to decide what actions to take in these
tem. Tasks can be relocated among CPUs to provide optimization through load bal- situations. Ideally, sufficient resources
ancing. should be devoted to determining the
RMS is a tool that developers can use to implement high-performance, real-time reason for the discrepancy. If it turns
simulations that make the best possible use of available resources. out that there is a system problem, the
HIL simulation will have demonstrat-
ed its value.
Simulations can produce massive amounts will be required to identify the source • When the cost of an operational
of data. It isn’t unusual for an HIL sim- of the anomaly. system test failure may be unac-
ulation to be capable of generating Reasonably priced software config- ceptably high, such as when testing
and storing 100K of data per second of uration management tools are avail- aircraft, missiles, and satellites
operation. If this simulation is in oper- able that make the process relatively • When the cost of developing and
ation for a full day, it will produce sev- painless. There really is no excuse for operating the HIL simulation can
eral gigabytes of data. What do you do not having your simulation under con- be saved by reductions in the num-
with all this data? figuration control. ber of operational tests. For exam-
A plan must be in place for per- ple, this may be the case with an
forming data reduction, analysis, and Consider having the users of the results pro- automotive antilock brake control
archiving. Users who request test runs vide a simulation accreditation. As previ- system that must be tested under a
of the simulation must specify what ously mentioned, verification and vali- wide variety of operator input and
types of data output they require. All dation of the simulation are critical road surface conditions
data that may be of interest at a later steps in the simulation’s development. • When it is necessary to be able to
date must be archived by the simula- Performing an additional step called duplicate test conditions precisely.
tion operation staff. accreditation often makes sense. An This allows comprehensive regres-
Data analysis and plotting pro- accredited simulation has had its veri- sion testing to be performed as
grams are the most general tools used fication and validation tests developed changes are made to the SUT
to examine the raw simulation output based partially on inputs from the ulti- • When it would be valuable to per-
data. More specialized automated mate users of the simulation results. form development testing on sys-
tools can be a great help for generat- Those users then examine the results tem component prototypes. This
ing summary reports and other tasks, of the verification and validation tests allows subsystems to be thoroughly
such as scanning the data to make sure and have authority to approve the sim- tested before a full system proto-
tolerances aren’t violated. ulation as demonstrating acceptable type has even been constructed
fidelity.
Configuration management must be part Involving the expert users in the HIL simulation is a valuable tech-
of the process from the beginning. The soft- verification and validation process can nique that has been used for decades
ware that is used in the HIL simulation provide powerful feedback that results in the development and testing of
must be maintained under adequate in an improved simulation and more complex systems such as missiles, air-
configuration management at all extensive simulation usage than would craft, and spacecraft. By taking advan-
times. Making any changes to the soft- otherwise occur. Accrediting the simu- tage of low-cost, high-powered com-
ware in such a way that the change lation can provide crucial “buy-in” puters and I/O devices, the advan-
cannot be undone is simply an unac- from people who might otherwise be tages of HIL simulation can be real-
ceptable scenario. dismissive when presented with simu- ized by a much broader range of sys-
Sometimes an anomaly will occur lation results that don’t match their tem developers. A properly designed
in a test situation that didn’t occur expectations. and implemented HIL simulation can
during a similar test in the past. Of help you develop your products faster
course, in the time since the previous A reasonable simulation? and test them more thoroughly at a
test, both the system under test and The development of an HIL simula- cost that may be significantly less than
the simulation have most likely under- tion can be a complex and time-con- the cost of using traditional system test
gone significant changes. If the simu- suming process. Getting system methods. esp
lation software has been under config- experts to accept the results of an HIL
uration control, it will be possible to simulation as valid is often a formida- Jim A. Ledin, PE, is an electrical engineer
restore the software version used in ble obstacle. A simulated operational in Camarillo, CA. He has worked in the
the previous test and run it again. In environment will never be a perfect field of HIL simulation for the past 14
attempting this, a problem may arise if representation of the real thing. Given years. He is a principal developer of HIL
the hardware interfaces or embedded the costs and potential difficulties simulations for several U.S. Navy tactical
system communication protocols have involved, when does it make economic missile systems at the Naval Air Warfare
changed between the two simulation and technical sense to develop and Center in Point Mugu, CA. He can be
versions. In this case, additional effort use an HIL simulation? reached by email at jledin@ix.netcom.com.