Adding PID controller to a MIMO state space system

victor
Fri, 15 Nov 2024 14:08:32 +0000
Modelling & Simulations

I have a state space process with two inputs and one output. The inputs are highly coupled. I would like to add a PID controller to one of the inputs with the output as measurement value. But I’m having a hard time with the feedback function. Could any one guide me in the right direction?

Quick example code:

using ControlSystemsBase, Plots
# Define the state space system
A = [1.0 0.5; 0.2 0.8]
B = [1.0 0.3; 0.4 1.1]
C = [2.0 1.5]
D = [0.5 0.2]

sys = ss(A, B, C, D)

# Simulate the system with lsim
t = 0:1.0:10
u1 = sin.(t)
u2 = cos.(t)
u = [u1 u2]'
y, t, x = lsim(sys, u, t)

plot(y')


# Step 2: Design the PID controller
Kp = 1.0
Ki = 0.5
Kd = 0.1
Tf = 0.1  # Filter time constant
C = pid(Kp, Ki, Kd, Tf=Tf, state_space=true, Ts=1.0, form=:parallel)

G= feedback(sys.sys*C ??????)

8 posts - 2 participants