State space controller implementation

8 visualizaciones (últimos 30 días)
Ahmad Alnoor
Ahmad Alnoor el 29 de Nov. de 2020
I need help understanding how to implement the state space servo controller equation
u(k) = r(k)*Kr -K*xHat(k);
in a control loop to track a constant reference input. Here, K is the controller gain
Kr is the reference scaling factor
xHat(k) is the estimated state from an prediction observer
Suppose I have the following state space model for a discrete time system:
A =[0 0.1;0 1]; B = [0.005; 0.1]; C= [1 0]; T=0.1;
K =[11.87 3.75]; Kr = 11.87; Lp = [0.2 1]'; %controller gain, scaling factor, and prediction observer gain respectively
Now, suppose I have an encoder that reads the servo motor position and returns its value in degrees as below:
y = MotorEncoder(servo); %position of the motor in degrees(output)
If i want the servo motor to track 45 degrees reference input, what changes should I make to the following code so that the tracking is achieved:
Tf = 10; %duration time
Ts = 0.1; %sampling time
t = 0:Ts:Tf; %intervals
Ns = length(t); %length of intervals
r = ones(1,Ns); %constant reference
r = 45*r; %constant input for the servo to track
K =[11.87 3.75]; Kr = 11.87; Lp = [0.2 1]';
for k = 1:Ns %control loop
y = MotorEncoder(servo); %read the position of servo (random value)
u(k) = Kr*r(k) - K*xHat(k); %controller equation to track the 45 degrees reference
xHat(k+1) = A*xHat + B*u(k) - Lp(y(k) - C*xHat(k)); %prediction observer equation updating the estimated states
end
%Steps of the loop:
% The output of the servo is read. Next the controller gain to reduce the error between the servo output and
%the reference input is calculated. After, the estimated states are updated by the predition observer
% The loop updates the k value and the next sample in computed until Ns
What am I missing?
I understand that xHat(k) are estimated states (variables), what changes should I make to the above code?
I also understand that there are better ways to find answer by using lsim(), but I am trying to understand the concept by applying it inside a loop.
Thank you in advance for your help!

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by