State Space Model with PID controller unstable in Julia compared to Matlab

lstagner
Wed, 31 Jul 2024 17:14:13 +0000
Specific Domains

I have the following code in Matlab that creates a stable system using a simple PID controller.

%% Define system
sys = ss(A,B,C,D);

%% New state space
sys_new = sys([1379],13);

%% Define s domain
Kp = 0;
Ki = 0;   % No integrator
Kd = 278.7369;
Tf = 0;
sys_C = pid(Kp,Ki,Kd,Tf);

%% Controller design
sys_cl = feedback(sys_new,sys_C);
step(sys_cl)

which produces the following step response

The Julia version (or at least as close as i can make it is

using ControlSystems

sys = ss(A,B,C,D)
sys_new = sminreal(sys[1379,13])
Kp = 0
Ki = 0
Kd = 278.7369
Tf = 0
sys_C = pid(Kp,Ki,Kd; Tf=0.001, form=:parallel, state_space=true)
# notice the Tf has to be set to be non-zero here but not in the matlab version
sys_cl = feedback(sys_new,sys_C);

y,t = step(sys_cl);
plot(t,y[1,:])

This produces nonsense

The main difference I see in the Matlab version and the Julia version is that in the Julia version is that the PID controller needs to be converted into state_space and that requires the Tf be set to something non-zero which causes the step response to go bad. Indeed setting Tf=0.001 in the matlab version produces a similar looking response.

My question is how can I make the julia and matlab version agree?

23 posts - 5 participants