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
TL (t )
u (t ) +−
Armature
i (t )
Torque Constant
uemf (t )
Ta (t ) − +
Back EMF Constant
Load
ω (t )
Mohsen Mirtalebi
de(t ) 1 t m(t ) = K e(t ) + ∫ e(τ )dτ + Td Ti 0 dt Ti = int egral _ time
PID in Z Domain
Td = derivative _ time m(kT ) = K {e(kT ) +
T e(0) + e(T ) e(T ) + e(2T ) e((k − 1)T ) + e(kT ) e(kT ) − e((k − 1)T ) + + ... + + Td Ti T 2 2 2
T e(0) + e(T ) e(T ) + e(2T ) e((k − 1)T ) + e(kT ) e(kT ) − e((k − 1)T ) M ( z ) = Ζ K {e(kT ) + T + + + ... + d T T 2 2 2 i T T 1 T M ( z ) = K 1 − + + d 1 − z −1 E ( z ) −1 T 2Ti Ti 1 − z
(
KI M ( z) = K P + + K D 1 − z −1 −1 1− z
(
)
) E ( z )
(K pz + K iz + K dz )z 2 − (K pz + 2 K dz )z + K z M ( z) = E( z) z2 − z 2 M ( z ) (K pz + K iz + K dz )z − (K pz + 2 K dz )z + K z GPID ( z ) = = E( z) z2 − z Therefore : KP = K − KT KI = Ti KD =
KTd T
KT 2Ti
Note: 1- Z domain is the digital domain. 2- T is the sampling frequency of the ADC 3- Zero-Order_Hold is the DAC
‘S’ Domain Equations Typical Armature Model in S Domain: 1 , L = Induction _ Value _ in _ Henry, r = Motor _ Winding _ Resistance Ls + r
Typical Load Model in S Domain: 1 , J = Moment _ of _ Inertia, B = Viscous _ Friction _ Coef Js + B
Back EMF and Torque Constants: Ka
Motor Equations in S Domain: r K 1 s + i ( s ) = − a ω ( s ) + u ( s ), i ( s ) = Motor _ Current , u ( s ) = Motor _ Input (Voltage) L L L B 1 1 s + ω ( s ) = K a i ( s ) − TL , TL = 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 − eTs , T = Sampling _ Period s
‘S’ Domain Calculations PID Controller and System: KDs2 + KPs + KI s Ka G p ( s) = 2 s LJs + (rJ + LB )s + rB + K a2 GPID ( s ) =
(
)
GD ( s ) = Gh ( s )G p ( s ) =
Ka 1 − eTs 2 s s LJs + (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 all; clc; %System Constants:******************************************************** r= input('Enter the Armature Resistance in Ohm: '); L= input('\nEnter the Armature Inductance in Henry: '); B= input('\nEnter the friction coefficeint of the mechanical system in N.m/Rad: '); k_a= input('\nEnter the Torque or Bkefm Constant N.m/Amp: '); J= input('\nEnter the Moment of Rotational Inertia (Sum of all M.R.I''s in Mech. Sys) in kg.sqr(m): '); T= input('\nEnter your Sampeling time in Sec: '); kp= input('\nEnter the PID Coef. Kp: '); ki= input('\nEnter the PID Coef. Ki: '); kd= input('\nEnter the PID Coef. Kd: '); r_t = input('\nEnter the motor''s Armature displacement in Radian: '); %*********************************************************************** num= [k_a]; denum= [L*J (r*J+L*B) (r*B+k_a^2) 0]; [num_z,denum_z]=c2dm(num,denum,T,'zoh'); %Z transform the system in S domain with 'zoh'= zero order hold kp_z=T*kp; ki_z=T*ki; kd_z=T*kd; num_pid_z = [(kp_z + ki_z + kd_z) -(kp_z + 2*kd_z) kd_z]; denum_pid_z = [1 1 0]; num_G_z = conv(num_pid_z,num_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 that you need to adjust to get the optimum point in your controller, T,Kp,Ki, Kd. This 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 methods such as: Root Locus Method, Frequency Response Method, and Analytical Design Method