- 3.0.2 optimal control module.
ControlInputConstraint.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 
20 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
21 class ControlInputConstraint : public BoxConstraintBase<CONTROL_DIM, STATE_DIM, CONTROL_DIM, SCALAR>
22 {
23 public:
24  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 
28 
31 
32  using VectorXi = Eigen::Matrix<int, Eigen::Dynamic, 1>;
33  using VectorXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>;
34  using MatrixXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic>;
35 
36  using sparsity_matrix_t = Eigen::Matrix<SCALAR, Eigen::Dynamic, CONTROL_DIM>;
37 
44  ControlInputConstraint(const control_vector_t& uLow, const control_vector_t& uHigh);
45 
52  ControlInputConstraint(const VectorXs& lb, const VectorXs& ub, const Eigen::VectorXi& control_sparsity);
53 
55 
56  virtual ~ControlInputConstraint();
57 
59 
60  virtual VectorXs evaluate(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
61 
62 #ifdef CPPADCG
63  virtual Eigen::Matrix<ct::core::ADCGScalar, Eigen::Dynamic, 1> evaluateCppadCg(
66  ct::core::ADCGScalar t) override;
67 #endif
68 
69  virtual MatrixXs jacobianState(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
70 
71  virtual MatrixXs jacobianInput(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
72 
73  virtual size_t getNumNonZerosJacobianState() const override;
74 
75  virtual size_t getNumNonZerosJacobianInput() const override;
76 
77  virtual VectorXs jacobianStateSparse(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
78 
79  virtual VectorXs jacobianInputSparse(const state_vector_t& x, const control_vector_t& u, const SCALAR t) override;
80 
81  virtual void sparsityPatternState(VectorXi& rows, VectorXi& cols) override;
82 
83  virtual void sparsityPatternInput(VectorXi& rows, VectorXi& cols) override;
84 };
85 
86 } // namespace optcon
87 } // namespace ct
virtual MatrixXs jacobianInput(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt input.
Definition: ControlInputConstraint-impl.h:79
virtual VectorXs jacobianInputSparse(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt control input in sparse structure. The default implementation map...
Definition: ControlInputConstraint-impl.h:115
virtual void sparsityPatternInput(VectorXi &rows, VectorXi &cols) override
Definition: ControlInputConstraint-impl.h:125
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
Class for control input box constraint term.
Definition: ControlInputConstraint.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: ControlInputConstraint-impl.h:68
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: ConstraintBase.h:32
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ConstraintBase.h:31
ControlInputConstraint(const control_vector_t &uLow, const control_vector_t &uHigh)
Constructor taking lower and upper state bounds directly. Assumes state box constraint is dense...
Definition: ControlInputConstraint-impl.h:12
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
typename ct::core::tpl::TraitSelector< SCALAR >::Trait Trait
Definition: ControlInputConstraint.h:26
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: ControlInputConstraint-impl.h:46
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual size_t getNumNonZerosJacobianInput() const override
Returns the number of nonzeros in the jacobian wrt control input. The default implementation assumes ...
Definition: ControlInputConstraint-impl.h:93
virtual size_t getNumNonZerosJacobianState() const override
Returns the number of nonzeros in the jacobian wrt state. The default implementation assumes a dense ...
Definition: ControlInputConstraint-impl.h:87
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
virtual ~ControlInputConstraint()
Definition: ControlInputConstraint-impl.h:34
Eigen::Matrix< SCALAR, Eigen::Dynamic, CONTROL_DIM > sparsity_matrix_t
Definition: ControlInputConstraint.h:36
Eigen::Matrix< int, Eigen::Dynamic, 1 > VectorXi
Definition: ControlInputConstraint.h:32
Base for box constraint, templated on dimension of the decision vector of the derived class...
Definition: BoxConstraintBase.h:20
virtual ControlInputConstraint< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Creates a new instance of the object with same properties than original.
Definition: ControlInputConstraint-impl.h:39
virtual void sparsityPatternState(VectorXi &rows, VectorXi &cols) override
Definition: ControlInputConstraint-impl.h:108
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: ControlInputConstraint-impl.h:100