Hi, i have a problem when using the s-function generated in simulink.
Similar to the NLP problem example, i made a Constrained Sindy version using Acados, now i want to set up the simulink part.
When i create the s-function block and add the correct file it returns me that output 6 is wrong, the problem is that i have only 5 outputs.
This is the code in matlab:
clear all
clc
is_parametric = 1;
import casadi.*; % Import CasADi library
load(‘Theta.txt’)
load(‘dXdt.txt’)
Theta=Theta(1:100,:);
dXdt=dXdt(1:100);
% Step 2: Define problem variables
eps=casadi.SX.sym(‘eps’,7);
if is_parametric
dXdt = SX.sym(‘dXdt’,size(dXdt));
end
if is_parametric
Theta = SX.sym(‘Theta’,size(Theta));
end
% Cost function with regularization
lambda = 1e-3; % Regularization term
f = abs((Theta * eps - dXdt)’ * (Theta * eps - dXdt));
% Constraint bounds
g = [eps(1);eps(2);eps(3);eps(4);eps(5);eps(6);eps(7)];
glb = [0.001;50;-5000;70000;-700000;-0.05;-0.001];
gub = [0.002;100;-3000;100000;-500000;-0.01;0];
% Step 3: Model setup
model = AcadosModel();
model.name = ‘prova_sindy’;
model.x = eps;
model.f_expl_expr = casadi.SX.zeros(length(model.x),1);
if is_parametric
model.p = vertcat(Theta(:),dXdt(:));
end
% Cost and constraints
ocp = AcadosOcp();
ocp.name = ‘nlp_solver’;
ocp.model = model;
ocp.cost.cost_type_e = ‘EXTERNAL’;
ocp.model.cost_expr_ext_cost_e = f;
ocp.model.con_h_expr_e = g;
ocp.constraints.lh_e = glb;
ocp.constraints.uh_e = gub;
ocp.cost.cost_type_0 = ‘EXTERNAL’;
ocp.model.cost_expr_ext_cost_0 = 0;
ocp.cost.cost_type = ‘EXTERNAL’;
ocp.model.cost_expr_ext_cost = 0;
% Solver options
ocp.solver_options.tf = 1;
ocp.solver_options.N_horizon = 1;
ocp.solver_options.nlp_solver_type = ‘SQP_RTI’;
ocp.solver_options.nlp_solver_max_iter = 1000;
ocp.solver_options.nlp_solver_tol_stat = 1e-6;
ocp.solver_options.nlp_solver_tol_eq = 1e-6;
ocp.solver_options.nlp_solver_tol_comp = 1e-6;
simulink_opts = get_acados_simulink_opts;
ocp.simulink_opts = simulink_opts;
% Solver creation
ocp_solver = AcadosOcpSolver(ocp);
%% Compile Sfunctions
cd c_generated_code
make_sfun
This the output from the Command Window:
Successfully created sfunction:
acados_solver_sfunction_prova_sindy.mexw64
Note: Usage of Sfunction is as follows:
Inputs are:
- parameters - concatenated for all stages 0 to N, size [1600]
- lh_e, size [7]
- uh_e, size [7]
Outputs are:
- acados solver status (0 = SUCCESS)
- KKT residual
- x1, state at node 1
- CPU time
- SQP iterations
And this the error:
I also have another question, why is x_init in the input not present?