How do you use SystemsModelFeedbackConnect?



I'm trying to grasp the new control system functions in Mathematica 8. I'd like to connect a controller model to a model of a plant to simulate the behavior of the system.

I define a simple servo model:

servo = StateSpaceModel[{x''[t] == u[t] - x'[t]}, {{x''[t], 0}}, {{u[t], 0}}, x[t], t]

where x[t] is the position of the servo and u[t] is the input (voltage).

and a simple PID controller:

pid = TransferFunctionModel[5 + 0.01*s - 0.00001/s, s]

Now I assumed that I could link the PID controller to the servo model using SystemsModelFeedbackConnect:

loop = SystemsModelFeedbackConnect[TransferFunctionModel[servo], pid]

But the system doesn't behave as I would have expected:

input = UnitStep[t - 1] - 0.5 UnitStep[t - 10];
output = OutputResponse[loop, input, t];
Plot[{input, output}, {t, 0, 30}]


There's a lot of overshoot because the PID is not optimized at all, but I would have expected that the P part of the controller would pull the output to the (target) input eventually. But it seems as if the P factor scales the input, rather than the error.

Niki Estner

Posted 2012-11-17T12:06:48.377

Reputation: 34 978



You need to first do a series connection of the PID controler to the plant. This gives the open loop transfer function. Then do a unity feedback connect to close the loop, like this

plant = StateSpaceModel[{x''[t] == u[t] - x'[t]}, {{x''[t],0}}, {{u[t], 0}}, x[t], t];
kip = 5; ki = -0.00001; kid = 0.01;
pid = TransferFunctionModel[(kip*s + ki + kid*s^2)/s, s] ;
openLoop = SystemsModelSeriesConnect[TransferFunctionModel[plant], pid];
closedLoop = SystemsModelFeedbackConnect[openLoop];
input = UnitStep[t - 1] - 0.5 UnitStep[t - 10];
output = OutputResponse[closedLoop, input, t];
Plot[{input, output}, {t, 0, 30}]

enter image description here

fyi, here is a demo


Posted 2012-11-17T12:06:48.377

Reputation: 92 661

1I'd like to point out that @Nasser's demonstration cited above includes the nicest technique for object-oriented programming in Mathematica that I have seen. – Reb.Cabin – 2017-10-22T22:17:34.460