Controller update in a discrete system
Hello everyone, I have a question
I have a continuous system that updates every 0.001 seconds.
In addition to this, I have a controller that should be updated with a delay of at least 100 times the system (ie every 100 iterations it is updated)
My question is this:
Do I need to calculate the signal and its derivatives and in addition the error and its derivative with T or with dt? I’m not sure..
The system is denoted as y_pk
The required signal is denoted as y_dk
This is part of my code:
dt=0.001; %discrete time
T=0.1; %continoues time
y_d = sin(1 * time); % desired signal
dy_d = diff(y_d) / dt;
ddy_d = diff(dy_d) / dt;
%initialize:
y_dk1=0; dy_dk1=0; uk2=0; uk1=0;
firstrun=true;
for j = 1:length(time)
y_dk = y_d(j);
if mod(j, 100) == 0 ||firstrun
T=dt; % ??
dy_dk = (y_dk-y_dk1)/T; %derv of y_dk
ddy_dk = (dy_dk – dy_dk1)/T; %second derv of y_dk
ek = y_dk – y_pk;
de_k = dy_dk – dy_pk;
uk = (1/c)*(a1*dy_pk + b1*(dy_pk)^2 + a2*y_pk + b2*(y_pk)^2 +k_p*ek + k_d*de_k + ddy_dk); % u: control input
% Store data for nex step:
uk2=uk1;
uk1=uk;
firstrun=false;
end
y_pk = …. ; %update each 0.001 second (continoues time)
dy_pk = (y_pk-y_pk1)/dt; %derv of y_pk
% Store data for nex step: system
y_pk2=y_pk1;
y_pk1=y_pk;
Thank you all!! :)Hello everyone, I have a question
I have a continuous system that updates every 0.001 seconds.
In addition to this, I have a controller that should be updated with a delay of at least 100 times the system (ie every 100 iterations it is updated)
My question is this:
Do I need to calculate the signal and its derivatives and in addition the error and its derivative with T or with dt? I’m not sure..
The system is denoted as y_pk
The required signal is denoted as y_dk
This is part of my code:
dt=0.001; %discrete time
T=0.1; %continoues time
y_d = sin(1 * time); % desired signal
dy_d = diff(y_d) / dt;
ddy_d = diff(dy_d) / dt;
%initialize:
y_dk1=0; dy_dk1=0; uk2=0; uk1=0;
firstrun=true;
for j = 1:length(time)
y_dk = y_d(j);
if mod(j, 100) == 0 ||firstrun
T=dt; % ??
dy_dk = (y_dk-y_dk1)/T; %derv of y_dk
ddy_dk = (dy_dk – dy_dk1)/T; %second derv of y_dk
ek = y_dk – y_pk;
de_k = dy_dk – dy_pk;
uk = (1/c)*(a1*dy_pk + b1*(dy_pk)^2 + a2*y_pk + b2*(y_pk)^2 +k_p*ek + k_d*de_k + ddy_dk); % u: control input
% Store data for nex step:
uk2=uk1;
uk1=uk;
firstrun=false;
end
y_pk = …. ; %update each 0.001 second (continoues time)
dy_pk = (y_pk-y_pk1)/dt; %derv of y_pk
% Store data for nex step: system
y_pk2=y_pk1;
y_pk1=y_pk;
Thank you all!! 🙂 Hello everyone, I have a question
I have a continuous system that updates every 0.001 seconds.
In addition to this, I have a controller that should be updated with a delay of at least 100 times the system (ie every 100 iterations it is updated)
My question is this:
Do I need to calculate the signal and its derivatives and in addition the error and its derivative with T or with dt? I’m not sure..
The system is denoted as y_pk
The required signal is denoted as y_dk
This is part of my code:
dt=0.001; %discrete time
T=0.1; %continoues time
y_d = sin(1 * time); % desired signal
dy_d = diff(y_d) / dt;
ddy_d = diff(dy_d) / dt;
%initialize:
y_dk1=0; dy_dk1=0; uk2=0; uk1=0;
firstrun=true;
for j = 1:length(time)
y_dk = y_d(j);
if mod(j, 100) == 0 ||firstrun
T=dt; % ??
dy_dk = (y_dk-y_dk1)/T; %derv of y_dk
ddy_dk = (dy_dk – dy_dk1)/T; %second derv of y_dk
ek = y_dk – y_pk;
de_k = dy_dk – dy_pk;
uk = (1/c)*(a1*dy_pk + b1*(dy_pk)^2 + a2*y_pk + b2*(y_pk)^2 +k_p*ek + k_d*de_k + ddy_dk); % u: control input
% Store data for nex step:
uk2=uk1;
uk1=uk;
firstrun=false;
end
y_pk = …. ; %update each 0.001 second (continoues time)
dy_pk = (y_pk-y_pk1)/dt; %derv of y_pk
% Store data for nex step: system
y_pk2=y_pk1;
y_pk1=y_pk;
Thank you all!! 🙂 control, discrete system, controller MATLAB Answers — New Questions
​