- 3.0.2 optimal control module.
TerminalConstraint-impl.h
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>
13 {
14  xF_ = xf;
15  Base::lb_.resize(STATE_DIM);
16  Base::ub_.resize(STATE_DIM);
17  // The terminal state constraint is treated as equality constraint, therefore, ub = lb
18  Base::lb_.setConstant(SCALAR(0.0));
19  Base::ub_.setConstant(SCALAR(0.0));
20 }
21 
22 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
24 {
26 }
27 
28 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
30  : Base(arg), xF_(arg.xF_)
31 {
32 }
33 
34 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
36 {
37 }
38 
39 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
41 {
42  return STATE_DIM;
43 }
44 
45 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
48  const control_vector_t& u,
49  const SCALAR t)
50 {
51  return x - xF_;
52 }
53 
54 #ifdef CPPADCG
55 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
56 Eigen::Matrix<ct::core::ADCGScalar, Eigen::Dynamic, 1>
60  ct::core::ADCGScalar t)
61 {
62  return x - xF_.template cast<ct::core::ADCGScalar>();
63 }
64 #endif
65 
66 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
69  const control_vector_t& u,
70  const SCALAR t)
71 {
72  return Eigen::Matrix<SCALAR, STATE_DIM, STATE_DIM>::Identity();
73 }
74 
75 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
78  const control_vector_t& u,
79  const SCALAR t)
80 {
81  return Eigen::Matrix<SCALAR, STATE_DIM, CONTROL_DIM>::Zero();
82 }
83 
84 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
86 {
87  return STATE_DIM;
88 }
89 
90 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
92 {
93  return 0;
94 }
95 
96 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
99  const control_vector_t& u,
100  const SCALAR t)
101 {
103 }
104 
105 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
107 {
108  this->genDiagonalIndices(STATE_DIM, rows, cols);
109 }
110 }
111 }
virtual MatrixXs jacobianInput(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt input.
Definition: TerminalConstraint-impl.h:77
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
static void genDiagonalIndices(const size_t num_elements, Eigen::VectorXi &iRow_vec, Eigen::VectorXi &jCol_vec)
upper bound on the constraints
Definition: ConstraintBase-impl.h:136
virtual size_t getConstraintSize() const override
The evaluate method used for jit compilation in constraint container ad.
Definition: TerminalConstraint-impl.h:40
virtual TerminalConstraint< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Creates a new instance of the object with same properties than original.
Definition: TerminalConstraint-impl.h:23
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
virtual ~TerminalConstraint()
Definition: TerminalConstraint-impl.h:35
virtual void sparsityPatternState(VectorXi &rows, VectorXi &cols) override
Definition: TerminalConstraint-impl.h:106
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: TerminalConstraint.h:33
Eigen::Matrix< int, Eigen::Dynamic, 1 > VectorXi
Definition: TerminalConstraint.h:31
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
virtual VectorXs evaluate(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
The evaluation of the constraint violation. Note this method is SCALAR typed.
Definition: TerminalConstraint-impl.h:47
virtual size_t getNumNonZerosJacobianInput() const override
Returns the number of nonzeros in the jacobian wrt control input. The default implementation assumes ...
Definition: TerminalConstraint-impl.h:91
virtual VectorXs jacobianStateSparse(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt state in sparse structure. The default implementation maps the Ja...
Definition: TerminalConstraint-impl.h:98
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: TerminalConstraint.h:32
virtual size_t getNumNonZerosJacobianState() const override
Returns the number of nonzeros in the jacobian wrt state. The default implementation assumes a dense ...
Definition: TerminalConstraint-impl.h:85
TerminalConstraint(const core::StateVector< STATE_DIM, SCALAR > xf)
Custom constructor.
Definition: TerminalConstraint-impl.h:12
Base class for the constraints used in this toolbox.
Definition: ConstraintBase.h:21
virtual MatrixXs jacobianState(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt state.
Definition: TerminalConstraint-impl.h:68
Class for terminal constraint.
Definition: TerminalConstraint.h:21