在h = dt的真实系统中,如何将Euler方法用于ODE一阶?

时间:2019-05-15 10:36:45

标签: matlab ode control-theory

我有2个ODE可以实时计算:

x1_est'=-l1*x1_est-(Kmi*Ko/Kt)*x2_est + 0*u +l1*x1
x2_est'=-l2*x1_est-(1/Tm)*x2_est +(Km*Kt/Tm)*u +l2*x1

从arduino读取x1,我必须这样计算x1_est和x2_est

x1_est -> x1 and
x2_est -> x2

当我在行>> x1old = x1new中注释掉x1的估计值时:x1new(= x1_est),观察者会使用x1_est,但永远不会使用x2_est

注意:这是控制理论中观察者的实现,其中l1,l2的给出是为了使观察者足够快(根据a1和a2)

function [x1] = lab41(u,a1,a2)

%OBSERVER
%This function is applied to arduino
%Observer implementation assuming y,u is known
%Give u(=7), a1, a2 so as s^2 +a1*s+a2 is the desired poly of A-L*C
%Run  lab4(7,60,900)

Tm=0.507;
Kmi=1/36;
Km=306;
Kt=0.003;
Ko=0.24;

l1=a1-1/Tm
l2=((l1/Tm -a2)*(Kt)) / (Kmi*Ko)

V_7805=5.48;
Vref_arduino=5;

a=arduino('COM3');

% OUTPUT ZERO CONTROL SIGNAL TO STOP MOTOR  %
analogWrite(a,6,0);
analogWrite(a,9,0);

positionData = [];
velocityData = [];
positionEstData = [];
velocityEstData = [];
timeData = [];

timeData = [timeData 0];
positionEstData = [positionEstData 0]; %INITIAL VALUE = 0
velocityEstData = [velocityEstData 0]; %INITIAL VALUE = 0

close all
disp(['Connect cable from Arduino to Input Power Amplifier and then press enter to start controller']);
pause()

%START CLOCK RUN THE LOOP FOR 5sec
t=0;
tic
%------------------------------------------START LOOP-------------------------------------------------------
while(t<5)

velocity=analogRead(a,3);
position=analogRead(a,5);
t=toc;
x1=3*Vref_arduino*position/1024; %REAL POSITION & OUTPUT y
x2=2*(2*velocity*Vref_arduino/1024- V_7805); %REAL VELOCITY
y=x1;

x1_est=(t-timeData(end)) * (-l1*positionEstData(end) - Kmi*Ko*velocityEstData(end)/Kt + 0*u + l1*y) + positionEstData(end);       %POSITION ESTIMATION VIA EULERS METHOD
x2_est=(t-timeData(end)) * (-l2*positionEstData(end) - velocityEstData(end)/Tm + Km*Kt*u/Tm + l2*y) + positionEstData(end);      %VELOCITY ESTIMATION VIA EULERS METHOD

%Write u to arduino u=7 >0
analogWrite(a,6,0);
analogWrite(a,9,min(round(u/2*255/ Vref_arduino) , 255));


timeData = [timeData t];
positionData = [positionData x1]; %REAL X1
velocityData = [velocityData x2]; %REAL X2
positionEstData = [positionEstData x1_est]; %ESTIMATED X1
velocityEstData = [velocityEstData x2_est]; %ESTIMATED X2

end
%---------------------------------------END LOOP-------------------------------------------------------

disp(['End of control Loop. Press enter to see diagramms']);
pause()

% OUTPUT ZERO CONTROL SIGNAL TO STOP MOTOR  %
analogWrite(a,6,0);
analogWrite(a,9,0);

figure
plot(timeData,positionData,'-r',   timeData,positionEstData,':b');
legend('x1','x1_{est}')
xlabel('Time(sec)')

figure
plot(timeData,velocityData,'-r',   timeData,velocityEstData,':b');
legend('x2','x2_{est}')
xlabel('Time(sec)')


disp('Disonnect cable from Arduino to Input Power Amplifier and then press enter to stop controller');
pause();

注意2:为了使我的代码更具可读性,我还有其他一些不需要的变量

0 个答案:

没有答案