/* * 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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE.; */ // standard #include #include // acados #include "acados/utils/print.h" #include "acados/utils/math.h" #include "acados_c/ocp_nlp_interface.h" #include "acados_solver_{{ model.name }}.h" // mex #include "mex.h" /* auxilary mex */ // prints a matrix in column-major format (exponential notation) void MEX_print_exp_mat(int m, int n, double *A, int lda) { for (int i=0; iN; i++) { ocp_nlp_out_set(nlp_config, nlp_dims, nlp_out, i, "x", x_init); ocp_nlp_out_set(nlp_config, nlp_dims, nlp_out, i, "u", u0); } status = {{ model.name }}_acados_solve(); ocp_nlp_get(nlp_config, nlp_solver, "time_tot", &elapsed_time); min_time = MIN(elapsed_time, min_time); } /* print solution and statistics */ for (int ii = 0; ii <= nlp_dims->N; ii++) ocp_nlp_out_get(nlp_config, nlp_dims, nlp_out, ii, "x", &xtraj[ii*{{ dims.nx }}]); for (int ii = 0; ii < nlp_dims->N; ii++) ocp_nlp_out_get(nlp_config, nlp_dims, nlp_out, ii, "u", &utraj[ii*{{ dims.nu }}]); mexPrintf("\n--- xtraj ---\n"); MEX_print_exp_tran_mat( {{ dims.nx }}, {{ dims.N }}+1, xtraj, {{ dims.nx }} ); mexPrintf("\n--- utraj ---\n"); MEX_print_exp_tran_mat( {{ dims.nu }}, {{ dims.N }}, utraj, {{ dims.nu }} ); mexPrintf("\nsolved ocp %d times, solution printed above\n\n", NTIMINGS); if (status == ACADOS_SUCCESS) mexPrintf("{{ model.name }}_acados_solve(): SUCCESS!\n"); else mexPrintf("{{ model.name }}_acados_solve() failed with status %d.\n", status); // get solution ocp_nlp_out_get(nlp_config, nlp_dims, nlp_out, 0, "kkt_norm_inf", &kkt_norm_inf); ocp_nlp_get(nlp_config, nlp_solver, "sqp_iter", &sqp_iter); mexPrintf("\nSolver info:\n"); mexPrintf(" SQP iterations %2d\n minimum time for 1 solve %f [ms]\n KKT %e\n", sqp_iter, min_time*1000, kkt_norm_inf); // free solver status = {{ model.name }}_acados_free(); if (status) { mexPrintf("{{ model.name }}_acados_free() returned status %d.\n", status); } return; }