![]() |
- 3.0.1 core module.
|
Computes the linearization of a general non-linear ControlledSystem using Automatic Differentiation with code generation. More...
#include <ADCodegenLinearizer.h>
Public Types | |
| typedef CppAD::AD< CppAD::cg::CG< SCALAR > > | ADCGScalar |
| Autodiff codegen type. More... | |
| typedef ControlledSystem< STATE_DIM, CONTROL_DIM, ADCGScalar > | system_t |
| type of system to be linearized More... | |
| typedef DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar > | 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 |
| input vector type More... | |
| typedef Base::state_matrix_t | state_matrix_t |
| state Jacobian type More... | |
| typedef Base::state_control_matrix_t | state_control_matrix_t |
| input Jacobian type More... | |
Public Types inherited from ct::core::LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| typedef Base::time_t | time_t |
| typedef StateVector< STATE_DIM, SCALAR > | state_vector_t |
| state vector type More... | |
| typedef ControlVector< CONTROL_DIM, SCALAR > | control_vector_t |
| input vector type More... | |
| typedef StateMatrix< STATE_DIM, SCALAR > | state_matrix_t |
| state Jacobian type More... | |
| typedef StateControlMatrix< STATE_DIM, CONTROL_DIM, SCALAR > | state_control_matrix_t |
| input Jacobian type More... | |
Public Types inherited from ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| typedef std::shared_ptr< ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > > | Ptr |
| typedef Base::time_t | time_t |
Public Types inherited from ct::core::System< STATE_DIM, SCALAR > | |
| typedef SCALAR | time_t |
| the type of the time variable More... | |
Public Member Functions | |
| ADCodegenLinearizer (std::shared_ptr< system_t > nonlinearSystem, bool cacheJac=true) | |
| default constructor More... | |
| ADCodegenLinearizer (const ADCodegenLinearizer< STATE_DIM, CONTROL_DIM > &arg) | |
| copy constructor More... | |
| ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR > * | clone () const override |
| deep cloning More... | |
| const state_matrix_t & | getDerivativeState (const state_vector_t &x, const control_vector_t &u, const SCALAR t=SCALAR(0.0)) override |
| get the Jacobian with respect to the state More... | |
| const state_control_matrix_t & | getDerivativeControl (const state_vector_t &x, const control_vector_t &u, const SCALAR t=SCALAR(0.0)) override |
| get the Jacobian with respect to the input More... | |
| void | compileJIT (const std::string &libName="ADCodegenLinearizer") |
| compile just-in-time More... | |
| void | generateCode (const std::string &systemName, const std::string &outputDir=ct::core::CODEGEN_OUTPUT_DIR, const std::string &templateDir=ct::core::CODEGEN_TEMPLATE_DIR, const std::string &ns1="core", const std::string &ns2="generated", bool useReverse=false, bool ignoreZero=true) |
| generates source code and saves it to file More... | |
| const linearizer_t & | getLinearizer () const |
| accessor to the linearizer, e.g. for testing More... | |
Public Member Functions inherited from ct::core::LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| LinearSystem (const ct::core::SYSTEM_TYPE &type=ct::core::SYSTEM_TYPE::GENERAL) | |
| default constructor More... | |
| virtual | ~LinearSystem () |
| destructor More... | |
| virtual void | computeControlledDynamics (const state_vector_t &state, const time_t &t, const control_vector_t &control, state_vector_t &derivative) override |
| compute the system dynamics More... | |
| virtual const state_matrix_t & | getDerivativeState (const state_vector_t &x, const control_vector_t &u, const time_t t=time_t(0.0))=0 |
| get the A matrix of a linear system More... | |
| virtual const state_control_matrix_t & | getDerivativeControl (const state_vector_t &x, const control_vector_t &u, const time_t t=time_t(0.0))=0 |
| get the B matrix of a linear system More... | |
| virtual void | getDerivatives (state_matrix_t &A, state_control_matrix_t &B, const state_vector_t &x, const control_vector_t &u, const time_t t=time_t(0.0)) |
| Get both linear system matrices A and B in one call. More... | |
Public Member Functions inherited from ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| ControlledSystem (const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL) | |
| default constructor More... | |
| ControlledSystem (std::shared_ptr< ct::core::Controller< STATE_DIM, CONTROL_DIM, SCALAR >> controller, const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL) | |
| constructor More... | |
| ControlledSystem (const ControlledSystem &arg) | |
| copy constructor More... | |
| virtual | ~ControlledSystem () |
| destructor More... | |
| void | setController (const std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR >> &controller) |
| set a new controller More... | |
| void | getController (std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR >> &controller) const |
| get the controller instance More... | |
| std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR > > | getController () |
| get the controller instace More... | |
| virtual void | computeDynamics (const StateVector< STATE_DIM, SCALAR > &state, const time_t &t, StateVector< STATE_DIM, SCALAR > &derivative) override |
| compute the dynamics of the system More... | |
| virtual void | computeControlledDynamics (const StateVector< STATE_DIM, SCALAR > &state, const time_t &t, const ControlVector< CONTROL_DIM, SCALAR > &control, StateVector< STATE_DIM, SCALAR > &derivative)=0 |
| ControlVector< CONTROL_DIM, SCALAR > | getLastControlAction () |
Public Member Functions inherited from ct::core::System< STATE_DIM, SCALAR > | |
| System (const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL) | |
| default constructor More... | |
| System (const System &other) | |
| copy constructor More... | |
| virtual | ~System () |
| destructor More... | |
| virtual void | computeDynamics (const StateVector< STATE_DIM, SCALAR > &state, const time_t &t, StateVector< STATE_DIM, SCALAR > &derivative)=0 |
| computes the system dynamics More... | |
| SYSTEM_TYPE | getType () const |
| get the type of system More... | |
| virtual bool | isSymplectic () const |
| Determines if the system is in symplectic form. More... | |
Public Attributes | |
| EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > | Base |
| Base class type. More... | |
Public Attributes inherited from ct::core::LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > | Base |
Public Attributes inherited from ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef System< STATE_DIM, SCALAR > | Base |
Public Attributes inherited from ct::core::System< STATE_DIM, SCALAR > | |
| EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef SCALAR | S |
| the scalar type More... | |
Additional Inherited Members | |
Protected Attributes inherited from ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
| std::shared_ptr< Controller< STATE_DIM, CONTROL_DIM, SCALAR > > | controller_ |
| the controller instance More... | |
| ControlVector< CONTROL_DIM, SCALAR > | controlAction_ |
Protected Attributes inherited from ct::core::System< STATE_DIM, SCALAR > | |
| SYSTEM_TYPE | type_ |
| type of system More... | |
Computes the linearization of a general non-linear ControlledSystem using Automatic Differentiation with code generation.
This class takes a non-linear ControlledSystem
and computes the linearization around a certain point
,
.
where
The linearization is computed using Auto Differentiation which is then used by a code generator framework to generate efficient code. For convenience just-in-time compilation is provided. However, you can also generate source code directly.
Unit test CodegenTests.cpp illustrates the use of the ADCodeGenLinearizer.
| STATE_DIM | dimension of state vector |
| CONTROL_DIM | dimension of control vector |
| SCALAR | primitive type of resultant linear system |
| typedef CppAD::AD<CppAD::cg::CG<SCALAR> > ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::ADCGScalar |
Autodiff codegen type.
| typedef ControlledSystem<STATE_DIM, CONTROL_DIM, ADCGScalar> ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::system_t |
type of system to be linearized
| typedef DynamicsLinearizerADCG<STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar> ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_t |
type of linearizer to be used
| typedef Base::state_vector_t ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::state_vector_t |
state vector type
| typedef Base::control_vector_t ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::control_vector_t |
input vector type
| typedef Base::state_matrix_t ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::state_matrix_t |
state Jacobian type
| typedef Base::state_control_matrix_t ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::state_control_matrix_t |
input Jacobian type
|
inline |
default constructor
Initializes an Auto-Diff codegen linearizer with a ControlledSystem
| nonlinearSystem | non-linear system instance |
| cacheJac | if true, caches the Jacobians to prevent recomputation for the same state/input |
|
inline |
copy constructor
|
inlineoverridevirtual |
deep cloning
Implements ct::core::LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >.
|
inlineoverride |
get the Jacobian with respect to the state
This computes the linearization of the system with respect to the state at a given point
,
, i.e. it computes
| x | state to linearize at |
| u | control to linearize at |
| t | time |
|
inlineoverride |
get the Jacobian with respect to the input
This computes the linearization of the system with respect to the input at a given point
,
, i.e. it computes
| x | state to linearize at |
| u | control to linearize at |
| t | time |
|
inline |
compile just-in-time
Generates the source code, compiles it and dynamically loads the resulting library.
|
inline |
generates source code and saves it to file
This generates source code for computing the system linearization and saves it to file. This function uses a template file in which it replaces two placeholders, each identified as the string "AUTOGENERATED_CODE_PLACEHOLDER"
| systemName | name of the resulting LinearSystem class |
| outputDir | output directory |
| templateDir | directory of the template file |
| ns1 | first layer namespace |
| ns2 | second layer namespace |
| useReverse | if true, uses Auto-Diff reverse mode |
| ignoreZero | if true, zero entries are not assigned zero |
|
inline |
accessor to the linearizer, e.g. for testing
| EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef LinearSystem<STATE_DIM, CONTROL_DIM, SCALAR> ct::core::ADCodegenLinearizer< STATE_DIM, CONTROL_DIM, SCALAR >::Base |
Base class type.