- 3.0.1 core module.
ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR > Class Template Reference

Computes the linearization of a general non-linear DiscreteControlledSystem using Automatic Differentiation (without code generation) More...

#include <DiscreteSystemLinearizerAD.h>

Inheritance diagram for ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >:
ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > ct::core::DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > ct::core::DiscreteSystem< STATE_DIM, CONTROL_DIM, SCALAR >

Public Types

typedef CppAD::AD< SCALARADScalar
 
typedef DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, ADScalarsystem_t
 type of system to be linearized More...
 
typedef DynamicsLinearizerAD< STATE_DIM, CONTROL_DIM, ADScalar, int > linearizer_t
 type of linearizer to be used More...
 
typedef Base::state_vector_t state_vector_t
 state vector type More...
 
typedef Base::control_vector_t control_vector_t
 control vector type More...
 
typedef Base::state_matrix_t state_matrix_t
 state Jacobian type (A) More...
 
typedef Base::state_control_matrix_t state_control_matrix_t
 
- Public Types inherited from ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >
typedef Base::time_t time_t
 
typedef Base::state_vector_t state_vector_t
 
typedef Base::control_vector_t control_vector_t
 
typedef StateMatrix< STATE_DIM, SCALARstate_matrix_t
 state Jacobian type More...
 
typedef StateControlMatrix< STATE_DIM, CONTROL_DIM, SCALARstate_control_matrix_t
 input Jacobian type More...
 
- Public Types inherited from ct::core::DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >
typedef DiscreteSystem< STATE_DIM, CONTROL_DIM, SCALARBase
 
typedef Base::state_vector_t state_vector_t
 
typedef Base::control_vector_t control_vector_t
 
typedef Base::time_t time_t
 
- Public Types inherited from ct::core::DiscreteSystem< STATE_DIM, CONTROL_DIM, SCALAR >
typedef int time_t
 the type of the time variable More...
 
typedef StateVector< STATE_DIM, SCALARstate_vector_t
 
typedef ControlVector< CONTROL_DIM, SCALARcontrol_vector_t
 

Public Member Functions

 DiscreteSystemLinearizerAD (std::shared_ptr< system_t > nonlinearSystem)
 control Jacobian type (B) More...
 
 DiscreteSystemLinearizerAD (const DiscreteSystemLinearizerAD &arg)
 copy constructor More...
 
virtual ~DiscreteSystemLinearizerAD ()
 destructor More...
 
DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR > * clone () const override
 deep cloning More...
 
const state_matrix_tgetDerivativeState (const state_vector_t &x, const control_vector_t &u, const int t=0)
 get the Jacobian with respect to the state More...
 
const state_control_matrix_tgetDerivativeControl (const state_vector_t &x, const control_vector_t &u, const int t=0)
 get the Jacobian with respect to the input More...
 
void getAandB (const state_vector_t &x, const control_vector_t &u, const state_vector_t &x_next, const int n, size_t numSteps, state_matrix_t &A, state_control_matrix_t &B) override
 retrieve discrete-time linear system matrices A and B. More...
 
- Public Member Functions inherited from ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >
 DiscreteLinearSystem (const ct::core::SYSTEM_TYPE &type=ct::core::SYSTEM_TYPE::GENERAL)
 default constructor More...
 
virtual ~DiscreteLinearSystem ()
 destructor More...
 
virtual void propagateControlledDynamics (const state_vector_t &state, const time_t n, const control_vector_t &control, state_vector_t &stateNext) override
 compute the system dynamics More...
 
void getAandB (const state_vector_t &x, const control_vector_t &u, const int n, state_matrix_t &A, state_control_matrix_t &B)
 
- Public Member Functions inherited from ct::core::DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >
 DiscreteControlledSystem (const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL)
 default constructor More...
 
 DiscreteControlledSystem (std::shared_ptr< DiscreteController< STATE_DIM, CONTROL_DIM, SCALAR >> controller, const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL)
 constructor More...
 
 DiscreteControlledSystem (const ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > &arg)
 copy constructor More...
 
virtual ~DiscreteControlledSystem ()=default
 destructor More...
 
void setController (const std::shared_ptr< DiscreteController< STATE_DIM, CONTROL_DIM, SCALAR >> &controller)
 set a new controller More...
 
void getController (std::shared_ptr< DiscreteController< STATE_DIM, CONTROL_DIM, SCALAR >> &controller) const
 get the controller instance More...
 
std::shared_ptr< DiscreteController< STATE_DIM, CONTROL_DIM, SCALAR > > getController ()
 get the controller instace More...
 
virtual void propagateDynamics (const state_vector_t &state, const time_t n, state_vector_t &stateNext) override
 propagates the system dynamics forward by one step More...
 
- Public Member Functions inherited from ct::core::DiscreteSystem< STATE_DIM, CONTROL_DIM, SCALAR >
 DiscreteSystem (const SYSTEM_TYPE &type=GENERAL)
 constructor More...
 
virtual ~DiscreteSystem ()
 desctructor More...
 
virtual void propagateDynamics (const StateVector< STATE_DIM, SCALAR > &state, const time_t n, StateVector< STATE_DIM, SCALAR > &stateNext)=0
 propagates the system dynamics forward by one step More...
 
SYSTEM_TYPE getType () const
 get the type of system More...
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALARBase
 
- Public Attributes inherited from ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALARBase
 
- Public Attributes inherited from ct::core::DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > > Ptr
 

Protected Attributes

state_matrix_t dFdx_
 
state_control_matrix_t dFdu_
 
std::shared_ptr< system_tnonlinearSystem_
 instance of non-linear system More...
 
linearizer_t linearizer_
 instance of ad-linearizer More...
 
- Protected Attributes inherited from ct::core::DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >
std::shared_ptr< DiscreteController< STATE_DIM, CONTROL_DIM, SCALAR > > controller_
 the controller instance More...
 
- Protected Attributes inherited from ct::core::DiscreteSystem< STATE_DIM, CONTROL_DIM, SCALAR >
SYSTEM_TYPE type_
 type of system More...
 

Detailed Description

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
class ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >

Computes the linearization of a general non-linear DiscreteControlledSystem using Automatic Differentiation (without code generation)

This class takes a non-linear DiscreteControlledSystem $ x[n+1] = f(x[n],u[n],n) $ and computes the linearization around a certain point $ x = x_s $, $ u = u_s $.

\[ x[n+1] = A x[n] + B u[n] \]

where

\[ \begin{aligned} A &= \frac{df}{dx} |_{x=x_s, u=u_s} \\ B &= \frac{df}{du} |_{x=x_s, u=u_s} \end{aligned} \]

Note
This is generally the most accurate way to generate the linearization of system dynamics together with DiscreteSystemLinearizerADCG. However, the latter is much faster. Consider using the latter for production code.

Unit test AutoDiffLinearizerTest.cpp illustrates the use of this class.

Warning
You should ensure that your DiscreteControlledSystem is templated on the scalar type and does not contain branching (if/else statements, switch cases etc.)
This function still has some issues with pure time dependency
Todo:
Make time an Auto-Diff parameter
Template Parameters
STATE_DIMdimension of state vector
CONTROL_DIMdimension of control vector
SCALARprimitive type of resultant linear system
Examples:
AutoDiffLinearizerTest.cpp.

Member Typedef Documentation

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef CppAD::AD<SCALAR> ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::ADScalar
template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef DiscreteControlledSystem<STATE_DIM, CONTROL_DIM, ADScalar> ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::system_t

type of system to be linearized

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef DynamicsLinearizerAD<STATE_DIM, CONTROL_DIM, ADScalar, int> ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_t

type of linearizer to be used

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef Base::state_vector_t ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::state_vector_t

state vector type

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef Base::control_vector_t ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::control_vector_t

control vector type

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef Base::state_matrix_t ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::state_matrix_t

state Jacobian type (A)

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
typedef Base::state_control_matrix_t ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::state_control_matrix_t

Constructor & Destructor Documentation

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::DiscreteSystemLinearizerAD ( std::shared_ptr< system_t nonlinearSystem)
inline

control Jacobian type (B)

default constructor

Parameters
nonlinearSystemnon-linear system instance to linearize
template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::DiscreteSystemLinearizerAD ( const DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR > &  arg)
inline

copy constructor

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
virtual ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::~DiscreteSystemLinearizerAD ( )
inlinevirtual

destructor

Member Function Documentation

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
DiscreteSystemLinearizerAD<STATE_DIM, CONTROL_DIM, SCALAR>* ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::clone ( ) const
inlineoverridevirtual
template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
const state_matrix_t& ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::getDerivativeState ( const state_vector_t x,
const control_vector_t u,
const int  t = 0 
)
inline

get the Jacobian with respect to the state

This computes the linearization of the system with respect to the state at a given point $ x=x_s $, $ u=u_s $, i.e. it computes

\[ A = \frac{df}{dx} |_{x=x_s, u=u_s} \]

Parameters
xstate to linearize at
ucontrol to linearize at
ttime
Returns
Jacobian wrt state

References ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::dFdx_, ct::core::DynamicsLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeState(), ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_, and t.

Referenced by TEST().

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
const state_control_matrix_t& ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::getDerivativeControl ( const state_vector_t x,
const control_vector_t u,
const int  t = 0 
)
inline

get the Jacobian with respect to the input

This computes the linearization of the system with respect to the input at a given point $ x=x_s $, $ u=u_s $, i.e. it computes

\[ B = \frac{df}{du} |_{x=x_s, u=u_s} \]

Parameters
xstate to linearize at
ucontrol to linearize at
ttime
Returns
Jacobian wrt input

References ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::dFdu_, ct::core::DynamicsLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeControl(), ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_, and t.

Referenced by TEST().

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
void ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::getAandB ( const state_vector_t x,
const control_vector_t u,
const state_vector_t x_next,
const int  n,
size_t  numSteps,
state_matrix_t A,
state_control_matrix_t B 
)
inlineoverridevirtual

retrieve discrete-time linear system matrices A and B.

This computes matrices A and B such that

\[ x_{n+1} = Ax_n + Bu_n \]

Note that the inputs x_next and subSteps are being ignored

Parameters
xthe state setpoint at n
uthe control setpoint at n
nthe time setpoint
x_next-> ignored
subSteps-> ignored
Athe resulting linear system matrix A
Bthe resulting linear system matrix B

Implements ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >.

References ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::dFdu_, ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::dFdx_, ct::core::DynamicsLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeControl(), ct::core::DynamicsLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeState(), and ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_.

Member Data Documentation

template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR> ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::Base
template<size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
std::shared_ptr<system_t> ct::core::DiscreteSystemLinearizerAD< STATE_DIM, CONTROL_DIM, SCALAR >::nonlinearSystem_
protected

instance of non-linear system


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