- 3.0.1 core module.
|
Computes the linearization of a general non-linear DiscreteControlledSystem using Automatic Differentiation with code generation. More...
#include <DiscreteSystemLinearizerADCG.h>
Public Member Functions | |
DiscreteSystemLinearizerADCG (std::shared_ptr< system_t > nonlinearSystem, bool cacheJac=true) | |
control Jacobian type (B) More... | |
DiscreteSystemLinearizerADCG (const DiscreteSystemLinearizerADCG &arg) | |
copy constructor More... | |
virtual | ~DiscreteSystemLinearizerADCG () |
destructor More... | |
DiscreteSystemLinearizerADCG< 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 int t=0) |
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 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... | |
void | compileJIT (const std::string &libName="DiscreteSystemLinearizerADCG") |
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::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, SCALAR > | Base |
Public Attributes inherited from ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > | Base |
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 Jacobian More... | |
state_control_matrix_t | dFdu_ |
input Jacobian More... | |
bool | cacheJac_ |
flag if Jacobian will be cached More... | |
std::shared_ptr< system_t > | nonlinearSystem_ |
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... | |
Computes the linearization of a general non-linear DiscreteControlledSystem using Automatic Differentiation with code generation.
This class takes a non-linear DiscreteControlledSystem and computes the linearization around a certain point , .
where
Unit test AutoDiffLinearizerTest.cpp illustrates the use of this class.
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.
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::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::ADCGScalar |
Autodiff codegen type.
typedef DiscreteControlledSystem<STATE_DIM, CONTROL_DIM, ADCGScalar> ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::system_t |
type of system to be linearized
typedef DynamicsLinearizerADCG<STATE_DIM, CONTROL_DIM, ADCGScalar, int> ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_t |
type of linearizer to be used
typedef Base::state_vector_t ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::state_vector_t |
state vector type
typedef Base::control_vector_t ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::control_vector_t |
control vector type
typedef Base::state_matrix_t ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::state_matrix_t |
state Jacobian type (A)
typedef Base::state_control_matrix_t ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::state_control_matrix_t |
|
inline |
control Jacobian type (B)
default constructor
nonlinearSystem | non-linear system instance to linearize |
|
inline |
copy constructor
|
inlinevirtual |
destructor
|
inlineoverridevirtual |
deep cloning
Implements ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >.
|
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 , , i.e. it computes
x | state to linearize at |
u | control to linearize at |
t | time |
References ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::dFdx_, ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeState(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_, and t.
|
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 , , i.e. it computes
x | state to linearize at |
u | control to linearize at |
t | time |
References ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::dFdu_, ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeControl(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_, and t.
|
inlineoverridevirtual |
retrieve discrete-time linear system matrices A and B.
This computes matrices A and B such that
Note that the inputs x_next and subSteps are being ignored
x | the state setpoint at n |
u | the control setpoint at n |
n | the time setpoint |
x_next | -> ignored |
subSteps | -> ignored |
A | the resulting linear system matrix A |
B | the resulting linear system matrix B |
Implements ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >.
References ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::dFdu_, ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::dFdx_, ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeControl(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getDerivativeState(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_.
|
inline |
compile just-in-time
Generates the source code, compiles it and dynamically loads the resulting library.
References ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::compileJIT(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_.
|
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 |
References ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::generateCode(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_.
|
inline |
accessor to the linearizer, e.g. for testing
References ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getMaxTempVarCount(), ct::core::internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::getOutScalarType(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::linearizer_, ct::core::internal::CGHelpers::parseFile(), ct::core::internal::CGHelpers::replaceAll(), ct::core::internal::CGHelpers::replaceOnce(), and ct::core::internal::CGHelpers::writeFile().
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR> ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::Base |
|
protected |
|
protected |
|
protected |
flag if Jacobian will be cached
|
protected |
instance of non-linear system
|
protected |
instance of ad-linearizer
Referenced by ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::compileJIT(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::generateCode(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getAandB(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getDerivativeControl(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getDerivativeState(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getLinearizer().