0

I am using MATLAB to build a code that does automatic tuning of the three PID controller gains. The way I am thinking of it, is to minimize the error (the difference between the desired state and the obtained one) of my system, for that, I coded a function that accepts the PID gains as input parameters and returns the calculated error, namely:

errors_vector = closedLoopSimulation(pidGains)

Since I have three set points (input commands), then the dimension of the output errors_vector is 3*N, where N is the number of time samples I have (1000 in my case). So that is the function I want to minimize, and for doing so, I tried using fminunc command, namely:

pidGains_ini  = [2.4 0.1 0.4];
func          = @closedLoopSimulation;
[pid, fval]   = fminunc(func, pidGains_ini)

However, when I run the last piece of code, I get this error:

User supplied objective function must return a scalar value.

which is clearly due to the fact that that errors_vector is a 3*1000 array and not a scalar.

My questions would be, from the programming point of view, is there a way that I can make fminunc minimize functions that return arrays?

On the other hand, and from the Control Theory point of view, is there another way which I can optimize the PID gains automatically?

I hope I made myself clear enough.

Thanks

M.A.
  • 169
  • 1
  • 1
  • 18
  • Can you explain the errors_vector better? It's clear that there is an error for each time-step, but why are there three at each time-step? Are you controlling three outputs at the same time? – tvo May 12 '16 at 14:45
  • 1
    The [Ziegler-Nichols method](https://en.wikipedia.org/wiki/Ziegler–Nichols_method) and the [Relay method](http://www.controleng.com/search/search-single-display/relay-method-automates-pid-loop-tuning/4a5774decc.html) are two popular PID tuning schemes. – horchler May 12 '16 at 17:57
  • @tvo, yes this is what I am doing. My system is MIMO, having 3 input commands and 3 control efforts outputing from the PID controller. – M.A. May 13 '16 at 14:13

1 Answers1

1

Minimizing a vector is not very well defined (there is something called multi-objective or multi-criteria optimization but that is somewhat specialized). "Normal" optimization methods can only minimize (or maximize) scalar objectives. I suspect in your case you could form such an objective by taking the sum of the squared errors and minimize that. To be complete: this is standard operating procedure and is often called "least squares".

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39