Hi @Freddy ,
I am glad you like the S-function.
I think that the whole x trajectory in the OCP solver is not often needed, so I wont implement that.
However, please feel free to edit the template that is used for the S-function:
/*
* Copyright 2019 Gianluca Frison, Dimitris Kouzoupis, Robin Verschueren,
* Andrea Zanelli, Niels van Duijkeren, Jonathan Frey, Tommaso Sartor,
* Branimir Novoselnik, Rien Quirynen, Rezart Qelibari, Dang Doan,
* Jonas Koenemann, Yutao Chen, Tobias Schöls, Jonas Schlagenhauf, Moritz Diehl
*
* This file is part of acados.
*
* The 2-Clause BSD License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
This file has been truncated. show original
In particular, you would have to edit these sections:
{%- if dims.nh > 0 %}
{%- set i_input = i_input + 1 %}
// lh
ssSetInputPortVectorDimension(S, {{ i_input }}, {{ dims.nh }});
{%- set i_input = i_input + 1 %}
// uh
ssSetInputPortVectorDimension(S, {{ i_input }}, {{ dims.nh }});
{%- endif %}
// specify dimension information for the output ports
ssSetOutputPortVectorDimension(S, 0, {{ dims.nu }} ); // optimal input
ssSetOutputPortVectorDimension(S, 1, 1 ); // solver status
ssSetOutputPortVectorDimension(S, 2, 1 ); // KKT residuals
ssSetOutputPortVectorDimension(S, 3, {{ dims.nx }} ); // first state
ssSetOutputPortVectorDimension(S, 4, 1); // computation times
ssSetOutputPortVectorDimension(S, 5, 1 ); // sqp iter
// specify the direct feedthrough status
// should be set to 1 for all inputs used in mdlOutputs
{%- for i in range(end=n_inputs) %}
for (int ii = 0; ii < {{ dims.N }}; ii++)
ocp_nlp_constraints_model_set(nlp_config, nlp_dims, nlp_in, ii, "uh", buffer);
{%- endif %}
/* call solver */
int rti_phase = 0;
ocp_nlp_solver_opts_set(nlp_config, nlp_opts, "rti_phase", &rti_phase);
int acados_status = acados_solve();
/* set outputs */
// assign pointers to output signals
real_t *out_u0, *out_status, *out_sqp_iter, *out_KKT_res, *out_x1, *out_cpu_time;
int tmp_int;
out_u0 = ssGetOutputPortRealSignal(S, 0);
out_status = ssGetOutputPortRealSignal(S, 1);
out_KKT_res = ssGetOutputPortRealSignal(S, 2);
out_x1 = ssGetOutputPortRealSignal(S, 3);
out_cpu_time = ssGetOutputPortRealSignal(S, 4);
out_sqp_iter = ssGetOutputPortRealSignal(S, 5);
Moreover, you will have to edit the Simulink block to adjust for the new outputs.
I hope that helps and isnt too involved…
Best,
Jonathan