Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 12 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.