- 3.0.2 optimal control module.
CostFunctionQuadraticSimple.hpp
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
9 
10 namespace ct {
11 namespace optcon {
12 
22 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
23 class CostFunctionQuadraticSimple : public CostFunctionQuadratic<STATE_DIM, CONTROL_DIM, SCALAR>
24 {
25 public:
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27 
28  typedef Eigen::Matrix<SCALAR, STATE_DIM, STATE_DIM> state_matrix_t;
29  typedef Eigen::Matrix<SCALAR, CONTROL_DIM, CONTROL_DIM> control_matrix_t;
30  typedef Eigen::Matrix<SCALAR, CONTROL_DIM, STATE_DIM> control_state_matrix_t;
31 
34 
48  CostFunctionQuadraticSimple(const state_matrix_t& Q,
49  const control_matrix_t& R,
50  const state_vector_t& x_nominal,
51  const control_vector_t& u_nominal,
52  const state_vector_t& x_final,
53  const state_matrix_t& Q_final);
54 
56 
58 
64 
65  virtual void setCurrentStateAndControl(const state_vector_t& x,
66  const control_vector_t& u,
67  const SCALAR& t) override;
68 
69  virtual SCALAR evaluateIntermediate() override;
70 
71  virtual state_vector_t stateDerivativeIntermediate() override;
72 
73  virtual state_matrix_t stateSecondDerivativeIntermediate() override;
74 
75  virtual control_vector_t controlDerivativeIntermediate() override;
76 
77  virtual control_matrix_t controlSecondDerivativeIntermediate() override;
78 
79  virtual control_state_matrix_t stateControlDerivativeIntermediate() override;
80 
81  virtual SCALAR evaluateTerminal() override;
82 
83  virtual state_vector_t stateDerivativeTerminal() override;
84 
85  virtual state_matrix_t stateSecondDerivativeTerminal() override;
86 
87  virtual void updateReferenceState(const state_vector_t& x_ref) override;
88 
89  virtual void updateFinalState(const state_vector_t& x_final) override;
90 
91 protected:
92  state_vector_t x_deviation_;
93  state_vector_t x_nominal_;
94  state_matrix_t Q_;
95 
96  control_vector_t u_deviation_;
97  control_vector_t u_nominal_;
98  control_matrix_t R_;
99 
100  state_vector_t x_final_;
101  state_matrix_t Q_final_;
102 };
103 
104 } // namespace optcon
105 } // namespace ct
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< SCALAR, STATE_DIM, STATE_DIM > state_matrix_t
Definition: CostFunctionQuadraticSimple.hpp:28
virtual SCALAR evaluateTerminal() override
evaluate terminal costs
Definition: CostFunctionQuadraticSimple-impl.hpp:121
state_matrix_t Q_
Definition: CostFunctionQuadraticSimple.hpp:94
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual void updateReferenceState(const state_vector_t &x_ref) override
update the reference state for intermediate cost terms
Definition: CostFunctionQuadraticSimple-impl.hpp:143
core::StateVector< STATE_DIM, SCALAR > state_vector_t
Definition: CostFunctionQuadraticSimple.hpp:32
virtual void setCurrentStateAndControl(const state_vector_t &x, const control_vector_t &u, const SCALAR &t) override
Definition: CostFunctionQuadraticSimple-impl.hpp:65
Eigen::Matrix< SCALAR, CONTROL_DIM, STATE_DIM > control_state_matrix_t
Definition: CostFunctionQuadraticSimple.hpp:30
CostFunctionQuadraticSimple< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Definition: CostFunctionQuadraticSimple-impl.hpp:59
virtual state_vector_t stateDerivativeIntermediate() override
Computes intermediate-cost first-order derivative with respect to state.
Definition: CostFunctionQuadraticSimple-impl.hpp:87
A simple quadratic cost function.
Definition: CostFunctionQuadraticSimple.hpp:23
virtual control_matrix_t controlSecondDerivativeIntermediate() override
Computes intermediate-cost second-order derivative with respect to input.
Definition: CostFunctionQuadraticSimple-impl.hpp:108
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
control_vector_t u_nominal_
Definition: CostFunctionQuadraticSimple.hpp:97
state_matrix_t Q_final_
Definition: CostFunctionQuadraticSimple.hpp:101
Describes a cost function with a quadratic approximation, i.e. one that can compute first and second ...
Definition: CostFunctionQuadratic.hpp:29
state_vector_t x_deviation_
Definition: CostFunctionQuadraticSimple.hpp:92
virtual state_vector_t stateDerivativeTerminal() override
Definition: CostFunctionQuadraticSimple-impl.hpp:129
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual state_matrix_t stateSecondDerivativeTerminal() override
Computes final-cost second-order derivative with respect to state.
Definition: CostFunctionQuadraticSimple-impl.hpp:137
virtual void updateFinalState(const state_vector_t &x_final) override
update the reference state for final cost terms
Definition: CostFunctionQuadraticSimple-impl.hpp:149
Eigen::Matrix< SCALAR, CONTROL_DIM, CONTROL_DIM > control_matrix_t
Definition: CostFunctionQuadraticSimple.hpp:29
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
control_matrix_t R_
Definition: CostFunctionQuadraticSimple.hpp:98
virtual SCALAR evaluateIntermediate() override
evaluate intermediate costs
Definition: CostFunctionQuadraticSimple-impl.hpp:78
core::ControlVector< CONTROL_DIM, SCALAR > control_vector_t
Definition: CostFunctionQuadraticSimple.hpp:33
virtual ~CostFunctionQuadraticSimple()
Definition: CostFunctionQuadraticSimple-impl.hpp:38
control_vector_t u_deviation_
Definition: CostFunctionQuadraticSimple.hpp:96
state_vector_t x_final_
Definition: CostFunctionQuadraticSimple.hpp:100
virtual state_matrix_t stateSecondDerivativeIntermediate() override
Computes intermediate-cost second-order derivative with respect to state.
Definition: CostFunctionQuadraticSimple-impl.hpp:94
virtual control_vector_t controlDerivativeIntermediate() override
Computes intermediate-cost first-order derivative with respect to control.
Definition: CostFunctionQuadraticSimple-impl.hpp:101
virtual control_state_matrix_t stateControlDerivativeIntermediate() override
Computes intermediate-cost derivative with respect to state and control.
Definition: CostFunctionQuadraticSimple-impl.hpp:115
CostFunctionQuadraticSimple()
Definition: CostFunctionQuadraticSimple-impl.hpp:12
state_vector_t x_nominal_
Definition: CostFunctionQuadraticSimple.hpp:93