Background: I wrote a function using fmincon to optimize inputs for a control system. Predictive Control so to say.
In Matlab everything works fine, it runs through and delivers good output and solves the control task very well - so i wanted to generate C-Code and evaluate how i can utilize this in a physical controller.
Inputs are: uold - 3x1 vector; TubeTemp - scalar; Traj - 45x1 vector; len - scalar; state - 6x1 vector; UpBounds, 3x1 vector; RateMode - scalar
This function is called in a loop with a system model (standard closed loop control ) and is updated every iteration with new values for the above described variables. Its basically a heating process and the states change of course over time.
function [u] = Executable_MPC(uold,TubeTemp,Traj,len,state,UpBounds,RateMode)
opts = optimoptions('fmincon','Algorithm','sqp','Display','off','MaxIterations',50);
objfun = @(x)obj(x,TubeTemp(:,1:len),Traj(:,1:len),state,RateMode);
[solution,objectiveValue] = fmincon(objfun,x0,,,,,repmat(0.01,...
function Error = obj (x,TubeTemp,Traj,t0,Mode)
elseif i >=t_length/6 && i < 2*t_length/6
t(i,:) = PlantMdl(t0,Power,0,0,TubeTemp(i),dt);
Error =sum(sum(abs(t(:,3:5) - Traj(2:4,:)')).*[2 1 1]);
Using the Matlab Coder GUI it fails in the Step: "Check for Run-Time Issues". I select the calling script as recommended from the GUI and it returns a whole bunch of errors. I don't really understand what the problem is, since i basically generated this script from an example that mathworks provided with the "optimization toolbox live editor". I am not an expert in coding or math - just a control engineer.
Since line 11 is marked together with line 14 i think it has something to do with the way how i call the objective function, but it doesn't give a hint what causes the problem and i didn't find any documentation around fmincon how to do that properly.
Sorry for the Wall of Text but i wanted to provide all info ;)
Thanks in advance for trying to help!