Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Project Report

Self Tuning Regulator Techniques for Position Control of Permanent


Magnet Stepper Motor

By

Sukumar Kamalasadan
Table of Contents

Section Description Page

1 Overview 1

2 Introduction 2

3 Dynamic Model 3

4 Static PID Control Law and Simulations 4

5 Application of the Adaptive Control Using the Self Tuning Regulators 7

5.1 Self Tuning PID Control 7

5.2 Minimum Variance Controller 9

5.3 Dead Beat Control 12

5.4 Pole Placement Controller 13

6 Conclusions and Recommendation 15

7 References 15

8 Appendix 1 16

ii
1 Overview

This project work concentrates mainly on the application of Self-Tuning Regulator techniques
with Least Square identification for Nonlinear Adaptive Control of Permanent Magnet Step Motors.

The problem of accurate positioning of permanent magnet step motors with sinusoidal flux
distribution is discussed in several papers [1] and adaptive control techniques are established. A nonlinear
model for Step Motors containing six unknown parameters discussed in R.Marino et al. [1] is considered as
the reference for our application of STR’s with LS identification techniques. This model along with the PID
Control suggested [1] has been developed as an algorithm and the system response for position error and
voltage modulus is plotted. Further the plotted graphs are compared with the one obtained in the simulation
from the mentioned paper.

The second part of the project was to find a suitable way to incorporate the following adaptive
control techniques and test them for such a model with suggested PID Control in the reference paper [1].

• Self Tuning PID Control


• Minimum Variance Control
• Time Optimal Control ( Dead Beat Control)
• Pole Placement Control

For all the above-mentioned Adaptive Control Techniques, Least Square Identification technique
has been used for identification. Logically the adaptive control techniques should improve the nonlinear
system response when compared to a static PID Control developed. The assessment was mainly on the
suitable way to apply the techniques and the performance of each of them on the improvement.

2 Introduction

Recent advances in the nonlinear Adaptive Control now make implementable complex nonlinear
control algorithms in electric drives. Several applications based on the Permanent Magnet Step Motors
especially in robotics, aerospace and manufacturing and the trend of replacing DC Motors by AC Motors
place its control in limelight. Moreover main advantages of these motors are

• Capability to deliver higher peak torque per unit weight


• Higher torque-to-inertia ratio than the DC motors
• More reliable and being brush less requires less maintenance

Since these machines are highly nonlinear and involve parameters that may vary during operation,
recently several nonlinear [2] and adaptive control [3] & [4] techniques have been successfully applied to
Permanent Magnet Stepper Motors (PMSM).

The goal of this project work is to apply the developed Self-Tuning Regulator (STR) adaptive
control techniques over a static PID control algorithm developed based on the paper R.Marino et al. [1].
Such adaptive techniques should control for accurate positioning of PMSM with unknown parameters with
the measurable states as angular position, angular speed and two-phase currents. The dynamics of PMSM
are modeled by nonlinear differential equations with sinusoidal flux distribution, which depends on six
unknown parameters, namely total inertia J, viscous friction coefficient F, torque load TL, motor torque
constant KM, Stator winding resistance R and inductance L. After knowing these parameters exactly, the
classical control is a nonlinear state feedback algorithm which is designed after performing the so-called
(d,q) transformation for the two-phase currents and voltages.

The PID control technique developed in the paper [1] is applied on a nonlinear state feedback
control that ensures asymptotic tracking of position reference signals, in any operating conditions, without
any knowledge of the six motor parameters. The key assumption of the paper requires sinusoidal flux
distribution, which is achieved by careful mechanical and electromagnetic design of the motor. When this

1
assumption is violated torque ripples are generated and a method on torque ripple reduction techniques [4]
needs to be considered in such case.

This project report is organized as follows.

Initially the dynamic model of PMSM as developed in [1] is summarized with the focus on the
model used for the analysis. The model simplification due to the sinusoidal flux distribution is also
explained in section 3. A classical non-adaptive control scheme with PID Control is reviewed next section.
Here the simulation, which is conducted in [1], is developed in the algorithmic form using MATLAB. The
model for the motor and the control law developed in this paper is used for simulation for a specific case
and the system response is compared as given in the paper.

Further, in section five the proposed Self Tuning Regulator techniques which is learnt during the
course is tested for the above model over the classical PID Control and the improvements in the responses
is analyzed. Analysis on each of the techniques is carried out comparing the simulations. Finally in section
six the report is concluded with the results and the future scope and works which can be performed.

3 Dynamic Model

Following assumptions have been considered in developing a general model for two-phase PMSM
developed in [5]. Such a model developed in [1] is discussed here.

• Linear Magnetic materials


• Symmetry of the rotor and between the two phases
• Nonlinear flux density distribution due to air gap geometry only
• Negligible magnetic hysteresis and Fault currents

Permanent magnets may be modeled by an equivalent rotor winding supplied by a fictitious current source
which is denoted by if.

The rotor shaft dynamics are given by

θ = T - Fθ
Jθ θ - TL
In which ‘J’ is the total inertia of the rotor and of the load, ‘F’ is the viscous friction coefficient, ‘TL is the
load torque and

T
ia  ia 
   
T = 1 / 2 ib * dL(θ ) / dθ ib
   
ic  ic 

Denoting the rotor angle by θ, we define the electric angle θl = pθ, which gives the main magnetic field
periodicity for a machine with ‘p’ poles symmetrically placed.

The differential equation for the current is developed as

  '  L' af (θ ) 


−1 
di / dt = Ls (θ )u − Rsi − ω Ls (θ ) + ir  '  
  θ
  L bf ( )  

in which ω = θ. The above equations constitute the dynamical model of a PMSM with both rotor and stator
salient poles. The dynamic model without saliency becomes

2
dθ / dt = ω

( )
dω / dt = K M / J − ia sin pθ + ib cos pθ − F / J * ω − TL / J

dia / dt = − R / L * ia + K M / L * ω sin pθ + Ua / L

dib / dt = − R / L * ib + K M / L * ω cos pθ + Ub / L

Considering the classical control technique based on Park’s transformation (transformation of the vectors
‘u’ and ‘i’ expressed in the fixed stator frame into vectors expressed in a frame which is rotating along the
fictitious excitation vector if directed as the d axis), the dynamics expressed in the above equations
becomes

dθ / dt = ω

dω / dt = K M / J (iq ) − F / J * ω − TL / J

did / dt = − R / L * id + p * ω * iq + Ud / L

diq / dt = − R / L * iq − p * ω * id − K M / L * ω + Uq / L

This set of equation is used for the static PID control developed.

4 Static PID Control law and Simulations

The simulation for the typical position reference trajectory θr(t) with trapezoidal speed reference ωr(t) is
given, while a constant load torque of 2 N m ( which is unknown to the controller ) is applied at t = 0.15s.

The PID control:


t
Ud = -pLωid – k4 (id – idr) – k5 ∫ [id (τ ) − id
0
r (τ )]dτ

t
Uq = KMω – k4 (iq – iqr) – k5 ∫ [iq(τ ) − iq (τ )]dτ
0
r

with
idr = 0
 
 ( ) [ ] 
 

3
The motor data
Number of phases 2
Number of pole pairs p 6
Torque constant kM 2 N m A-1
Stator Resistance R 3 Ohm
Stator Self-inductance l 0.0006 H
Total rotor-load inertia J 0.01kg.m2
Table 1: The motor data used for the simulations.

The performance of static PID control with the reference trajectory is given in the figure 1 and the tracking
of the position error and the voltage modulus is given in figure 2.

Figure 1: The Speed and Position References

Figure 2: Position and Speed Error for Static PID Control

4
The voltage modulus obtained using the simulation is shown in Figure 3.

Figure 3: The Voltage Modulus for Static PID Control

When compared to the simulation described in [1], it can be seen that the wave shape is pretty
much similar but with a slight variation at 0.35 seconds and also increase in the magnitude. This is
basically may be due to the difference in the algorithm developed as it can be seen that the logic is right.

The Control law for the static PID Control is shown in the Figure 4. These simulations acts as the reference
for the application of the STR for the problem

Figure 4: Controls Uq and Ud for static PID Control

5
5 Application of the adaptive Control using the Self Tuning Regulators

As mentioned before following Self Tuning Regulators (STR’s) have been tested along with the static PID
Control explained in the previous section.

• Self Tuning PID Control


• Minimum Variance Control
• Time Optimal Control
• Pole Placement Control

5.1 Self Tuning PID Control

In the self-tuning PID Control the adaptive control algorithm is applied along with the static PID
Controller for only the position reference. The simulation results for the position error and the speed error
are shown in the figure 5. The result shows that there is some improvement in the performance (tracking)
since the error reduces though not drastically.

Figure 5: Position and Speed Error for Self Tuning PID Control

Further the voltage modulus is plotted in this case and then assessed for the improvement. The
voltage modulus doesn’t show any drastic improvement in this case as the effect is basically in the
identification and control of the position vector, which is understandable.

Figure 6 shows the voltage modulus and the pattern. The graphs also show a straight-line
approximation not as a smooth curve, which is due to the less number of sampling time. When the
sampling time increases much high the integration tolerance limit has been achieved when working with
the ode function file and thus, the algorithm gives irratic results. This was noticed in this case and thus the
curve doesn’t show smooth response.

Figure 7 shows the control Uq and Ud the Control for self-Tuning PID. Ud shows that there is
some improvement in the control after little over 0.05 seconds and mostly it is close to zero further.

6
Figure 6: Voltage Modulus for Self Tuning PID Control

Figure 7: Controls Uq and Ud for Self Tuning PID Control

7
5.2 Minimum Variance Controller

The application of the minimum variance controller with the static PID Controller is developed as
in the code mentioned in appendix 1. The simulation step was able to increase using this controller with
Least square identification. As before the Position Error and the speed error have been plotted as in figure 8
below.

Figure 8: Position and Speed Error for Self Minimum variance Controller

Figure 9 shows the voltage modulus for this controller. It can be seen that the position error, speed
error and the voltage modulus has much more improvement and gets a more detailed curve. The reduction
in the position error is much better when compared with the speed error.

Figure 9: Voltage Modulus for Self Minimum variance Controller

8
Figure 10 shows the variation in the control parameters. As can be seen that the control Ud gives
some variation in dynamics but develops to zero in the later part of the simulation time.

Figure 10: Position and Speed Error for Self Minimum variance Controller

The identification routine in the above mentioned case is with both the controllers Ud and U and
for the position error. The same controller was tested for tracking instead of the error for the position.
Figures 11, 12 and 13 shows the simulation for that condition. It was obvious that the error identification
was much more effective when compared with tracking actual values.

Figure 11: Position and Speed Error for the output vector

9
Figure 12: Voltage modulus for Self Minimum variance Controller and for the output vector

Figure 13: Control parameters difference for Self Minimum variance Controller with direct position
control

Further the position error with change in the gama values ( weighting factor for Identification ) is
tested and it was found that there is no change in the position error or the voltage modulus when the gama
value is changed. Also the simulation was possible to be executed till 400 iterations to get less samples
from the system for minimum variance control.

10
5.3 Dead beat Control

Figure 14: Position and Speed Error for the deadbeat controller

For this proposed problem the deadbeat controller technique was found to be not that effective.
The proposed method was able to fun up to 80 sample corresponding to a step time of 0.05 seconds. The
performance of the controller for further tracking was not possible. Further more the output tracking didn’t
run due to the integration time step restriction.

The deadbeat controller for the second method (method in which the controller values are
modified during every third sample) is also analyzed. The response wasn’t changed much.

Figure 15: Voltage Modulus for the deadbeat controller

11
Figure 18 Voltage Modulus for the Pole Placement controller

Figure 19: Controllers Ud and Uq for the Pole Placement controller

It can be observed that the pole placement adaptive controller technique doesn’t change the
positional error and the speed. The performance of the controller gives the idea as the variation in the
control value at different time.

13
6 Conclusions and Recommendation

The PID Controller was able to perform the adaptive control but was restricted on the sample time
and thus accuracy. The order of the identification for the adaptive control was restricted to 2, which can be
a possible problem in finding out the better value of Theta and thus the control action.

The minimum variance control preformed the best with the variations in the error. The simulations
were performed for less samples which made it more accurate. Further both the tracking and error
variations was able to achieve on the minimum variance controller showing the depth of the techniques in
this particular case.

The time optimal controller was better than the PID controller, in the sense of much better sample
time but was not able to perform for simulations time of 0.001 seconds which was achievable by minimum
variance controller. Further the method of the control U calculation after ever third samples gave the same
results

Pole Placement Controller applied for the position error generates a control U that is close to zero
or around that. This concludes that this control adaptive control technique is not as efficient as the other
techniques. Further the tracking response was similar even though the poles are chosen at different values.

Finally it is observed that the simulation of the system dynamics was not as detailed as in the case
mentioned in [1] which shows that a better way of generating the system model to incorporate details needs
to be done if we wish to proceed for searching better techniques. These parts of the work have to be
performed exploring the capabilities of Minimum variance controller as future scope of work.

7 References

1. Nonlinear adaptive Control of Permanent Magnet Step Motors. R Marino, S Peresada and P Tomei
Automatica vol 31, No 11 pp-1595-1604, 1995.
2. Application of nonlinear control methods to the positioning of a permanent magnet stepper motor.
Bodson, M J and J Chiasson (1989). In Proc. 28th IEEE Conf. On Decision and Control, Tampa, FL.
Pp. 531-532
3. Nonlinear adaptive torque-ripple cancellation for step mtoors. Chen D and B Paden. In Proc. 29th IEEE
Conf. On Decision and Control. Honolulu, HI, pp.3319-3324.
4. Position Control of a PM stepper motor by exact linearization. IEEE Trans. Automation and Control,
AC 36, 620-625.
5. Adaptive Control of Stepper motors via nonlinear extended matching. Marino R and P Tomei (1993)
In Proc. IFAC Workshop on Motion Control of Intelligent Automation, Perugia, Italy, pp.135-139.

14
Appendix 1

Case 1

Code for the Static PID Controller developed using model in [1]
%===================================================
% PID Control equation testing from R.Marino et al.
%===================================================

close all;
clear all;

ph = 2;
p = 6;
Km = 2;
R = 3;
L = 0.006;
J = 0.01;
Jn = J;
Kmn = Km;
Rn = R;
T = 0.0005;
k1 = 80000;
k2 = 65*k1;
k3 = 500;
k4 = L/T;
k5 = R/T;

n=2; %estimated model order


t_s=0.001; %time interval between two samplings
k0=n;
gama=1; %weighting fator
finish_point=500; %finish point of calculation
%thr = 15; %provided step instead of ramp
%omr = 50; %Provided step instead of trapeziod
beta=100000; %Select initial values of P
P=beta*eye(2*n);
alpha=0.5;
Theta = 0.1*ones(2*n,1);
idr = 0;

for k=1:n;
Uq(k)=0;
Ud(k)=0;
U(k)=0;
Y_out(k)=0;
Ym(k)=0;
id(k)=0;
iqr(k)=0;
end;

%Global to id_theta.m
global k U Theta n gama P;

k0=n+1;
Y0 =[0;0;0;0;0;0;0;0;0];

%Global to id_theta.m
global k U Theta n gama P;

%Global to process
global k Ud Uq
%%%%%% Main Algorithm %%%%%%%%%%%
for k=k0:finish_point

%system processing,get Y(k)


tstart=(k-k0)*t_s;
tfinal=tstart+t_s;
[t,Y]=ode23T('smot1',[tstart tfinal],Y0);
[m,l]=size(Y);

15
thr(k) = Y(m,1);
omr(k) = Y(m,2);
Y_out(k)=Y(m,3); % finding out the output
th(k)=Y(m,3);
ther(k)=th(k)-thr(k);
om(k)=Y(m,4); % Omega value after one sample period
omer(k)=om(k)-omr(k);
id(k)=Y(m,5); % Id value after one sample period
iq(k)=Y(m,6); % Iq value after one sample period
iqr(k)=Y(m,7);
Ud(k) = Y(m,8);
Uq(k) = Y(m,9);
Y0=Y(m,:); % Changing the Initial values of Y
end;

subplot(2,1,1),plot(0:t_s:(k-1)*t_s,ther,'b'); % Plotting the values of Y_out


hold on
grid on
title('Theta Error')
figure(1);
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omer,'b');
hold on
grid on
title('Omega Error');
figure(2);
subplot(2,1,1),plot(Uq,'b');
hold on
grid on
title('Uq');
subplot(2,1,2),plot(Ud,'b');
hold on
grid on
title('Ud');
figure(3);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,thr,'b');
hold on
grid on
title('omegaref');
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omr,'b');
hold on
grid on
title('thetaref');
figure(4);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,om,'b');
hold on
grid on
title('omega');
figure(5);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,th,'b');
hold on
grid on
title('theta');

Code for the function Model for static PID Controller


% Stepper Motor Model

function Ydot = smot1(t,Y);

global k U
ph = 2;
p = 6;
%Km = 2;
Km = 2*0.5;
%R = 3;
R = 3/2;
%L = 0.006;
L = 0.006*1.5;
%J = 0.01;
J = 0.01*1.5;

16
Jn = J;
Kmn = Km;
Rn = R;
T = 0.0005;
%F = 0.6;
F = 0.6*0.5;
k1 = 80000;
k2 = 65*k1;
k3 = 500;
k4 = L/T;
k5 = R/T;
%thr = 15; %provided step instead of ramp
if t >=0.15;
TL = 2;
else
TL=0;
end

Ydot (1)= 13/0.3;% thr

if t > 0.3
Ydot(1) = 0;
end

if t < 0.06

Ydot (2) = 50/0.06;

elseif 0.06 < t < 0.26


Ydot (2) = 0;
end

if t > 0.26 & t < 0.32


Ydot (2) = - (50/0.06);
end

Ydot(3) = Y(4); % theta


Ydot(4) = (Km/J)*Y(6)-(F/J)*Y(4)-TL/J; % omega
Ydot(5) = -(R/L)*Y(5)+p*Y(4)*Y(6)+ (Y(8))/L;% id
Ydot(6) = -(R/L)*Y(6)-p*Y(4)*Y(5)-(Km/L)*Y(4)+ Y(9)/L;% iq
Ydot(7) = -(J/Km)*(k1*(Ydot(3)-Ydot(1))+k2*(Y(3)-Y(1))+k3*(Ydot(4)-Ydot(2)));% iqr
Ydot(8) = -p*L*(Y(4)*Ydot(6)+Ydot(4)*Y(6))-k4*Ydot(5)-k5*Y(5);% Ud
Ydot(9) = Km*Ydot(4)-k4*(Ydot(6)-Ydot(7))-k5*(Y(6)-Y(7)); % Uq

Ydot = Ydot';

Case 2

Code for the Self-Tuning PID Control

%===================================================
% PID Control equation testing from R.Marino et al.
%===================================================

close all;
clear all;

ph = 2;
p = 6;
Km = 2;
R = 3;
L = 0.006;
J = 0.01;
Jn = J;
Kmn = Km;
Rn = R;
T = 0.0005;
k1 = 80000;
k2 = 65*k1;
k3 = 500;

17
k4 = L/T;
k5 = R/T;

n=2; %estimated model order


t_s=0.01; %time interval between two samplings
k0=n;
gama=0.9; %weighting fator
finish_point=50; %finish point of calculation
beta=100000; %Select initial values of P
P=beta*eye(2*n);
alpha =0.7;
Theta = [-0.7888;
0.5236;
0.0520;
-0.0256];
%Theta = [-2.0055;
% 1.0077;
% -0.0000;
% -0.0000];

idr = 0;

for k=1:n;
Uq(k)=0;
Ud(k)=0;
U(k)=0;
Y_out(k)=0;
Ym(k)=0;
id(k)=0;
iqr(k)=0;
end;

k0=n+1;
Y0 =[0;0;0;0;0;0;0;0;0];

%Global to id_theta.m
global k U Ud Theta n gama P;

%Global to process
global k U Ud Uq
%%%%%% Main Algorithm %%%%%%%%%%%
for k=k0:finish_point

%system processing, get Y(k)


tstart=(k-k0)*t_s;
tfinal=tstart+t_s;
[t,Y]=ode23('smot1',[tstart tfinal],Y0);
[m,l]=size(Y);
thr(k) = Y(m,1);
omr(k) = Y(m,2);
Y_out(k)=Y(m,3)-Y(m,1); % finding out the output
%Y_out(k)=Y(m,3); % finding out the output
th(k)=Y(m,3);
ther(k)=th(k)-thr(k);
om(k)=Y(m,4); % Omega value after one sample period
omer(k)=om(k)-omr(k);
id(k)=Y(m,5); % Id value after one sample period
iq(k)=Y(m,6);% Iq value after one sample period
iqr(k)=Y(m,7);
Ud(k) = Y(m,8);
Uq(k) = Y(m,9);
Y0=Y(m,:); % Changing the Initial values of Y

%system identification, get Theta


Theta=id_theta(Y_out,Theta);
Thetak(k,:)=Theta';
a1=Theta(1);
a2=Theta(2);
b1=Theta(3);
b2=Theta(4);

18
%Calculate Ym(k+1)
Ym(k)=0;
for i=1:n;
Ym(k)=Ym(k)-Theta(i)*Y_out(k-i)+Theta(i+n)*U(k-i);
end;

% calculate for r1,s0,s1,s2


x=1-a1+alpha+a1*alpha;
y=a1-a2+a1*alpha*alpha+a2*alpha*alpha;
z=a2+a2*alpha^3;
A=[1,b1,0,0;a1-1,b2,b1,0;a2-a1,0,b2,b1;-a2,0,0,b2];
B=[x;y;z;0];
Result=inv(A)*B;
r1=Result(1);
s0=Result(2);
s1=Result(3);
s2=Result(4);

%calculate for k_p, k_d, k_i


k_i=-(s0+s1+s2)/t_s;
k_p=(s1+2*s2)/(1+r1);
k_d=t_s*((r1*s1)-(1-r1)*s2)/(1+r1);

%calculate for U(k)


%U(k)=-(t_s*k_i)*thr(k)+(t_s*k_i+k_d/t_s+k_p) * Y_out(k) - (2*k_d/t_s+k_p-r1*k_p)...
% * Y_out(k-1) + (k_d/t_s-r1*k_p) * Y_out(k-2) - (r1-1) * U(k-1) + r1*U(k-2);

U(k)=(t_s*k_i+k_d/t_s+k_p) * Y_out(k) - (2*k_d/t_s+k_p-r1*k_p)...


* Y_out(k-1) + (k_d/t_s-r1*k_p) * Y_out(k-2) - (r1-1) * U(k-1) + r1*U(k-2);

end;

subplot(2,1,1),plot(0:t_s:(k-1)*t_s,ther,'b'); % Plotting the values of Y_out


hold on
grid on
title('Theta Error')
figure(1);
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omer,'b');
hold on
grid on
title('Omega Error');
figure(2);
subplot(2,1,1),plot(Uq,'b');
hold on
grid on
title('Uq');
subplot(2,1,2),plot(Ud,'b');
hold on
grid on
title('Ud');
figure(3);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,thr,'b');
hold on
grid on
title('omegaref');
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omr,'b');
hold on
grid on
title('thetaref');
figure(4);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,om,'b');
hold on
grid on
title('omega');
figure(5);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,th,'b');
hold on
grid on
title('theta');

19
Case 3

Code for the Minimum variance Control

%==============================================================
% Minimum Variance Control equation testing from R.Marino et al.
%==============================================================

close all;
clear all;

ph = 2;
p = 6;
Km = 2;
R = 3;
L = 0.006;
J = 0.01;
Jn = J;
Kmn = Km;
Rn = R;
T = 0.0005;
k1 = 80000;
k2 = 65*k1;
k3 = 500;
k4 = L/T;
k5 = R/T;

n=8; %estimated model order


t_s=0.001; %time interval between two samplings
k0=n;
gama=1; %weighting fator
finish_point=500; %finish point of calculation
beta=100000; %Select initial values of P
P=beta*eye(2*n);
alpha =0.9;
idr = 0;

for k=1:n;
Uq(k)=0;
Ud(k)=0;
U(k)=0;
Y_out(k)=0;
Ym(k)=0;
id(k)=0;
iqr(k)=0;
end;

k0=n+1;
Y0 =[0;0;0;0;0;0;0;0;0];

%Global to id_theta.m
global k U Ud Theta n gama P;

%Global to process
global k U Ud Uq
%%%%%% Main Algorithm %%%%%%%%%%%
for k=k0:finish_point

%system processing, get Y(k)


tstart=(k-k0)*t_s;
tfinal=tstart+t_s;
[t,Y]=ode23('smot1',[tstart tfinal],Y0);
[m,l]=size(Y);
thr(k) = Y(m,1);
omr(k) = Y(m,2);
Y_out(k)=Y(m,3)-Y(m,1); % finding out the output
%Y_out(k)=Y(m,3); % finding out the output
th(k)=Y(m,3);
ther(k)=th(k)-thr(k);

20
om(k)=Y(m,4); % Omega value after one sample period
omer(k)=om(k)-omr(k);
id(k)=Y(m,5); % Id value after one sample period
iq(k)=Y(m,6);% Iq value after one sample period
iqr(k)=Y(m,7);
Ud(k) = Y(m,8);
Uq(k) = Y(m,9);
Y0=Y(m,:); % Changing the Initial values of Y

%system identification, get Theta


if k==k0
% Theta = [-1.9460;
% 0.9882;
% 0.0063;
%-0.0175;
%-0.0233;
% 0.0066;
%-0.0069;
% 0.0063;
% 0.0000;
% 0.0000;
%-0.0000;
% 0.0000;
% 0.0000;
% 0.0000;
%-0.0000;
% 0.0000];
Theta = 0.1*ones(2*n,1);
%Theta=[0.1;0.1;0.1;0.1;0.1;0.1];
else
Theta=id_theta(Y_out,Theta);
end
Thetak(k,:)=Theta';
%Calculate Ym(k+1)
Ym(k)=0;
for i=1:n;
Ym(k)=Ym(k)-Theta(i)*Y_out(k-i)+Theta(i+n)*U(k-i);
end;

sum=Theta(1)*Y_out(k);
for i=1:n-1
sum=sum+Theta(i+1)*Y_out(k-i)-Theta(n+i+1)*U(k-i);
end
U(k)=sum/Theta(n+1);
if U(k)>500;
U(k)=500;
elseif U(k)<-500;
U(k)=-500;
end;

end;

subplot(2,1,1),plot(0:t_s:(k-1)*t_s,ther,'b'); % Plotting the values of Y_out


hold on
grid on
title('Theta Error')
figure(1);
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omer,'b');
hold on
grid on
title('Omega Error');
figure(2);
subplot(2,1,1),plot(Uq,'b');
hold on
grid on
title('Uq');
subplot(2,1,2),plot(Ud,'b');
hold on
grid on
title('Ud');

21
figure(3);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,thr,'b');
hold on
grid on
title('omegaref');
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omr,'b');
hold on
grid on
title('thetaref');
figure(4);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,om,'b');
hold on
grid on
title('omega');
figure(5);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,th,'b');
hold on
grid on
title('theta');

Case 4

Code for the Dead Beat Control

%=========================================================================
% Dead Beat Control equation testing from R.Marino et al.
%=========================================================================

close all;
clear all;

ph = 2;
p = 6;
Km = 2;
R = 3;
L = 0.006;
J = 0.01;
Jn = J;
Kmn = Km;
Rn = R;
T = 0.0005;
k1 = 80000;
k2 = 65*k1;
k3 = 500;
k4 = L/T;
k5 = R/T;

n=8; %estimated model order


t_s=0.005; %time interval between two samplings
k0=n;
gama=1; %weighting fator
finish_point=100; %finish point of calculation
beta=100000; %Select initial values of P
P=beta*eye(2*n);
Theta = 5*ones(2*n,1);
%Theta = [-1.1738;
% 0.5145;
% -0.0308;
% 0.0139;
%0.0131;
%0.0280;
%-0.0233;
% 0.0633;
% 0.0000;
% 0.0000;
%-0.0000;
% 0.0000;
% 0.0000;
% -0.0000;
%-0.0000;

22
%-0.0000 ];

idr = 0;

for k=1:n;
Uq(k)=0;
Ud(k)=0;
U(k)=0;
Y_out(k)=0;
Ym(k)=0;
id(k)=0;
iqr(k)=0;
end;

%Global to id_theta.m
global k U Ud Theta n gama P;

k0=n+1;
Y0 =[0;0;0;0;0;0;0;0;0];

%Global to process
global k U Ud
%%%%%% Main Algorithm %%%%%%%%%%%
for k=k0:finish_point

%system processing, get Y(k)


tstart=(k-k0)*t_s;
tfinal=tstart+t_s;
[t,Y]=ode23('smot1',[tstart tfinal],Y0);
[m,l]=size(Y);
thr(k) = Y(m,1);
omr(k) = Y(m,2);
Y_out(k)=Y(m,3)-Y(m,1); % finding out the output
%Y_out(k)=Y(m,3); % finding out the output
th(k)=Y(m,3);
ther(k)=th(k)-thr(k);
om(k)=Y(m,4); % Omega value after one sample period
omer(k)=om(k)-omr(k);
id(k)=Y(m,5); % Id value after one sample period
iq(k)=Y(m,6);% Iq value after one sample period
iqr(k)=Y(m,7);
Ud(k) = Y(m,8);
Uq(k) = Y(m,9);
Y0=Y(m,:); % Changing the Initial values of Y

%system identification, get Theta


Theta=id_theta(Y_out,Theta);

%claculate p's and q's


A=Theta(1:n);
B=Theta(n+1:2*n);
q0=1/sum(B);
q=A/sum(B);
p=B/sum(B);

%calculate for U(k)


U(k)=q0*(Y_out(k));
for i=1:n;
%U(k)=U(k)+q(i)*(thr(k)-Y_out(k-i))+p(i)*U(k-i);
U(k)=U(k)+q(i)* -Y_out(k-i)+p(i)*U(k-i);

end
%Calculate Ym(k+1)
Ym(k)=0;
for i=1:n;
Ym(k)=Ym(k)-Theta(i)*Y_out(k-i)+Theta(i+n)*U(k-i);
end;

end;

23
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,ther,'b'); % Plotting the values of Y_out
hold on
grid on
title('Theta Error')
figure(1);
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omer,'b');
hold on
grid on
title('Omega Error');
figure(2);
subplot(2,1,1),plot(Uq,'b');
hold on
grid on
title('Uq');
subplot(2,1,2),plot(Ud,'b');
hold on
grid on
title('Ud');
figure(3);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,thr,'b');
hold on
grid on
title('omegaref');
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omr,'b');
hold on
grid on
title('thetaref');
figure(4);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,om,'b');
hold on
grid on
title('omega');
figure(5);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,th,'b');
hold on
grid on
title('theta');

Case 5

Code for the Pole Placement Control

%===================================================
% Pole Placement Control equation testing from R.Marino et al.
%===================================================

close all;
clear all;

ph = 2;
p = 6;
Km = 2;
R = 3;
L = 0.006;
J = 0.01;
Jn = J;
Kmn = Km;
Rn = R;
T = 0.0005;
k1 = 80000;
k2 = 65*k1;
k3 = 500;
k4 = L/T;
k5 = R/T;

n=8; %estimated model order


t_s=0.001; %time interval between two samplings
k0=n;

24
gama=0.95; %weighting fator
finish_point=400; %finish point of calculation
beta=100000; %Select initial values of P
P=beta*eye(2*n);
alpha =0.9;
idr = 0;

for k=1:n;
Uq(k)=0;
Ud(k)=0;
U(k)=0;
Y_out(k)=0;
Ym(k)=0;
id(k)=0;
iqr(k)=0;
F(k)=0;
thr(k)=0;

end;

k0=n+1;
Y0 =[0;0;0;0;0;0;0;0;0];

%Theta = 0.1 * ones(2*n,1);


%Theta = [-1.8110;
% 0.8052;
% 0.0361;
%-0.0023;
% 0.0083;
% 0.0012;
% 0.0380;
%-0.0415;
%-0.0881;
%-0.1111;
%-0.1588;
%-0.2026;
%-0.1262;
%-0.0646;
%-0.1826;
%-0.5957];

Theta =[-1.9360;
0.6903;
0.2605;
0.0402;
-0.0022;
0.0217;
0.0354;
-0.0938;
0.3316;
0.2057;
0.1345;
0.1178;
0.0805;
0.0114;
0.0615;
0.0303];

%Global to id_theta.m
global k U Ud Theta n gama P;

%Global to process
global k U Ud
%%%%%% Main Algorithm %%%%%%%%%%%
for k=k0:finish_point

%system processing, get Y(k)


tstart=(k-k0)*t_s;
tfinal=tstart+t_s;
[t,Y]=ode23('smot1',[tstart tfinal],Y0);
[m,l]=size(Y);

25
thr(k) = Y(m,1);
omr(k) = Y(m,2);
Y_out(k)=Y(m,3)-Y(m,1); % finding out the output
%Y_out(k)=Y(m,3); % finding out the output
th(k)=Y(m,3);
ther(k)=th(k)-thr(k);
om(k)=Y(m,4); % Omega value after one sample period
omer(k)=om(k)-omr(k);
id(k)=Y(m,5); % Id value after one sample period
iq(k)=Y(m,6);% Iq value after one sample period
iqr(k)=Y(m,7);
Ud(k) = Y(m,8);
Uq(k) = Y(m,9);
Y0=Y(m,:); % Changing the Initial values of Y

Theta=id_theta(Y_out,Theta);
Thetak(k,:)=Theta';

%Creation of Poles from the Shifted uncontrolled System


Poles=roots([1;Theta(1:n)]);
Poles=[zeros(n-1,1);0.95*Poles];
RD=poly(Poles)';
for i=1:2*n;
D(i,1)=RD(2*n+1-i);
end;
%in real application, collect Y(k) and U(k) here
M=diopha(Theta,D);
%calculate U(k)
sum = M(2*n)*Y_out(k-1);
for i=1:n-1;
sum=sum+M(2*n-i)*Y_out(k-i-1)-M(n-i)*F(k-i);
end;
F(k)=sum/M(n);
a=1; b=0; c=0; d=0;

for i=1:n;
a=a+Theta(i);
b=b+Theta(n+i);
c=c+M(i);
d=d+M(n+i);
end;
K0=(c*a+d*b)/(c*b);
%U(k)=K0*thr(k)-F(k);
U(k)=-F(k);

Ym(k)=0;

%Calculate Ym
Ym(k)=0;
for i=1:n;
Ym(k)=Ym(k)-Theta(i)*Y_out(k-i)+Theta(i+n)*U(k-i);
end;
end;

Theta

subplot(2,1,1),plot(0:t_s:(k-1)*t_s,ther,'b'); % Plotting the values of Y_out


hold on
grid on
title('Theta Error')
figure(1);
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omer,'b');
hold on
grid on
title('Omega Error');
figure(2);
subplot(2,1,1),plot(Uq,'b');
hold on
grid on
title('Uq');

26
subplot(2,1,2),plot(Ud,'b');
hold on
grid on
title('Ud');
figure(3);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,thr,'b');
hold on
grid on
title('omegaref');
subplot(2,1,2),plot(0:t_s:(k-1)*t_s,omr,'b');
hold on
grid on
title('thetaref');
figure(4);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,om,'b');
hold on
grid on
title('omega');
figure(5);
subplot(2,1,1),plot(0:t_s:(k-1)*t_s,th,'b');
hold on
grid on
title('theta');

Code for the function for developing diaphontine equations for Pole Placement Controller

%=======================================================================
% Script for finding out the diaphontine calculation (filename diopha.m)
%=======================================================================
function M=diopha(Theta,D);

global n E Theta
A=[1;Theta(1:n)];
B=[0;Theta(n+1:2*n)];
%construct E
for i=1:2*n;
for j=1:n;
if j>i|i>j+n
E(i,j)=0;
else
E(i,j)=A((n+1)-(i-j));
end;
end;
for j=n+1:2*n;
if j-n>i|i>j
E(i,j)=0;
else
E(i,j)=B(1-(i-j));
end;
end;
end;

M=inv(E)*D;

Code for the function Model for all the STR’s

% Stepper Motor Model

function Ydot = smot1(t,Y);

global k U Ud Uq
ph = 2;
p = 6;
Km = 2;
R = 3;
L = 0.006;
J = 0.01;
Jn = J;

27
Kmn = Km;
Rn = R;
T = 0.0005;
F = 0.06;
k1 = 80000;
k2 = 65*k1;
k3 = 500;
k4 = L/T;
k5 = R/T;
if t >=0.15;
TL = 2;
else
TL=0;
end

Ydot (1)= 13/0.3;% thr

if t > 0.3
Ydot(1) = 0;
end

if t < 0.06

Ydot (2) = 50/0.06;

elseif 0.06 < t < 0.26


Ydot (2) = 0;
end

if t > 0.26 & t < 0.32


Ydot (2) = - (50/0.06);
end

Ydot(3) = Y(4); % theta


Ydot(4) = (Km/J)*Y(6)-(F/J)*Y(4)-TL/J; % omega
Ydot(5) = -(R/L)*Y(5)+p*Y(4)*Y(6)+ (Y(8)/L)+U(k-1);% id
Ydot(6) = -(R/L)*Y(6)-p*Y(4)*Y(5)-(Km/L)*Y(4)+ Y(9)/L;% iq
Ydot(7) = -(J/Km)*(k1*(Ydot(3)-Ydot(1))+k2*(Y(3)-Y(1))+k3*(Ydot(4)-Ydot(2)));% iqr
Ydot(8) = -p*L*(Y(4)*Ydot(6)+Ydot(4)*Y(6))-k4*Ydot(5)-k5*Y(5);% Ud
Ydot(9) = Km*Ydot(4)-k4*(Ydot(6)-Ydot(7))-k5*(Y(6)-Y(7)); % Uq

Ydot = Ydot';

Code for the function Identification for all the STR’s

%=========================================================================
% Script for Identification with least square (file name id_theta.m)
%=========================================================================
function Theta=id_theta(Y_out,Theta);

global k U Ud Theta n gama P;

%Define X
for i=1:n;
X(i,1)= -Y_out(k-i);
end;
for i=n+1:n+n;
X(i,1)=U(k+n-i)+Ud(k+n-i);
%X(i,1)=U(k+n-i);

end;

K=P*X/(gama+X'*P*X);
Theta=Theta+K*(Y_out(k)-X'*Theta);
P=1/gama*(eye(2*n)-K*X')*P;

28

You might also like