[Link]
blog
Hardware-in-the Loop (HIL)
Simulation and Testing
Hans-Petter Halvorsen
HIL Simulation and Testing
• Hardware-in-the-Loop (HIL) Simulation is a
technique that is used for Testing Control
Systems, Embedded Systems, etc.
• Carrying out a HIL Simulation to Test the
Control System, Embedded System, etc. is
called HIL Testing.
[Link]
[Link]
HIL Simulation and Testing
• The machine or physical part of the system (which
we call the plant) is normally connected with the
control system, through actuators and sensors.
• With HIL testing the plant is replaced by a
simulation of the plant (which we call the HIL
simulator).
• If the HIL simulator is designed well, it will
accurately mimic the plant, and can be used to test
the control system.
[Link]
HIL Simulation and Testing
• Hardware-in-the-loop (HIL) simulation is a technique that is used in the
development and test of complex process systems
• The HIL simulation includes a mathematical model of the process and a hardware
device/ECU (Electronic Control Unit) you want to test, e.g. an industrial PID
controller we will use in our example. The hardware device is normally an
embedded system
• The main purpose with the HIL Simulation is to test the hardware device on a
simulator before we implement it on the real process
• It is also very useful for training purposes, i.e., the process operator may learn
how the system works and operate by using the hardware-in-the-loop simulation
• Another benefit of Hardware-In-the-Loop is that testing can be done without
damaging equipment or endangering lives.
The main purpose with the HIL Simulation is to
test the hardware device on a simulator HIL Simulation and
before we implement it on the real process.
Testing
Hardware-in-the-loop (HIL) simulation is a technique that is used in the
development and test of complex process systems. HIL simulation
provides an effective platform by adding the complexity of the plant
under control to the test platform.
The complexity of the plant under control
is included in test and development by
adding a mathematical representation of
all related dynamic systems. These
mathematical representations are referred
to as the “plant simulation.”
Hardware-In-the-Loop is a form of real-time simulation. Hardware-In-the-Loop differs from real-
time simulation by the addition of a real component in the loop. This component may be an
“Electronic Control Unit” (ECU).
ECU - Electronic Control Unit
• In automotive electronics, electronic control
unit (ECU) is a generic term for any embedded
system that controls one or more of the
electrical system or subsystems in a motor
vehicle.
• ECU could also be an embedded PID Controller,
etc. (which we will use in our example)
[Link]
Examples of Industrial Control Systems (ICS)
Industrial Control Systems are computer controlled systems that monitor and control industrial processes that exist in the physical world
National
Instruments
cRIO
Programmable LabVIEW
PC based Control
Automation Industrial PID System/SCADA System
Controller Controller (Supervisory Control And Data
(PAC) Acquisition) I/O Module
Distributed Control Systems (DCS) PLC (Programmable Logic Controller)
Controller I/O Modules
DeltaV
from Emerson
Siemens PLC
Example of Industrial Single Loop PID Control
Process (Air Heater)
+
Process Value
- 1-5V
- Control Signal
0-5V
Industrial PID Controller
Example of PC-based Control System
Process (Air Heater)
USB Analog In
(Process Value)
AI0+
Computer (with LabVIEW) 1-5V
AI0-
AO0 0-5V
GND
Analog Out
(Control Signal)
I/O Module (USB-6008)
Typically you want to test the Control System using a
PID Control and Monitoring Mathematical Model before you use it on the Real System
Traditional Process Control using Software
for Implementing the Control System
Software Hardware
u y y AI
ECU Process
u
DAQ
AO
HIL Simulation and Testing
Hardware Software
u y AI
ECU Process
u
y
DAQ
AO
HIL Simulation and Testing
Example
Hans-Petter Halvorsen, [Link].
Necessary Software Software
• LabVIEW
• LabVIEW Control & Simulation Module
• DAQmx Driver Software
Air Heater
Fuji PXG5 PID Controller
HIL Example
• Typically, a simulator communicates with an “ECU” (“Electronic Control
Unit”) via ordinary I/O. Such a system - where the real controller is
controlling a simulated process is denoted Hardware-in-the-loop (HIL)
simulation.
• The main purpose of this Example is to test the hardware device on a
simulator before we implement it on the real process.
• If the mathematical model used in the simulator is an accurate
representation of the real process, you may even tune the controller
parameters (e.g. the PID parameters) using the simulator.
• We will test the Fuji PGX5 PID controller on a model, and if everything
is OK we will implement the controller on the real system.
Example of HIL Simulation and Testing
Model of Process (Air Heater)
Analog Out
(Process Value) USB
1-5V
AO0
GND
Mathematical Model
Note!!
AI0+
AI0- Computer (with LabVIEW)
Analog In I/O Module
(Control Signal) (USB-6008)
0-5V
PID Control
HIL Simulation and Testing
The figure illustrates the principle of testing a control system by replacing the physical system
(or process) to be controlled by a simulated system. The controller is assumed to be a PID
controller, but the figure applies to any controller function.
HIL Simulation Example - Step-by-step
1
Step 1: Ordinary Software Simulation:
2
Step 2: HIL Simulation:
3
Step 3: Running the Real System:
Traditional Process Control using Software
for Implementing the Control System
Software Hardware
u y y AI
PID Process
u
DAQ
AO
HIL Simulation and Testing
Hardware Software
u y AI
PID Process
u
y
DAQ
AO
HIL Simulation using PXG5 PID Controller
Control Signal
𝑢 [0 − 5𝑉] 𝑦 [20℃ − 50℃]
𝑢 [0 − 5𝑉]
PXG5 𝑢 Simulated
Scaling USB-6008
PID Controller Process Measurement
Analog In (AI0)
Analog Out (AO0)
USB-6008 Scaling
[1 − 5𝑉] [1 − 5𝑉] 𝑦 [20℃ − 50℃]
𝑓(𝑥) = 𝑎𝑥 + 𝑏
Matematical Model
Hans-Petter Halvorsen, [Link].
Air Heater
Hardware
Air Heater
• Heater: The air is heated by an electrical heater. The supplied
power is controlled by an external voltage signal in the range 0 -
5 V (min power, max power).
• Temperature sensors: A Pt100 temperature sensor. The range is
1 - 5 V, and this voltage range corresponds to the temperature
range 20 - 50oC (with a linear relation).
Example of Mathematical model:
1
𝑇̇789 = −𝑇789 + 𝐾< 𝑢 𝑡 − 𝜃> + 𝑇?@A
𝜃9
Air Heater Hardware
Mathematical Model
1
𝑇̇789 = −𝑇789 + 𝐾< 𝑢 𝑡 − 𝜃> + 𝑇?@A
𝜃9
Where:
We will use the
following values in
the Simulations:
Air Heater in LabVIEW
Heater: The air is heated by an electrical heater. The supplied power is
controlled by an external voltage signal in the range 0 - 5 V (min power,
max power).
Temperature sensors: Two Pt100 temperature elements are available. The
range is 1 - 5 V, and this voltage range corresponds to the temperature
range 20 - 50oC (with a linear relation).
Example of Mathematical Model of Air Heater implemented in LabVIEW:
Note! This model is implemented in a so-called “Simulation Subsystem” (which is recommended!!!)
Model Simulation Example (Note! No PID Control in this Example)
Note! This is just an Example! – You should create your own personal Application
Clear the Charts, etc. Step Response
using “Property Nodes”
Manual
Control
Simulation SubSystem
Initialization
Simulation Subsystem
A Way to structure your code, similar to SubVIs
This is the recommended way to do it! – You can easly reuse your
Subsystems in different VIs and your code becomes more structured!
Select File -> New ..., Then choose “Simulation
Subsystem”.
Create your Model within the Simulation Subsystem
System Identification
Hans-Petter Halvorsen, [Link].
Air Heater Hardware
Mathematical Model
1
𝑇̇789 = −𝑇789 + 𝐾< 𝑢 𝑡 − 𝜃> + 𝑇?@A
𝜃9
Where:
We will use the
following values in
the Simulations:
Finding Model Parameters using “Trial and Error”
You may use, e.g., the following Parameters as a starting point, but since every Theory
Air Heater is unique, you may want to adjust these parameters. The “Trial and
Error Method” may be an easy way to find the Parameters for your Process.
Step Respone
Equal?
Procedure: You run the Model and the Real Process in Parallel. Adjust the Model
Parameters until the output of the Model and the Real Process is “equal”.
“Trial and Error” Example in LabVIEW
SubVI that take care of input
from DAQ device, Scaling, etc.
Compare Model
with Real Process
Initialization using
Property Nodes Replace this with your
model of the Air
Heater
Alternative: Finding Model Parameters Theory
using the “Step Response Method”
Assuming a [Link] model
you can easily find the model
Laplace parameters (Process Gain,
Time constant and a Time
delay if any) from the step
response of the real system
Simulated Control System
Hans-Petter Halvorsen, [Link].
PID Control of Model in LabVIEW
Feedback Node
PID in LabVIEW
Front Panel
Normally we use seconds as unit for Ti and Td (which is
recommended!)
But the built-in PID algorithm in LabVIEW uses minutes
as unit!
Cluster
Block Diagram:
Trick:
Divide by 60
You could also put this code
into a new SubVI
HIL with Fuju PXG5 PID
Hans-Petter Halvorsen, [Link].
HIL with Fuji PXG5PID
• It may be very useful to test a controller function
with a simulated process before the controller is
applied to the real (physical) process.
• If the mathematical model used in the simulator
is an accurate representation of the real process,
you may even tune the controller parameters
(e.g. the PID parameters) using the simulator.
HIL Simulation Setup
Model of Process (Air Heater)
Analog Out
(Process Value) USB
1-5V
AO0
GND Mathematical Model
Note!!
AI0+
AI0- Computer (with LabVIEW)
Analog In I/O Module
(Control Signal) (USB-6008)
0-5V
PID Control
Test Communication between PXG5 and DAQ Device
You should test the communication before you start working on the task Note! Set Parameter C1r in Ch6: 0-20mA.
A 250 Ω resistor converts the signal to 0-
5V
You can
choose to
show
voltage or
Engineering
0 − 100% → 0 − 5𝑉 units
We run the PXG5 in Manual
We manually adjust the
Mode (hold down the A/M
setpoint between 0-
button for å few seconds) 100%
HIL Simulation in LabVIEW - Example
You can use a
Simulation
Loop or a
While Loop
SubVI: Note! This is opposite of what you normally do
Setting PID
Parameters
on the PXG5
Note! PXG5 uses Proportional Band
Example:
PID Tuning with Skogestad
We can set, e.g., Tc=10
sec. and c=1.5. You may
use other values if these
values give a poor result.
PXG5 – Auto-tuning
1. With the controller in manual mode (open loop control): Adjust the manual control
signal so that the process output is approximately 2.5 𝑉.
2. Set the controller in automatic mode (“closed loop control”).
3. Start Auto-tuning
Note! PXG5 uses
Proportional Band
A lamp is blinking when the
auto-tuning is running
Fuju PXG5 + Real Air Heater
Hans-Petter Halvorsen, [Link].
Air Heater
Fuju PXG5 + Real Air Heater
Industrial PID Controller
Process Value
1-5V
Control Signal
0-5V
You should Test the PXG5 PID Controller on the real Air Heater. Are you able to use the same
PID settings you found using the Model? Test also the Auto-tuning functionality. Do you get the
same parameters as using the model?
Fuju PXG5 + Real Air Heater + PC for Monitoring
Industrial PID Controller
Process Value
1-5V
Trending/Monitoring 0-5V
the Process Value on
the PC Control Signal
y Process Value
USB
1-5V
With this setup you can Monitor
PC with LabVIEW the Process Value on your PC
Hans-Petter Halvorsen
University of Southeast Norway
[Link]
E-mail: [Link]@[Link]
Web: [Link]