OCS2 Manual  v1.0.0
OCS2 Documentation
ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM > Class Template Reference

#include <ConstraintBaseAD.h>

Detailed Description

template<size_t STATE_DIM, size_t INPUT_DIM>
class ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >

The system constraint Base with Algorithmic Differentiation (i.e. Auto Differentiation). The linearized state-input constraint is defined as:
$ 0 = C(t) \delta x + D(t) \delta u + e(t) $
The linearized state-only constraint is defined as:
$ 0 = F(t) \delta x + h(t) $
The linearized final state-only constraint is defined as:
$ 0 = F_f \delta x + h_f $

Template Parameters
STATE_DIMDimension of the state space.
INPUT_DIMDimension of the control input space.
Inheritance diagram for ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >:
ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >

Public Types

using BASE = ConstraintBase< STATE_DIM, INPUT_DIM >
 
using ad_interface_t = CppAdInterface< scalar_t >
 
using ad_scalar_t = typename ad_interface_t::ad_scalar_t
 
using ad_dynamic_vector_t = typename ad_interface_t::ad_dynamic_vector_t
 
using dynamic_vector_t = typename ad_interface_t::dynamic_vector_t
 
using constraint_timeStateInput_matrix_t = Eigen::Matrix< scalar_t, -1, 1+STATE_DIM+INPUT_DIM >
 
using constraint_timeState_matrix_t = Eigen::Matrix< scalar_t, -1, 1+STATE_DIM >
 
using constraint1_input_matrix_t = typename DIMENSIONS::constraint1_input_matrix_t
 
using constraint1_state_matrix_t = typename DIMENSIONS::constraint1_state_matrix_t
 
using constraint1_vector_t = typename DIMENSIONS::constraint1_vector_t
 
using constraint2_state_matrix_t = typename DIMENSIONS::constraint2_state_matrix_t
 
using constraint2_vector_t = typename DIMENSIONS::constraint2_vector_t
 
using input_vector_t = typename DIMENSIONS::input_vector_t
 
using scalar_t = typename DIMENSIONS::scalar_t
 
using state_input_matrix_t = typename DIMENSIONS::state_input_matrix_t
 
using state_matrix_t = typename DIMENSIONS::state_matrix_t
 
using state_vector_t = typename DIMENSIONS::state_vector_t
 
- Public Types inherited from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >
using Ptr = std::shared_ptr< ConstraintBase< STATE_DIM, INPUT_DIM > >
 
using ConstPtr = std::shared_ptr< const ConstraintBase< STATE_DIM, INPUT_DIM > >
 
using DIMENSIONS = Dimensions< STATE_DIM, INPUT_DIM >
 
using scalar_t = typename DIMENSIONS::scalar_t
 
using scalar_array_t = typename DIMENSIONS::scalar_array_t
 
using state_vector_t = typename DIMENSIONS::state_vector_t
 
using state_vector_array_t = typename DIMENSIONS::state_vector_array_t
 
using input_vector_t = typename DIMENSIONS::input_vector_t
 
using input_vector_array_t = typename DIMENSIONS::input_vector_array_t
 
using state_matrix_t = typename DIMENSIONS::state_matrix_t
 
using state_matrix_array_t = typename DIMENSIONS::state_matrix_array_t
 
using input_matrix_t = typename DIMENSIONS::input_matrix_t
 
using input_matrix_array_t = typename DIMENSIONS::input_matrix_array_t
 
using state_input_matrix_t = typename DIMENSIONS::state_input_matrix_t
 
using input_state_matrix_t = typename DIMENSIONS::input_state_matrix_t
 
using input_state_matrix_array_t = typename DIMENSIONS::input_state_matrix_array_t
 
using constraint1_vector_t = typename DIMENSIONS::constraint1_vector_t
 
using constraint1_vector_array_t = typename DIMENSIONS::constraint1_vector_array_t
 
using constraint2_vector_t = typename DIMENSIONS::constraint2_vector_t
 
using constraint2_vector_array_t = typename DIMENSIONS::constraint2_vector_array_t
 
using constraint1_state_matrix_t = typename DIMENSIONS::constraint1_state_matrix_t
 
using constraint1_input_matrix_t = typename DIMENSIONS::constraint1_input_matrix_t
 
using constraint2_state_matrix_t = typename DIMENSIONS::constraint2_state_matrix_t
 

Public Member Functions

 ConstraintBaseAD ()
 
 ConstraintBaseAD (const ConstraintBaseAD &rhs)
 
void initialize (const std::string &modelName, const std::string &modelFolder="/tmp/ocs2", bool recompileLibraries=true, bool verbose=true)
 
void setCurrentStateAndControl (const scalar_t &t, const state_vector_t &x, const input_vector_t &u) final
 
void getConstraint1 (constraint1_vector_t &e) final
 
void getConstraint2 (constraint2_vector_t &h) final
 
void getFinalConstraint2 (constraint2_vector_t &h_f) final
 
void getConstraint1DerivativesState (constraint1_state_matrix_t &C) final
 
void getConstraint1DerivativesControl (constraint1_input_matrix_t &D) final
 
void getConstraint2DerivativesState (constraint2_state_matrix_t &F) final
 
void getFinalConstraint2DerivativesState (constraint2_state_matrix_t &F_f) final
 
- Public Member Functions inherited from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >
 ConstraintBase ()=default
 
 ConstraintBase (const ConstraintBase &rhs)=default
 
virtual ~ConstraintBase ()=default
 
virtual ConstraintBase< STATE_DIM, INPUT_DIM > * clone () const
 
virtual size_t numStateInputConstraint (const scalar_t &time)
 
virtual size_t numStateOnlyConstraint (const scalar_t &time)
 
virtual void getInequalityConstraint (scalar_array_t &h)
 
virtual size_t numInequalityConstraint (const scalar_t &time)
 
virtual size_t numStateOnlyFinalConstraint (const scalar_t &time)
 
virtual void getConstraint1DerivativesEventTimes (constraint1_vector_array_t &g1DevArray)
 
virtual void getInequalityConstraintDerivativesState (state_vector_array_t &dhdx)
 
virtual void getInequalityConstraintDerivativesInput (input_vector_array_t &dhdu)
 
virtual void getInequalityConstraintSecondDerivativesState (state_matrix_array_t &ddhdxdx)
 
virtual void getInequalityConstraintSecondDerivativesInput (input_matrix_array_t &ddhdudu)
 
virtual void getInequalityConstraintDerivativesInputState (input_state_matrix_array_t &ddhdudx)
 

Static Public Attributes

static EIGEN_MAKE_ALIGNED_OPERATOR_NEW constexpr size_t MAX_CONSTRAINT_DIM_ = INPUT_DIM
 

Protected Member Functions

virtual void stateInputConstraint (ad_scalar_t time, const ad_dynamic_vector_t &state, const ad_dynamic_vector_t &input, ad_dynamic_vector_t &constraintVector) const
 
virtual void stateOnlyConstraint (ad_scalar_t time, const ad_dynamic_vector_t &state, ad_dynamic_vector_t &constraintVector) const
 
virtual void stateOnlyFinalConstraint (ad_scalar_t time, const ad_dynamic_vector_t &state, ad_dynamic_vector_t &constraintVector) const
 

Private Member Functions

void setADInterfaces (const std::string &modelName, const std::string &modelFolder)
 
void createModels (bool verbose)
 
void loadModelsIfAvailable (bool verbose)
 

Private Attributes

std::unique_ptr< ad_interface_tstateInputADInterfacePtr_
 
std::unique_ptr< ad_interface_tstateOnlyADInterfacePtr_
 
std::unique_ptr< ad_interface_tstateOnlyFinalADInterfacePtr_
 
constraint_timeStateInput_matrix_t stateInputJacobian_
 
constraint_timeState_matrix_t stateOnlyJacobian_
 
constraint_timeState_matrix_t stateOnlyFinalJacobian_
 
constraint1_vector_t stateInputValues_
 
constraint2_vector_t stateOnlyValues_
 
constraint2_vector_t stateOnlyFinalValues_
 

Additional Inherited Members

- Protected Attributes inherited from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >
scalar_t t_
 
state_vector_t x_
 
input_vector_t u_
 

Member Typedef Documentation

◆ ad_dynamic_vector_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::ad_dynamic_vector_t = typename ad_interface_t::ad_dynamic_vector_t

◆ ad_interface_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::ad_interface_t = CppAdInterface<scalar_t>

◆ ad_scalar_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::ad_scalar_t = typename ad_interface_t::ad_scalar_t

◆ BASE

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::BASE = ConstraintBase<STATE_DIM, INPUT_DIM>

◆ constraint1_input_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::constraint1_input_matrix_t = typename DIMENSIONS::constraint1_input_matrix_t

◆ constraint1_state_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::constraint1_state_matrix_t = typename DIMENSIONS::constraint1_state_matrix_t

◆ constraint1_vector_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::constraint1_vector_t = typename DIMENSIONS::constraint1_vector_t

◆ constraint2_state_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::constraint2_state_matrix_t = typename DIMENSIONS::constraint2_state_matrix_t

◆ constraint2_vector_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::constraint2_vector_t = typename DIMENSIONS::constraint2_vector_t

◆ constraint_timeState_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::constraint_timeState_matrix_t = Eigen::Matrix<scalar_t, -1, 1 + STATE_DIM>

◆ constraint_timeStateInput_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::constraint_timeStateInput_matrix_t = Eigen::Matrix<scalar_t, -1, 1 + STATE_DIM + INPUT_DIM>

◆ dynamic_vector_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::dynamic_vector_t = typename ad_interface_t::dynamic_vector_t

◆ input_vector_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::input_vector_t = typename DIMENSIONS::input_vector_t

◆ scalar_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::scalar_t = typename DIMENSIONS::scalar_t

◆ state_input_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::state_input_matrix_t = typename DIMENSIONS::state_input_matrix_t

◆ state_matrix_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::state_matrix_t = typename DIMENSIONS::state_matrix_t

◆ state_vector_t

template<size_t STATE_DIM, size_t INPUT_DIM>
using ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >::state_vector_t = typename DIMENSIONS::state_vector_t

Member Function Documentation

◆ getConstraint1()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getConstraint1 ( constraint1_vector_t e)
inlinefinalvirtual

Computes the state-input equality constraints.

Parameters
[out]eThe state-input equality constraints value.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ getConstraint1DerivativesControl()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getConstraint1DerivativesControl ( constraint1_input_matrix_t D)
inlinefinalvirtual

The D matrix at a given operating point for the linearized state-input constraints, $ C(t) \delta x + D(t) \delta u + e(t) = 0 $.

Parameters
[out]D$ D(t) $ matrix.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ getConstraint1DerivativesState()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getConstraint1DerivativesState ( constraint1_state_matrix_t C)
inlinefinalvirtual

The C matrix at a given operating point for the linearized state-input constraints, $ C(t) \delta x + D(t) \delta u + e(t) = 0 $.

Parameters
[out]C$ C(t) $ matrix.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ getConstraint2()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getConstraint2 ( constraint2_vector_t h)
inlinefinalvirtual

Gets the state-only equality constraints.

Parameters
[out]hThe state-only (in)equality constraints value.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ getConstraint2DerivativesState()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getConstraint2DerivativesState ( constraint2_state_matrix_t F)
inlinefinalvirtual

The F matrix at a given operating point for the linearized state-only constraints, $ F(t) \delta x + h(t) = 0 $.

Parameters
[out]F$ F(t) $ matrix.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ getFinalConstraint2()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getFinalConstraint2 ( constraint2_vector_t h_f)
inlinefinalvirtual

Compute the final state-only equality constraints.

Parameters
[out]h_fThe final state-only (in)equality constraints value.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ getFinalConstraint2DerivativesState()

template<size_t STATE_DIM, size_t INPUT_DIM>
void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::getFinalConstraint2DerivativesState ( constraint2_state_matrix_t F_f)
inlinefinalvirtual

The F matrix at a given operating point for the linearized terminal state-only constraints, $ F_f(t) \delta x + h_f(t) = 0 $.

Parameters
[out]F_f$ F_f(t) $ matrix.

Reimplemented from ocs2::ConstraintBase< STATE_DIM, INPUT_DIM >.

◆ stateInputConstraint()

template<size_t STATE_DIM, size_t INPUT_DIM>
virtual void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateInputConstraint ( ad_scalar_t  time,
const ad_dynamic_vector_t state,
const ad_dynamic_vector_t input,
ad_dynamic_vector_t constraintVector 
) const
inlineprotectedvirtual

Interface method to the state-input equality constraints. This method should be implemented by the derived class.

Parameters
[in]timetime.
[in]statestate vector.
[in]inputinput vector
[out]constraintVectorconstraints vector.

◆ stateOnlyConstraint()

template<size_t STATE_DIM, size_t INPUT_DIM>
virtual void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyConstraint ( ad_scalar_t  time,
const ad_dynamic_vector_t state,
ad_dynamic_vector_t constraintVector 
) const
inlineprotectedvirtual

Interface method to the state-only equality constraints. This method should be implemented by the derived class.

Parameters
[in]timetime.
[in]statestate vector.
[out]constraintVectorconstraint vector.

◆ stateOnlyFinalConstraint()

template<size_t STATE_DIM, size_t INPUT_DIM>
virtual void ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyFinalConstraint ( ad_scalar_t  time,
const ad_dynamic_vector_t state,
ad_dynamic_vector_t constraintVector 
) const
inlineprotectedvirtual

Interface method to the state-only final equality constraints. This method should be implemented by the derived class.

Parameters
[in]timetime.
[in]statestate vector.
[out]constraintVectorconstraint vector.

Member Data Documentation

◆ MAX_CONSTRAINT_DIM_

template<size_t STATE_DIM, size_t INPUT_DIM>
EIGEN_MAKE_ALIGNED_OPERATOR_NEW constexpr size_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::MAX_CONSTRAINT_DIM_ = INPUT_DIM
static

◆ stateInputADInterfacePtr_

template<size_t STATE_DIM, size_t INPUT_DIM>
std::unique_ptr<ad_interface_t> ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateInputADInterfacePtr_
private

◆ stateInputJacobian_

template<size_t STATE_DIM, size_t INPUT_DIM>
constraint_timeStateInput_matrix_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateInputJacobian_
private

◆ stateInputValues_

template<size_t STATE_DIM, size_t INPUT_DIM>
constraint1_vector_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateInputValues_
private

◆ stateOnlyADInterfacePtr_

template<size_t STATE_DIM, size_t INPUT_DIM>
std::unique_ptr<ad_interface_t> ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyADInterfacePtr_
private

◆ stateOnlyFinalADInterfacePtr_

template<size_t STATE_DIM, size_t INPUT_DIM>
std::unique_ptr<ad_interface_t> ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyFinalADInterfacePtr_
private

◆ stateOnlyFinalJacobian_

template<size_t STATE_DIM, size_t INPUT_DIM>
constraint_timeState_matrix_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyFinalJacobian_
private

◆ stateOnlyFinalValues_

template<size_t STATE_DIM, size_t INPUT_DIM>
constraint2_vector_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyFinalValues_
private

◆ stateOnlyJacobian_

template<size_t STATE_DIM, size_t INPUT_DIM>
constraint_timeState_matrix_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyJacobian_
private

◆ stateOnlyValues_

template<size_t STATE_DIM, size_t INPUT_DIM>
constraint2_vector_t ocs2::ConstraintBaseAD< STATE_DIM, INPUT_DIM >::stateOnlyValues_
private

The documentation for this class was generated from the following file: