acados_solver_ros2 main
Acados-based NMPC controllers for ROS2 control
Loading...
Searching...
No Matches
acados_solver_utils.hpp
Go to the documentation of this file.
1// Copyright 2023 ICUBE Laboratory, University of Strasbourg
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Author: Thibault Poignonec (tpoignonec@unistra.fr)
16
17#ifndef ACADOS_SOLVER_BASE__ACADOS_SOLVER_UTILS_HPP_
18#define ACADOS_SOLVER_BASE__ACADOS_SOLVER_UTILS_HPP_
19
20#include <Eigen/Dense>
21
22#include <string>
23
24// Acados C interface
25#include "acados_c/ocp_nlp_interface.h"
26
29
30
31namespace acados
32{
33
34namespace utils
35{
36
37// ---------------------------------------------------------
38// Convenience setters for commonly used cost variables
39// ---------------------------------------------------------
40
54template<typename Derived>
56 AcadosSolver & solver,
57 unsigned int stage,
58 const std::string & field,
59 Eigen::EigenBase<Derived> & value);
60
61// Linear cost L = || Vx @ u + Vu @ u + Vz @ z - y_ref ||²_W
62//
63// Make sure the cost type is 'LINEAR_LS'
64// ---------------------------------------------------------
65
74bool set_cost_Vx(AcadosSolver & solver, unsigned int stage, Eigen::MatrixXd & Vx);
75
84bool set_cost_Vu(AcadosSolver & solver, unsigned int stage, Eigen::MatrixXd & Vu);
85
94bool set_cost_Vz(AcadosSolver & solver, unsigned int stage, Eigen::MatrixXd & Vz);
95
104bool set_cost_W(AcadosSolver & solver, unsigned int stage, Eigen::MatrixXd & W);
105
114bool set_cost_y_ref(AcadosSolver & solver, unsigned int stage, Eigen::VectorXd & y_ref);
115
116// ------------------------------------------------------------
117// Convenience setters for commonly used constraint variables
118// ------------------------------------------------------------
119
133template<typename Derived>
135 AcadosSolver & solver,
136 unsigned int stage,
137 const std::string & field,
138 Eigen::EigenBase<Derived> & value);
139
140// Linear constraints
141// ---------------------------------------------------------
142
143// For basic utils, see `AcadosSolver::set_state_bounds` and `AcadosSolver::set_control_bounds`
144
145// TODO(tpoignonec):
146// - Add resize_state_bounds(stage, idxbx, suppress_warnings = false)
147// - Add resize_state_bounds(stage, bx_index_map, suppress_warnings = false)
148// - Add resize_control_bounds(stage, idxbu, suppress_warnings = false)
149// - Add resize_control_bounds(stage, bu_index_map, suppress_warnings = false)
150
151// Polytopic constraints of the form
152// ---------------------------------------------------------
153// General linear constraints of the form
154// \f$ D @ u+ C @ x \in [g_min; g_max] \f$
155// except for terminal stage where
156// \f$ C @ x \in [g_min; g_max] \f$
157
166bool set_const_C(AcadosSolver & solver, unsigned int stage, Eigen::MatrixXd & C);
167
176bool set_const_D(AcadosSolver & solver, unsigned int stage, Eigen::MatrixXd & D);
177
186bool set_const_g_min(AcadosSolver & solver, unsigned int stage, Eigen::VectorXd & g_min);
187
196bool set_const_g_max(AcadosSolver & solver, unsigned int stage, Eigen::VectorXd & g_max);
197
198// Ton-linear constraints
199// ---------------------------------------------------------
200
209bool set_const_h_min(AcadosSolver & solver, unsigned int stage, Eigen::VectorXd & h_min);
210
219bool set_const_h_max(AcadosSolver & solver, unsigned int stage, Eigen::VectorXd & h_max);
220
221// ------------------------------------------------------------
222// Convenience getters for solver stats
223// ------------------------------------------------------------
224
235template<typename T>
236void unsafe_get_stats_field(AcadosSolver & solver, const std::string & field, T & value);
237
247
257
267
268} // namespace utils
269
270} // namespace acados
271
272#endif // ACADOS_SOLVER_BASE__ACADOS_SOLVER_UTILS_HPP_
Abstract C++ wrapper of generated Acados solver C-code.
Definition acados_solver.hpp:42
double get_stats_cost_value(AcadosSolver &solver)
Retrieve the current cost value.
bool set_const_g_max(AcadosSolver &solver, unsigned int stage, Eigen::VectorXd &g_max)
Set the upper bound g_max used by polytopic constraints.
bool set_cost_field(AcadosSolver &solver, unsigned int stage, const std::string &field, Eigen::EigenBase< Derived > &value)
Generic setter for the cost.
bool set_const_D(AcadosSolver &solver, unsigned int stage, Eigen::MatrixXd &D)
Set the D matrix used by polytopic constraints.
bool set_cost_W(AcadosSolver &solver, unsigned int stage, Eigen::MatrixXd &W)
Set the W cost matrix used for 'LINEAR_LS' cost.
bool set_cost_Vu(AcadosSolver &solver, unsigned int stage, Eigen::MatrixXd &Vu)
Set the Vu matrix used for 'LINEAR_LS' cost.
bool set_cost_y_ref(AcadosSolver &solver, unsigned int stage, Eigen::VectorXd &y_ref)
Set the y_ref vector for a given stage.
int get_stats_sqp_iter(AcadosSolver &solver)
Retrieve the SQP iteration at the last solve() call.
void unsafe_get_stats_field(AcadosSolver &solver, const std::string &field, T &value)
Read a given field from the solver stats (solve must be called before...)
bool set_const_h_min(AcadosSolver &solver, unsigned int stage, Eigen::VectorXd &h_min)
Set the lower bound h_min used by non-linear constraints.
bool set_cost_Vz(AcadosSolver &solver, unsigned int stage, Eigen::MatrixXd &Vz)
Set the Vz matrix used for 'LINEAR_LS' cost.
bool set_const_C(AcadosSolver &solver, unsigned int stage, Eigen::MatrixXd &C)
Set the C matrix used by polytopic constraints.
bool set_cost_Vx(AcadosSolver &solver, unsigned int stage, Eigen::MatrixXd &Vx)
Set the Vx matrix used for 'LINEAR_LS' cost.
bool set_const_h_max(AcadosSolver &solver, unsigned int stage, Eigen::VectorXd &h_max)
Set the upper bound h_max used by non-linear constraints.
bool set_const_g_min(AcadosSolver &solver, unsigned int stage, Eigen::VectorXd &g_min)
Set the lower bound g_min used by polytopic constraints.
double get_stats_cpu_time(AcadosSolver &solver)
Retrieve the CPU time needed for the last solve() call.
bool set_constraint_field(AcadosSolver &solver, unsigned int stage, const std::string &field, Eigen::EigenBase< Derived > &value)
Generic setter for the constraints.
Definition acados_solver.hpp:35