# Limiting transfer function of PID to upper and lower bounds

I have a question about Limiting the output of a transfer function in my system model. (Im fairly new to control theory and control systems)

I have a model where a PID controller is directly controlling the acceleration of a quadcopter. The quadcopter is "trying" to fly at a set hight.

Currently, I have the following: My question is: how can I limit the acceleration (the PID output) in the system?

I've tried the solution from question 133541. But that didn't work out for me. Mathematica tells me the transfer function of the PID controller cant be converted into a nonlinearStateSpaceModel? I don't really know why or how as I'm new to the field. The core problem is that NonlinearStateSpaceModel does not support descriptor systems.

When there are pure derivative terms, the state-space representation will need a singular descriptor matrix. This is supported by StateSpaceModel but not by NonlinearStateSpaceModel.

Through@{StateSpaceModel, NonlinearStateSpaceModel}@TransferFunctionModel[s, s] A workaround is to do away with the derivative term or use a filter on the derivative terms. (These are done in applications where there is large sensor noise or abrupt reference changes.)

SystemsModelSeriesConnect[TransferFunctionModel[kp + ki/s + kd s/(s + α), s],
NonlinearStateSpaceModel[{{}, Clip[u]}, {}, u]] • Is there a mathematical reason NonlinearStateSpaceModels don't support pure derivative terms? Or is that just a Mathematica thing? Anyways the filter is working like a charm so thanks! :D – Levy Ehrstein Jul 24 at 15:07
• It's not a mathematical reason. We did not get to it yet. – Suba Thomas Jul 24 at 15:12

Due to the double pole representing the copter, a simple PD will suffice. Follows a layman procedure to find an acceptable solution. The procedure consists in searching through a minimization procedure, the nearest response regarding a reference response to a step. Here the reference response is given by

stepref = InverseLaplaceTransform[(a^2 + b^2)/((s + a)^2 + b^2)/s, s, t]


the actual step response is obtained as follows:

PID = kp + ki/s + s kd;
COPTER = 1/s^2;
model = COPTER PID/(1 + COPTER PID)
stepresponse = InverseLaplaceTransform[model/s, s, t];


then follows the minimization procedure

parms = {a -> 2, b -> 2};
tmax = 4;
n = 20;
stepref0 = stepref /. parms;
tab = Sum[Abs[stepresponse - stepref0], {t, 0, tmax, tmax/n}];
sol = NMinimize[{tab, kp > 0, ki > 0, kd > 0}, {kp, ki, kd}]
stepresponse0 = stepresponse /. sol[]


Follows a plot showing in blue the reference response and in red the response found. • Is there some place where you are clipping the signal between PID and COPTER to be within 2 units? – Suba Thomas Jul 24 at 14:18
• The acceleration limit at the PID can be obtained by conveniently choosing it's parameters. No need for Clip[] – Cesareo Jul 24 at 16:18
• were a, b -> 2 arbitrarily choosen? Or where did that come from...being matching a $e^{-a*t}$ sin($\omega$ t) for the system – morbo Jul 26 at 11:49
• Choosing $a, b$ we are choosing the needed unit step response for our COPTER + PID. – Cesareo Jul 26 at 11:52