- 3.0.2 optimal control module.
TermLinear-impl.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 namespace ct {
9 namespace optcon {
10 
11 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
14  const SCALAR_EVAL c)
15  : a_(a), b_(b), c_(c)
16 {
17 }
18 
19 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
21  : TermBase<STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR>(arg), a_(arg.a_), b_(arg.b_), c_(arg.c_)
22 {
23 }
24 
25 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
28 {
30 }
31 
32 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
34 {
35 }
36 
37 
38 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
40 {
41 }
42 
43 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
45  const Eigen::Matrix<SCALAR, CONTROL_DIM, 1>& u,
46  const SCALAR& t)
47 {
48  return evalLocal<SCALAR>(x, u, t);
49 }
50 
51 #ifdef CPPADCG
52 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
56  ct::core::ADCGScalar t)
57 {
58  return evalLocal<ct::core::ADCGScalar>(x, u, t);
59 }
60 #endif
61 
62 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
66  const SCALAR_EVAL& t)
67 {
68  return a_;
69 }
70 
71 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
76  const SCALAR_EVAL& t)
77 {
78  return state_matrix_t::Zero();
79 }
80 
81 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
86  const SCALAR_EVAL& t)
87 {
88  return b_;
89 }
90 
91 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
96  const SCALAR_EVAL& t)
97 {
98  return control_matrix_t::Zero();
99 }
100 
101 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
106  const SCALAR_EVAL& t)
107 {
108  return control_state_matrix_t::Zero();
109 }
110 
111 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
113  const std::string& termName,
114  bool verbose)
115 {
116  // read in the file and put the valus in a_ and b_
117  loadMatrixCF(filename, "a", a_, termName);
118  loadMatrixCF(filename, "b", b_, termName);
119  if (verbose)
120  {
121  std::cout << "Read a as a= \n" << a_ << std::endl;
122  std::cout << "Read b as b= \n" << b_ << std::endl;
123  }
124 }
125 } // namespace optcon
126 } // 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
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
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
Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > state_matrix_t
Definition: TermBase.hpp:39
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
void loadMatrixCF(const std::string &filename, const std::string &matrixName, Eigen::Matrix< SCALAR, ROW, COL > &matrix, const std::string &termName="")
Definition: utilities.hpp:46
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
virtual ~TermLinear()
Definition: TermLinear-impl.hpp:39