You are on page 1of 61

1

Introduction to the NI LabVIEWControl


Design and Simulation Module
Andreas Stark
Systems Engineer
2
Agenda
Simulation Concepts
PID Concepts
Advanced Control Algorithms
Conclusion
3
Agenda
Simulation Concepts
PID Concepts
Advanced Control Algorithms
Conclusion
4
How to become a control expert?
Trial and Error Simulation
Time consuming
Risk
No need of physical plant
Safe
5
What can you learn from simulation?
Gain insight into the system that otherwise would
be impossible or difficult due to real-world
limitations
Improve your design before beginning the
prototyping stage
Validate and tune your embedded LabVIEW
FPGA or LabVIEW Real-Time logic
6
What is simulation?
Use mathematical formulas to represent dynamics
of a system
7
Simulation Benefits
Faster, better control algorithm code
development
Understand how your control algorithm effects
the system
Evaluate impact of
Sampling rate
Sensor response time, noise, offset/gain error
Deadtime, backlash or resonance
8
Todays Example
Maxon Amax
Brushed DC Motor
NI 9505
Motor Drive Module
Ethernet
9
Demo DC Motor Control Simulation
10
Control System Diagram DC Motor
Desired
Position
PID
Compensator
Drive
Output
Motion
System
Encoder
Sensor
-
+
Error
Disturbance
LabVIEW
Front Panel
PID
Toolkit
NI 9505
Real-Time Hardware
Measured
Position
FPGA Hardware Windows
11
12
How to create plant models.
The old days
Write differential equations for system
Linearize the system
Convert to Laplace domain
Rearrange for transfer function or state-space model
Enter matrix equations
Today
Write differential equations for system
Type into a formula node in the LabVIEW diagram
Click RUN
Use System Identification
Use measurement data
13
Simulating a DC Motor the Old Way
i K T
t m
= B
J
Shaft
Angle
u
dt
d
B T
f
u
=
2
2
dt
d
J T
i
u
=
+
-
+
-
+
-
R L
i
dt
d
K v
e e
u
=
dt
di
L v
L
=
iR v
R
=
m
v
DO5
+
-
+
-
V
sup
i
d
dt
d
K
dt
di
L Ri v
e m
u
+ + =
dt
d
B
dt
d
J i K
t
u u
=
2
2
0
L
v
dt
d
L
K
i
L
R
dt
di
m e
+ =
u
dt
d
J
B
i
J
K
dt
d
t
u u
=
2
2
Sum of Forces Kirchoffs Voltage Law
Rearrange to put highest order derivative terms on the left side of equation:
14
The Traditional Way: Laplace Transforms
Laplace transform of motor force & voltage equations,
Rearranging the force equation,
Transfer function between motor terminal
voltage and shaft angle position,
O O = s B s J I K
t
2
0
s B s J
I K
t
+
= O
2
( )
|
.
|

\
|
+
+ + +
=
O
JL
K K BR
s L R J B s s
JL K
V
e t
t
m
/ /
/
2 3
O + + = s K sI L I R V
e m
15
Demo - DC Motor Simulation TF
16
Laplace Transform Approach
Benefits
Wide array of analytical techniques available (bode plots, root
locus, stability analysis, )
Challenges
Transformation is labor intensive
System must be linear otherwise a linear approximation must
be made
Transfer functions are solved for one input and one output
must redo algebra to solve for other variables.
Difficult to monitor other system states during simulation
Abstract. After transformation, the system model is less
human readable
17
Simulating a DC Motor the Modern Way
i K T
t m
= B
J
Shaft
Angle
u
dt
d
B T
f
u
=
2
2
dt
d
J T
i
u
=
+
-
+
-
+
-
R L
i
dt
d
K v
e e
u
=
dt
di
L v
L
=
iR v
R
=
m
v
DO5
+
-
+
-
V
sup
i
d
dt
d
K
dt
di
L Ri v
e m
u
+ + =
dt
d
B
dt
d
J i K
t
u u
=
2
2
0
L
v
dt
d
L
K
i
L
R
dt
di
m e
+ =
u
dt
d
J
B
i
J
K
dt
d
t
u u
=
2
2
Sum of Forces Kirchoffs Voltage Law
Rearrange to put highest order derivative terms on the left side of equation:
18
Demo - DC Motor Simulation - Textual
19
LabVIEW Simulation Module with Formula Node
Easier: If you can find the equations in a textbook, you
can simulate the system
More intuitive: You can analyze the differential
equations to gain insight into the system and discover
novel control techniques
More informative: You can instrument the system
with no physical limitations on time, accuracy or which
variables can be measured
More accurate: Both linear and non-linear behavior can
be accurately simulated
20
System Identification Definition
If prototype hardware exists, system identification can
be used as first step in model-based control design
process
Create a mathematical model of dynamic system using
measured stimulus and response data
Techniques similar to curve-fitting
Dynamic
System
Inputs
(stimulus signals)
Outputs
(response signals)
21
Demonstration System Identification
22
Comparing Simulated & Real World Results
Real-World Simulated
23
Agenda
Simulation Concepts
PID Concepts
Basic PID Algorithms
Loop Rate
PID tuning
Advanced Control Algorithms
Conclusion
25
Set Point (SP) Desired control point
Output (OP) Controller output
Process Variable (PV) Plant/process output
Error = SP - PV
SP
OP
PV
error
What is PID Control
26
PID Parameters
Proportional
Drive to setpoint
Error 0, OP 0
Steady-state error
Integral
Eliminate steady-state error
OP proportional to error
Derivative
Increase response rate
OP proportional to change of error rate
27
Proportional-Integral-Derivative (PID)
Proportional
The further the system is from the set point, the larger the
actuator output to drive it to the set point
Integral
The longer the system has been off from the set point, the
larger the actuator output to drive it to the set point
Derivative
The faster the system is changing, the larger the actuator
output to drive it to the set point
28
Demo DC Motor Control
30
How to program PID
PID VIs
PID FPGA VIs
Function Blocks
Textual Math Scripts
Simulation VI
Ready to Run Custom
31
Algorithm Compatibility Chart
PID VIs Function
Blocks
FPGA PID VI Simulation VI Textual Math
Scripts
Windows
Yes No Yes Yes Yes
Real Time
Yes Yes Yes Yes Yes
FPGA
No No Yes No No
Included
with Product
PID and
Fuzzy Logic
Toolkit
LabVIEWRT PID and
Fuzzy Logic
Toolkit
Control
Design and
Simulation
Mathscript
RT
32
PID and Fuzzy Logic Toolkit - Features
Saturation
Integral Antiwindup
Bumpless Transfers
Autotuning
Gain Scheduling
Filtering
33
PID Toolkit Features Explained
Output Range Limits
Protects the motor
Integrator Antiwindup
Better performance in the presence of control
saturation
Bumpless Manual Control
Avoid abrupt changes to motor, increase life
34
Demonstration Integral Antiwindup
35
How fast should the loop rate be
Perception that faster is
better
Too fast might be
challenge to implement
Tuning challenges
Use Frequency
Response to find out
36
Frequency Response
Gain Crossover Frequency
Input
Output
System (Plant)
Frequency (Hz)
37
What can you learn from the frequency response?
Loop Rate Requirements
How fast the control system need to be
Rule of thumb
The control loop should be at least ten times faster than the gain
crossover frequency of the system (minimum 2X faster)
Crossover frequency = 40 Hz
Suggested Loop rate = 400 Hz
CAUTION: Increasing the control algorithm gain increases the crossover frequency
38
Demo: Frequency Response Demo
39
Real World Control Challenges
Systems with a fast response
Use a fast control system and fast I/O modules
Ensure determinism and avoid jitter
FPGA-based control systems are ideal !
40
PID Tuning and Loop Rates
Increasing the P gain makes your system faster.
Result: You may need a faster control loop rate.
41
Conclusions
The performance and stability of the system
depends on the frequency response of the
system AND the control algorithm
Systems that change quickly or have complex
behavior require faster control loop rates
Increasing the gain of the control algorithm may
mean you need to run the control system faster
44
Other PID Tuning tools
Manual
Open Loop Ziegler-Nichols
Closed Loop Ziegler-Nichols
Automatic
Autotuning
Frequency Based (Analytical PID)
Time Based (Optimization)
45
Demo Analytical PID
46
Conclusions
P gain is the most important factor in PID tuning
I gain gets rid of steady-state error
D gain is rarely used and may cause problems if
feedback signal is noisy
If you increase the gain, you may have to
increase the loop rate
If you see a system tuned with a gain of less than 1,
running the control loops faster may improve
performance and reliability
47
Agenda
Simulation Concepts
PID concepts
Advanced PID Algorithms
Conclusion
48
Upgrade Your PID
Disturbances
Nonlinear
Time Variant
Known
Profiles
Feedforward
Gain Scheduling
Adaptive PID
Model Predictive
Control
49
Feed forward
50
Gain Scheduling
PID 1
PID 2
PID 3
51
Control Design Techniques
Adaptive Control
Self-Tuning
Parameter or Structure of the
Controller modifies with changes
on the plant
System
(Plant)
Plant
Estimator
Set Point
-
+
Controller
Controller
Configurator
52
Adaptive PID - Example
53
Control Design Techniques
Modern Control
State-Space Feedback Controller Design
Ackermann / Pole Placement
Optimal or Linear Quadratic Regulator (LQR)
Stochastic Systems and Linear Quadratic Gaussian (LQG)
System
(Plant)
Estimator
Set Point
Regulator
u=-k.x
States
-
+
-
+
PID
Servo
54
Control Design Techniques
Optimal Control and Predictive Control
Parameter of the Controller are optimized for the specific operation.
System
(Plant)
Set Point
-
+
PID Control
Optimizer Constraints
dt Nu x Ru u Qx x J
Np
T T T
}
+ + =
0
2 min
55
Model Predictive Control Vs PID
57
Agenda
Simulation Concepts
PID concepts
Advanced PID Algorithms
Conclusion
58
Easily Deploy to Hardware the NI Way
Many modelsOne approach
59
Questions?
To find
Code used on the demonstration
Technical documentation
Follow up whitepapers
Go to
www.ni.com\info
and enter the code
devdays2010ctrl
60
Additional Resources
61
Deadtime
The interval of time between initiation of an input change or
stimulus and the start of the resulting response
Deadtime
62
Dead time
Deadtime is a delay between when a process
variable changes, and when that change can be
observed.
Examples:
Temperature sensor is placed far away from a cold water
fluid inlet valve
Delay caused by the flow of fluid through pipes
Will not measure a change in temperature immediately if the
valve is opened or closed
Deadtime can also be caused by a System (Plant) or
Output Actuator that is slow to respond to the
Compensator command.
Valve that is slow to open or close
Every sensor and I/O module causes some delay in
the measurement
Thermocouple sensor: Response time depends on thermal
mass
I/O module: Filters that remove 50/60 Hz noise slow the
response
63
Backlash
Example: Motor spins but gate doesnt begin to
open for some time due to a sloppy mechanical
system.
64
Resonance or Vibration
Avoid exciting the system at the resonant
frequency
Gain can be reduced at the problem frequency using
a notch filter or low pass filter
Use a custom control algorithms such as a lead-
lag controller
Convolve algorithm
MFA algorithm
65
Linear systems vs non-linear systems
Linear system
Steady state response of the system is linearly
proportional to the stimulus
Steady State Response Constant Stimulus
Offset
Gain
b mX Y + =
66
Linear system
Differential equation describing system response (y)
has constant multiplier coefficients
The function (y) or its derivatives (y, y) are not raised to
some power or embedded in another function (such as sin
y)
0 7
'
= y y First order linear, no stimulus
x y y y 2 sin 8 2
' ' '
= + Second order linear
( ) x y x y 4 sin 1
2 2 ' '
= Second order nonlinear

You might also like