quadratic_state_cost.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_OPTIMAL_CONTROL_INCLUDE_CORBO_OPTIMAL_CONTROL_FUNCTIONS_QUADRATIC_STATE_COST_H_
26 #define SRC_OPTIMAL_CONTROL_INCLUDE_CORBO_OPTIMAL_CONTROL_FUNCTIONS_QUADRATIC_STATE_COST_H_
27 
30 
31 #include <memory>
32 
33 namespace corbo {
34 
36 {
37  public:
38  QuadraticStateCost() { _Q_sqrt = Eigen::MatrixXd::Constant(1, 1, 1); }
39 
40  QuadraticStateCost(const Eigen::Ref<const Eigen::MatrixXd>& Q, bool integral_form, bool lsq_form = false)
41  : _integral_form(integral_form), _lsq_form(lsq_form)
42  {
43  setWeightQ(Q);
44  }
45 
46  StageCost::Ptr getInstance() const override { return std::make_shared<QuadraticStateCost>(); }
47 
48  bool hasIntegralTerms(int k) const override { return _integral_form; }
49  bool hasNonIntegralTerms(int k) const override { return !_integral_form; }
50 
51  int getNonIntegralStateTermDimension(int k) const override { return !_integral_form ? (_lsq_form ? _Q.rows() : 1) : 0; }
52  int getIntegralStateControlTermDimension(int k) const override { return _integral_form ? 1 : 0; }
53 
54  bool isLsqFormNonIntegralStateTerm(int k) const override { return !_integral_form && _lsq_form; }
55 
58  void setLsqForm(bool lsq_form) { _lsq_form = lsq_form; }
59  void setIntegralForm(bool integral_form) { _integral_form = integral_form; }
60 
63  Eigen::Ref<Eigen::VectorXd> cost) const override;
64 
66  bool single_dt, const Eigen::VectorXd& x0, StagePreprocessor::Ptr stage_preprocessor, const std::vector<double>& dts,
67  const DiscretizationGridInterface* /*grid*/) override
68  {
69  _x_ref = &xref;
70 
72 
73  return false;
74  }
75 
76  bool checkParameters(int state_dim, int control_dim, std::stringstream* issues) const override;
77 
78 #ifdef MESSAGE_SUPPORT
79  virtual bool fromMessage(const messages::QuadraticStateCost& message, std::stringstream* issues);
80  virtual void toMessage(messages::QuadraticStateCost& message) const;
81 
82  bool fromMessage(const messages::StageCost& message, std::stringstream* issues) override
83  {
84  return fromMessage(message.quadratic_state_cost(), issues);
85  }
86  void toMessage(messages::StageCost& message) const override { toMessage(*message.mutable_quadratic_state_cost()); }
87 #endif
88 
89  protected:
90  Eigen::MatrixXd _Q_sqrt;
91  Eigen::MatrixXd _Q;
94  bool _diagonal_mode = false;
96  bool _lsq_form = true;
97  bool _integral_form = false;
98 
100  bool _zero_x_ref = false;
101 };
103 
104 } // namespace corbo
105 
106 #endif // SRC_OPTIMAL_CONTROL_INCLUDE_CORBO_OPTIMAL_CONTROL_FUNCTIONS_QUADRATIC_STATE_COST_H_
bool setWeightQ(const Eigen::Ref< const Eigen::MatrixXd > &Q)
bool hasNonIntegralTerms(int k) const override
QuadraticStateCost(const Eigen::Ref< const Eigen::MatrixXd > &Q, bool integral_form, bool lsq_form=false)
void setIntegralForm(bool integral_form)
Generic interface class for discretization grids.
Eigen::DiagonalMatrix< double, -1 > _Q_diag
bool checkParameters(int state_dim, int control_dim, std::stringstream *issues) const override
bool isLsqFormNonIntegralStateTerm(int k) const override
int getNonIntegralStateTermDimension(int k) const override
Eigen::DiagonalMatrix< double, -1 > _Q_diag_sqrt
int getIntegralStateControlTermDimension(int k) const override
void computeIntegralStateControlTerm(int k, const Eigen::Ref< const Eigen::VectorXd > &x_k, const Eigen::Ref< const Eigen::VectorXd > &u_k, Eigen::Ref< Eigen::VectorXd > cost) const override
#define FACTORY_REGISTER_STAGE_COST(type)
void computeNonIntegralStateTerm(int k, const Eigen::Ref< const Eigen::VectorXd > &x_k, Eigen::Ref< Eigen::VectorXd > cost) const override
bool update(int n, double t, ReferenceTrajectoryInterface &xref, ReferenceTrajectoryInterface &uref, ReferenceTrajectoryInterface *sref, bool single_dt, const Eigen::VectorXd &x0, StagePreprocessor::Ptr stage_preprocessor, const std::vector< double > &dts, const DiscretizationGridInterface *) override
StageCost::Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:192
void setLsqForm(bool lsq_form)
Interface class for reference trajectories.
const ReferenceTrajectoryInterface * _x_ref
std::shared_ptr< StagePreprocessor > Ptr
std::shared_ptr< StageCost > Ptr
bool hasIntegralTerms(int k) const override
PlainMatrixType mat * n
Definition: eigenvalues.cpp:41


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:07:14