Hardware in The Loop Simulation and Testing
Hardware in The Loop Simulation and Testing
blog
These are the complete requirements for the assignment. The rest of this document
contains resources like additional information, code examples, tips and tricks, step-by
step instructions, etc. that you can use at your own discretion.
https://www.halvorsen.blog
Resources
Hans-Petter Halvorsen Table of Contents
Table of Contents
1. Introduction
2. Introduction to HIL
3. Simulated Control System
• Air Heater Model
• LabVIEW PID Controller
• Lowpass Filter
4. HIL + Fuji PXG5 PID Controller
5. Real Control System: Fuji PXG5 + Air Heater
6. Digital Twins
https://www.halvorsen.blog
Introduction
Hans-Petter Halvorsen Table of Contents
Fuji PXG5 PID Controller
• We will create a Simulator (Mathematical
model) that shall be controlled by the PID
controller
• The main Hardware in this Lab is an
industrial PID controller
• The PID controller device will be the
“Hardware in the Loop”
• The aim is to test the the device before
you put it into production. This is referred
to as “Hardware in the Loop Simulation
and Testing
General HIL Concept Sketch
Hardware (HW) Software (SW)
Input Model of Output
HIL Unit
the System
Feedback
Learning Goals
• Learn key concepts within Hardware in the loop (HIL) simulations and
testing
• Learn practical skills and implementation of HIL applications
• Learn practical skills in Modelling, Control and Simulation
• Learn practical implementation of Industrial Control Systems
• Learn more LabVIEW Programming
• Learn about Hardware-Software Interactions
• Learn Practical Skills and Implementations in general
• Learn Software Installation in general, which can be cumbersome with
many pitfalls
• Learn to use and create Software in general in a professional manner
HIL Simulation - Step-by-step
1
Step 1: Ordinary Software Simulation: Mathematical Model
2
Step 2: HIL Simulation and Testing:
Mathematical Model
Purpose: Test your Hardware device
before you apply it on your real system.
Also useful for Training purposes.
3
Step 3: Running the Real System:
Purpose: Apply your Hardware in
the Production System
Step 1: SimulaIon
Control and Simulation in LabVIEW using built-in PID Controller and
Mathematical Model of the Process (Software only)
- Control Signal
0-5V
Industrial PID Controller
Software
• LabVIEW
• LabVIEW Control & SimulaBon Module
• DAQmx Driver SoIware
Your Personal
Computer
We have limited numbers of PID Controllers, so, 2-3 students may need to share a PID Controller
The teacher have not done Very often it works on one computer but
not on another. You may have other
all the Tasks in detail, so he
versions of the software, you may have
may not have all the installed it in the wrong order, etc...
answers! That's how it is in In these cases Google is your best friend!
real life also!
The Teacher dont have all the answers (very few actually L)!! Sometimes you just need to “Google” in
order to solve your problems, Collaborate with other Students, etc. Thats how you Learn!
Troubleshooting & Debugging
Use the Debugging Tools in your Use available Resources
Programming IDE. such as User Guides,
Visual Studio, LabVIEW, etc. have great Datasheets, Textbooks,
Tutorials, Examples,
Debugging Tools! Use them!!
My System Tips & Tricks, etc.
is not Mu
ltim
Working?? eter
, etc
“Google It”! Use
.
You probably will find the Microsoft
answer on the Internet Teams
Check your electric circuit, electrical cables, DAQ device, etc. Check if
Another person in the world probably the wires from/to the DAQ device is correct. Are you using the same
had a similar problem I/O Channel in your SoFware as the wiring suggest? etc.
Lab Assignment Guidelines
• Make sure to read the whole assignment before you start to
solve any of the problems.
• If you miss assump:ons for solving some of the problems, you
may define proper assump:ons yourself.
• The Tasks described in the Assignment are somewhat loosely
defined and more like guidelines, so feel free to interpret the
Tasks in your own way with a personalized touch.
• Feel free to Explore! Make sure to Add Value and Crea/vity to
your Applica:ons!
• Try to add some extra value and be crea:ve compared to the
simplified examples given by me, in that way you learn so
much more.
Lab Assignment Guidelines
• Think about the Lab Assignment as a small real-life industrial
Project, and not a set of tasks or exercises.
• What does the company that hire you expect from you when
you deliver this project? What kind of Quality is expected?
• Try to see your work in a larger context than just a Lab
Assignment or a set of exercises.
• Try to see the big picture. The tasks within the assignment
are just just small building blocks that ends up with a fully
working system.
• It is recommended that you make a Work Plan and a System
Sketch that gives you an overview of what YOU should do
Lab Work Requirements
• Make sure to see the “Big picture” – you don’t need to document every single step you
have made. Focus on what’s important (your final system).
• Your GUIs is important! - make sure to make them user friendly and intuitive. You create
this on behalf of someone that are going to use your applications.
• Make sure to always add Units in your GUI, charts, documentation, etc.
• Presenting values with 4+ decimals makes no sense! E.g., a temperature sensor is not
that accurate. You can easily change number of decimals that you present in your GUI in
LabVIEW, C#, etc.
• The Quality of the LabVIEW code is important. Make sure to use "straight lines" in your
LabVIEW code, etc. The code should also flow from left to right, not opposite direction.
You create this on behalf of someone that are going to use your applications. Neat code
makes it easier to develop, maintain, find code errors, etc.
• In general, make sure that you take some pride in your applications and the work that
you do. It's not about getting finished as soon as possible. The mission is to learn as
much as possible within a given timeframe. Try to change the mindset.
• To improve the LabVIEW code, please see this video: LabVIEW Applications using State
Machine: https://youtu.be/-b9St8wNhpQ
https://www.halvorsen.blog
Introduction to HIL
Hans-Petter Halvorsen Table of Contents
What is HIL Simulation?
The main purpose with the HIL Simulation is to Test the Hardware-in-the-loop (HIL) simulation and testing is a
Hardware device on a Simulator before we implement it
technique that is used in the development and test of
on the real process.
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.”
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)
- Control Signal
0-5V
Industrial PID Controller
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)
DeltaV
from Emerson
Siemens PLC
HIL Background
• 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)
simulaMon.
• The main purpose with HIL is to test the hardware device on a
simulator before we implement it on the real process.
• If the mathemaMcal model used in the simulator is an accurate
representaMon 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.
HIL Simulation
Traditional Process Control using Software for Implementing the Control System
SoJware Hardware
u y y AI
PID Process
u
DAQ
AO
HIL Simulation
Hardware SoJware
u y AI
u
PID Process
Mathematical Model y
DAQ
AO
HIL Simulation
• 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 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.
HIL Simulation using PXG5 PID
Control Signal
𝑢 [0 − 5𝑉] 𝑦 [20℃ − 50℃]
𝑢 [0 − 5𝑉]
PXG5 𝑢 Simulated
Scaling? USB-6008
PID Controller It depends on
Process Measurement
Analog In (AI0)
your settings
Simulated Control
System
Hans-Petter Halvorsen Table of Contents
Simulated Control System
Purpose: Create, Simulate, Control and Test the Mathematical Model.
Find Proper PID Parameters.
Software Software
u y
PID Process
DAQ
https://www.halvorsen.blog
𝐾$
Heater
Control
Unit
𝑇!"# Temperature
Sensor on the 20 − 50℃
Fan outlet
Students: Implement and Simulate a Mathematical Model of the Air Heater using LabVIEW.
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:
Manual
Control
Simulation SubSystem
Inimalizamon
Finding Model Parameters using “Trial and Error”
You may use, e.g., the following Parameters as a starting point, but since every
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.
These values can be a good starting point:
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
Ex
SubVI that take care of input am
from DAQ device, Scaling, etc. pl
e
Compare Model
with Real Process
Initialization using
Property Nodes Replace this with your
model of the Air Heater
“Air Heater Black Box Model”
• The Real Air Heater is only available in the
Laboratory
• A “Real” Air Heater will we provided for
download as a “black box”. Actually, it is a
LabVIEW SubVI where the Block Diagram and
the Process Parameters are hidden.
• Useful for Online Students and when you are
working with the Assignment outside the
Laboratory
For Online Students • You can use it to find Model Parameters, etc.
when you are not in the Laboratory
https://www.halvorsen.blog
LabVIEW PID
Controller
Hans-Petter Halvorsen Table of Contents
PID Control of Model in LabVIEW
The Simulation Loop has some drawbacks/is more complicated to use than an ordinary While Loop. If we
use Simulatation Subsystems, we can use them inside a While Loop instead! - which becomes very handy!
Students: Implement a Control System in LabVIEW where you use the built-in PID
Controller and the Mathematical Model of the Air Heater
LabVIEW PID Controller
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
PID Parameters
• Find Proper PID Parameters for the system
• We will primarily focus on PI, but you may try PID
as well
• E.g., use one or more of the following methods:
– “Trial and Error” method
You may try these values
– Skogestad’s method as a starting point:
– Ziegler Nichols method 𝐾) = 0.8
𝑇* = 20𝑠
– etc. 𝑇( = 0𝑠
PID Tuning with Skogestad
Lowpass Filter
Hans-Petter Halvorsen Table of Contents
Lowpass Filter
• You should consider using a Lowpass Filter in order to
reduce Noise
• You can use a built-in Filter in LabVIEW
• Or you can create your own Lowpass Filter from scratch
• Or download a Lowpass Filter (LabVIEW SubVI) from the
Web site of this Lab Assignment
• You should first Test it on the MathemaGcal model before
you apply it on the real system (next Task)
See next slides for examples
Built-in Lowpass Filter to reduce Noise
Functions palette: Express -> Signal Analysis -> Simulate Signal
SubVIs
am
pl
e
https://www.halvorsen.blog
Step 2: HIL Simulation and Testing
Hardware Software
u y
PID Process
DAQ
Fuji PXG5 PID Controller
No Food and Drink allowed when
you use the Fuji PXG5 hardware,
Make sure to disconnect the power cable when wiring because of risk of electric shock!
HIL with Fuji PXG5/PXR5 PID Theory
Numeric Control
Should be equal
Numeric Indicator
You can find the The PXG5 PID Instrucmon Manual googling it or on the lab assignment web page
Hardware
PXG5 PID Controller
Wiring Diagram
We use a 250Ω resistor to convert
the signal from 0-20mA to 0-5V
Channel 1: Auto-tuning
Channel 2: PID Parameters
PXG5 - Configuration
Some recommended Channel Settings:
Closed-loop Control
Channel 6:
Channel 1: Channel 2: Pvb = 20 (Lower PV Limit)
MAn = oFF SvL = 20 (Lower SV Limit) PvF = 50 (Upper PV Limit)
rEM = LoCl Svh = 50 (Upper SV Limit) Pvd = 0 (or 1) #digits after
AT = oFF You set SV locally in the Fuji PID
decimal point
You can
choose to
show
voltage or
Engineering
0 − 100% → 0 − 5𝑉 units
Example:
Students: Find proper PID parameters using, e.g., Skogestad, Ziegler Nichols, etc.
PID Tuning with Skogestad
Hardware Hardware
u y
PID Process
DAQ
Fuji PXG5 + Real Air Heater
Industrial PID Controller
Process Value
1-5V
Control Signal
0-5V
Students: 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? Which PID parameters are best?
When you are not in the Laboratory
For Online Students
Trending/Monitoring
0-5V
the Process Value and
Control Signal on the PC Control Signal
y Process Value
u USB 1-5V Control Signal
0-5V
Recommended Settings
Save Data to File (Datalogging)
Ex
am
pl
e
Measurement
Open the File with Logged
File – Data Visualization
Open the File with Logged Data in MS Excel and
Data in e.g., Notepad: create a Chart (Measurement Value, Control Value)
Fuji Autotuning
on Model
Fuji on Real
Process
Fuji Autotuning
on Real Process
... others
Digital Twins
A brief Overview of a Digital Twins and how it is related to HIL Simulations
Feedback
Digital Twin
• Digital twins integrate internet of things, artificial
intelligence, machine learning etc. to create living
digital simulation models that update and change
as their physical counterparts change.
• A digital twin continuously learns and updates
itself from multiple sources (sensors, etc.) to
represent its near real-time status
Digital Twin and HIL
• The terms Digital Twin and Hardware in the Loop
Simulation are closely related.
• National Instruments doesn’t use the term digital
twin, but their hardware-in-the-loop (HIL) testing
technology platform provides similar
functionality
• http://www.ni.com/en-no/innovations/automotive/hardware-in-the-loop.html
• https://www.digitalengineering247.com/article/seeing-digital-twin-double/
Digital Twins in Automation Systems
• Preventive Maintenance
• Improved Control
• Model Based Control (MPC)
• State Estimation and Kalman Filter
• Can use the simulated environment to experiment
with different controls strategies
• Model different scenarios to optimize the
production
Why Digital Twins?
• Preventive Maintenance
• Predictive Analytics
• Improved Control
• Can use the simulated environment to
experiment with different controls strategies
• Model different scenarios to optimize the
production
Fuji PXG5 + Real Air Heater + Digital Twin
A Simulator running in
parallel with the real system
𝑢
𝑦
Simulator
𝑦 𝑢
E-mail: [email protected]
Web: https://www.halvorsen.blog