1st Lecture Mechatronics Application 2
1st Lecture Mechatronics Application 2
Lecture No. 1
• PID controller
• Control of DC motor with Encoder
Dr. Eng. Essa Alghannam
Ph.D. Degree in Mechatronics
Engineering
ميكاترونيك – سنة رابعة
2023
• This signal (u) will be sent to the plant, and the new
output (Y) will be obtained.
t de(t )
u (t ) = K p e(t ) + K i e( ) d + K d
0 dt
• This new output (Y) will be sent back to the sensor again to find the new error signal (e).
• The controller takes this new error signal and computes its derivative and its integral again. This
process goes on and on.
Kp = Proportional gain
Ki K d s 2 + K p s + Ki
KI = Integral gain Kp + + Kd s =
s s
Kd = Derivative gain
s = tf('s');
C = Kp + Ki/s + Kd*s
• or
C1 = pid(Kp,Ki,Kd)
C=tf(C1)
Peak time
Controlled Reference
variable
Time
Steady-state error is defined as the difference between the input and output of a system in the limit as time
goes to infinity (i.e. when the response has reached the steady state). The steady-state error will depend on
the type of input (step, ramp, etc) as well as the system type (0, I, or II).
We define rise time as the time it takes to get to 90% of steady-state value (of a step response)
Delay time (td) is the time required to reach at 50% of its final value by a time response signal during its
first cycle of oscillation.
Decrease
Ki Increase Increase Decrease
In fact, changing one of these variables can change the effect of the other
two. For this reason, the table should only be used as a reference when
you are determining the values for Ki, Kp and Kd
In general, the torque generated by a DC motor is proportional to the armature current and the strength of the
magnetic field. In this example we will assume that the magnetic field is constant and, therefore, that the motor torque
𝑇 is proportional to only the armature current 𝑖 by a constant factor 𝑘𝑡 (armature constant) as shown in the equation
below. This is referred to as an armature-controlled motor.
T = kt i
The back emf, 𝑒 , is proportional to the angular velocity of the shaft by a constant factor 𝑘𝑒 (motor
constant).
e = ke
In SI units, the motor torque and back emf constants are equal, that is, 𝑘𝑡 = 𝑘𝑒 ; therefore, we will use 𝐾 to represent
both the motor torque constant and the back emf constant.
J + b = Ki
di
L + Ri = V − K
dt
I (s) =
( Js + b ) s ( s )
K
( Ls + R ) I ( s ) = V − Ks ( s )
( Js + b ) s ( s )
( Ls + R ) = V − Ks ( s )
K
4/30/2023 Dr. Eng. Essa Alghannam
By eliminating I(s) we can get the following open-loop transfer function, where the rotational speed is the
output and the voltage is the input
( Js + b )
( Ls + R ) + K s ( s ) = V
K
( Ls + R ) ( Js + b ) + K 2 V V
= =
K s ( s ) (s)
(s) K rad / s
=
V ( Ls + R ) ( Js + b ) + K 2 v
U = V
= A X + B U
X X =
Y = C X + D U i
Y =
• In state-space form, the governing equations above can be expressed by choosing the rotational
speed and electric current as the state variables. Again the armature voltage is treated as the input and
the rotational speed is chosen as the output.
b K
− 0
d J
+ 1 V
J
=
dt i K R i
− − L
L
L
Y = 1 0 + 0 V
i
Transfer function
You can access the Linear System Analyzer also by going to the APPS
tab of the MATLAB toolstrip and clicking on the app icon under Control
System Design and Analysis, or by the following command:
In the command below, the string 'step' passed to the function specifies
to generate a unit step response plot for the system P_motor.
The range of numbers 0:0.1:5 specify that the step response plot should
include data points for times from 0 to 5 seconds in steps of 0.1 seconds. 'Step Response for the Open Loop System'
From the plot we see that when 1 volt is applied to the system:
• the motor can only achieve a maximum speed of 0.1 rad/sec, ten times smaller than our desired
speed.
• Also, it takes the motor 3 seconds to reach its steady-state speed; this does not satisfy our 2 seconds
settling time criterion.
Let's first try using a proportional controller with a gain of 100. Add the following code to the end of your m-file:
Kp=100;
numa=Kp*num;
dena=den;
To determine the closed-loop transfer function, we use the cloop command. Add the following line to your m-file:
[numac,denac]=cloop(numa,dena);
Note that [numac,denac] are the numerator and the denominator of the overall closed-loop transfer function.
t=0:0.01:5;
figure
step(numac,denac,t)
title('Step response with Proportion Control')
t ) de(t
u (t ) = K p e(t ) + K i e( ) d + K d
0 dt