- 3.0.2 optimal control module.
TermLinear.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 
8 #include "TermBase.hpp"
9 
10 namespace ct {
11 namespace optcon {
12 
19 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL = double, typename SCALAR = SCALAR_EVAL>
20 class TermLinear : public TermBase<STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR>
21 {
22 public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
25  typedef Eigen::Matrix<SCALAR_EVAL, STATE_DIM, STATE_DIM> state_matrix_t;
26  typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM> control_matrix_t;
27  typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, STATE_DIM> control_state_matrix_t;
28  typedef Eigen::Matrix<SCALAR_EVAL, STATE_DIM, STATE_DIM> state_matrix_double_t;
29  typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM> control_matrix_double_t;
30  typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, STATE_DIM> control_state_matrix_double_t;
31 
34  const SCALAR_EVAL c = 0.);
35 
36  TermLinear();
37 
38  TermLinear(const TermLinear& arg);
39 
41 
42  virtual ~TermLinear();
43 
44  SCALAR evaluate(const Eigen::Matrix<SCALAR, STATE_DIM, 1>& x,
45  const Eigen::Matrix<SCALAR, CONTROL_DIM, 1>& u,
46  const SCALAR& t) override;
47 
48 #ifdef CPPADCG
49  virtual ct::core::ADCGScalar evaluateCppadCg(const core::StateVector<STATE_DIM, ct::core::ADCGScalar>& x,
51  ct::core::ADCGScalar t) override;
52 #endif
53 
56  const SCALAR_EVAL& t) override;
57 
60  const SCALAR_EVAL& t) override;
61 
64  const SCALAR_EVAL& t) override;
65 
68  const SCALAR_EVAL& t) override;
69 
72  const SCALAR_EVAL& t) override;
73 
74  void loadConfigFile(const std::string& filename,
75  const std::string& termName,
76  bool verbose = false) override; // virtual function for data loading
77 
78 protected:
79  template <typename SC>
80  SC evalLocal(const Eigen::Matrix<SC, STATE_DIM, 1>& x, const Eigen::Matrix<SC, CONTROL_DIM, 1>& u, const SC& t);
81 
84  SCALAR_EVAL c_;
85 };
86 
87 
88 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
89 template <typename SC>
91  const Eigen::Matrix<SC, CONTROL_DIM, 1>& u,
92  const SC& t)
93 {
94  Eigen::Matrix<SC, 1, 1> y_eigen = a_.template cast<SC>().transpose() * x + b_.template cast<SC>().transpose() * u;
95  SC y = y_eigen(0, 0) + SC(c_);
96  return y;
97 }
98 
99 
100 } // namespace optcon
101 } // namespace ct
A linear term of type .
Definition: TermLinear.hpp:20
SCALAR evaluate(const Eigen::Matrix< SCALAR, STATE_DIM, 1 > &x, const Eigen::Matrix< SCALAR, CONTROL_DIM, 1 > &u, const SCALAR &t) override
Evaluates the term at x, u, t.
Definition: TermLinear-impl.hpp:44
SC evalLocal(const Eigen::Matrix< SC, STATE_DIM, 1 > &x, const Eigen::Matrix< SC, CONTROL_DIM, 1 > &u, const SC &t)
Definition: TermLinear.hpp:90
Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, STATE_DIM > control_state_matrix_double_t
Definition: TermLinear.hpp:30
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
control_state_matrix_t stateControlDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) override
compute the cross-term derivative (state-control) of this cost function term
Definition: TermLinear-impl.hpp:103
Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM > control_matrix_t
Definition: TermLinear.hpp:26
An interface for a term, supporting both analytical and auto-diff terms.
Definition: TermBase.hpp:30
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
TermLinear()
Definition: TermLinear-impl.hpp:33
CppAD::AD< CppAD::cg::CG< double > > SCALAR
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > state_matrix_double_t
Definition: TermLinear.hpp:28
control_matrix_t controlSecondDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) override
compute second order derivative of this cost term w.r.t. the control input
Definition: TermLinear-impl.hpp:93
SCALAR_EVAL c_
Definition: TermLinear.hpp:84
core::StateVector< STATE_DIM, SCALAR_EVAL > a_
Definition: TermLinear.hpp:82
TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR > * clone() const override
Deep-copy term.
Definition: TermLinear-impl.hpp:27
core::StateVector< STATE_DIM, SCALAR_EVAL > stateDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) override
compute derivative of this cost term w.r.t. the state
Definition: TermLinear-impl.hpp:63
void loadConfigFile(const std::string &filename, const std::string &termName, bool verbose=false) override
load this term from a configuration file
Definition: TermLinear-impl.hpp:112
core::ControlVector< CONTROL_DIM, SCALAR_EVAL > b_
Definition: TermLinear.hpp:83
Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, STATE_DIM > control_state_matrix_t
Definition: TermLinear.hpp:27
const bool verbose
Definition: ConstraintComparison.h:18
Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM > control_matrix_double_t
Definition: TermLinear.hpp:29
state_matrix_t stateSecondDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) override
compute second order derivative of this cost term w.r.t. the state
Definition: TermLinear-impl.hpp:73
core::ControlVector< CONTROL_DIM, SCALAR_EVAL > controlDerivative(const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) override
compute derivative of this cost term w.r.t. the control input
Definition: TermLinear-impl.hpp:83
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > state_matrix_t
Definition: TermLinear.hpp:25
virtual ~TermLinear()
Definition: TermLinear-impl.hpp:39