I made this Matlab script to implement a dynamical system with full state feedback and integral action.
Maybe I'm wrong in implementing the integral action because the system diverges.
First I converted the continuous time system into discrete time. Then I extended the state and computed the gain to implement full state feedback and integral action.
Probably there is an error in how the integral action is implemented in
Shouldn't "integral in discrete time" simply be the previous sample?
clear; close all; clc; A = [ -0.313 56.7 0 -0.0139 -0.426 0 0 56.7 0]; B = [0.232 0.0203 0]; C = [0 0 1]; %conversion to descrete time T = .1; sys = ss(A, B, C, 0); sysd = c2d(sys, T); Ad = sysd.A; Bd = sysd.B; Cd = sysd.C; %extension A_ext = [ Ad [0 0 0]' -Cd 1 ]; B_ext = [Bd 0]; %desidered poles p_des = [0.5 0.501 0.502 0.503]; K = -place(A_ext, B_ext, p_des); Kr = K(1:3); Ki = K(4); N = 100; %desidered output yd = 0.05; x(:, 1) = [0 0 0]'; u(:, 1) = yd * Ki + Kr * x(:, 1); %(yd - 0) * Ki + Kr * x(:, 1) x(:, 2) = Ad * x(:, 1) + Bd * u(:, 1); y(:, 1) = Cd * x(:, 1); for i=2:N u(:, i) = (yd - y(:, i - 1)) * Ki + Kr * x(:, i); if (i < N) x(:, i + 1) = Ad * x(:,i) + Bd * u(:, i); end y(:, i) = Cd * x(:, i); end k = 1:N; plot(k, x');
Any help would be appreciated.