我有 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
其中 x1 是从 arduino 读取的,我必须计算 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:我有不需要的其他变量,以使我的代码可读