Digital PID and DC Motor Block Diagram
r (t )
e(t ) +
−
e(kT ) T = Sampling Period
Digital PID Controller
m(kT )
Zero Order Hold
Gh ( s )
GPID ( s )
ADC
u (t )
(t )
DC Motor
G p ( s )
h(t ) Sensor
DC Motor in Detail
T L (t ) u (t ) +
−
Armature
i (t )
Torque Constant
uemf (t )
T a (t )
Back EMF Constant
−
+
Load
(t )
Mohsen Mirtalebi
1
T i
m(t ) = K e(t ) + T i
∫ 0
e(τ )d τ + T d
de(t )
PID in Z Domain
dt
int egral _ time
=
T d
t
=
derivative _ time
m(kT ) = K {e( kT ) +
T e(0) + e(T )
T i
M ( z ) = Ζ Ζ K {e(kT ) +
2
e(T ) + e(2T )
+
2
T e(0) + e(T )
T i
+
... +
e(T ) + e(2T )
+
+
e((k − 1)T ) + e(kT )
... +
+ T d
2
e((k − 1)T ) + e( kT )
2 2 T T 1 T d + + M ( z ) = K 1 − (1 − z 1 ) E ( z ) 1 T 2T i T i 1 − z K I 1 M ( z ) = K P + + K D (1 − z ) E ( z ) 1 1 − z (K pz + K iz + K dz ) z 2 − (K pz + 2 K dz ) z + K z M ( z ) = E ( z ) z 2 − z
2
e( kT ) − e((k − 1)T )
+ T d
T
e( kT ) − e((k − 1)T ) T
−
−
−
−
GPID ( z ) =
M ( z ) E ( z )
=
(K
pz +
K iz
+
K dz ) z
2
−
(K
pz +
2 K dz ) z + K z
z 2 − z
Therefore : K P K I K D
=
=
=
K − KT
KT
2T i
Note: 1- Z domain domain is the digital digital domain. domain.
T i
2- T is the sampling sampling frequenc frequency y of the ADC
KT d
3- Zero-Ord Zero-Order_H er_Hold old is the DAC
T
‘S’ Domain Domain Equation Equationss Typical Armature Model in S Domain: 1 Ls + r
, L = Induction _ Value _ in _ Henry, r = Motor _ Winding _ Resistance
Typical Load Model in S Domain: 1 Js + B
, J = Moment _ of _ Inertia, B = Viscous _ Friction _ Coef
Back EMF and Torque Constants: K a
Motor Equations in S Domain: K 1 r s + i ( s ) = − a ω ( s) + u ( s), i ( s) = Motor _ Current , u ( s) = Motor _ Input (Voltage) L L L 1 1 B s + ω ( s ) = K a i ( s ) − T L , T L = Load _ Disturbances(Torque), ω ( s) = Motor _ Output ( Angular _ Velocity) J J J ω ( s )
=
sθ ( s ),θ ( s ) = Angular _ Displacement
Zero Order Hold in S Domain: Gh ( s ) =
1− e s
Ts
, T = Sampling _ Period
‘S’ Domain Domain Calculation Calculationss PID Controller and System: GPID ( s ) = G p ( s ) =
K D s
s ( LJs
2
+
K P s + K I s K a
2
+
(rJ + LB )s + rB + K a2 )
G D ( s ) = Gh ( s )G p ( s ) Ts
=
1− e s
s ( LJs
K a
2
+
(rJ + LB )s + rB + K a2 )
System Simulation with MATLAB® %Mohsen Mirtalebi, BSEE: MATLAB m file to simulate a DC motor response using PID control %*********************************************************************** clear clear all; clc; %System Constants:******************************************************** r= input('Enter the Armature Resistance in Ohm: '); L= input('\nEnter input('\nEnter the Armature Inductance in Henry: '); B= input('\nEnter input('\nEnter the friction coefficeint coefficeint of the mechanical system in N.m/Rad: '); k_a= k_a= input('\n input('\nEnte Enterr the Torque Torque or Bkefm Bkefm Constant Constant N.m/Amp N.m/Amp:: '); J= input('\nEnter input('\nEnter the Moment Moment of Rotational Inertia Inertia (Sum of all M.R.I''s in Mech. Mech. Sys) Sys) in kg.sqr(m): '); T= input('\ input('\nEnt nEnter er your your Sampelin Sampeling g time in Sec: '); kp= input('\n input('\nEnte Enterr the PID Coef. Coef. Kp: '); ki= input('\ input('\nEnt nEnter er the PID Coef. Coef. Ki: '); kd= input('\n input('\nEnte Enterr the PID Coef. Coef. Kd: '); r_t = input('\n input('\nEnte Enterr the motor''s motor''s Armature Armature displacem displacement ent in Radian: Radian: '); %*********************************************************************** num= [k_a]; denum= [L*J (r*J+L*B) (r*J+L*B) (r*B+k_a^2) (r*B+k_a^2) 0]; [num_z,denum_z]=c [num_z,denum_z]=c2dm(num 2dm(num,denum,T,'zoh ,denum,T,'zoh'); '); %Z transform the system in S domain with 'zoh'= zero order hold kp_z=T* kp_z=T*kp; kp; ki_z=T* ki_z=T*ki; ki; kd_z=T* kd_z=T*kd; kd; num_pid num_pid_z _z = [(kp_z [(kp_z + ki_z + kd_z) kd_z) -(kp_z -(kp_z + 2*kd_z) 2*kd_z) kd_z]; kd_z]; denum_pid_z = [1 1 0]; num_G_z num_G_z = conv(num_pid_z,num conv(num_pid_z,num_z); _z); denum_G_z=conv(denum_pid_z,denum_z); K_f = 100; K=0:1:K_f; r_z=r_t*ones(1,K_f+1); %t=K*T y=filter(num_G_z,denum_G_z,r_z); plot(K,y,'o',K,y,'--'); title('Output (Angular Displacement),y(KT) [Rad]'); xlabel('K, t=KT (Second)');
Running System Response with Typical Numbers r= 5;L= 0.005;B=0.00001;k_a=0.1;J=0.0001;T=0.0005;kp=1000;ki=50;kd=10;r_t = .02
Sample of Overdamped/Underdamped/Critically Damped Response
Image Source: www.hydraulicspneumatics.com
How to Tweak Your Controller There are methods to optimize your controller: 1- There are 4 variables variables that you need to adjust to get get the optimum point in your your controller, T,Kp,Ki, T,Kp,Ki, Kd. This method method is tedious and requires a significant amount of time or luck to find the best controller. Please note that the sampling period is extremely critical to the stability of the controller. This is not obviously a recommended method. 2- Utilizing the proven design design methods such as: Root Locus Method, Method, Frequency Response Response Method, Method, and Analytical Design Method Method