- 3.0.1 core module.
|
Computes the linearization of a system dynamics function through autodiff with code generation. More...
#include <DynamicsLinearizerADCG.h>
Public Types | |
typedef Base::OUT_SCALAR | OUT_SCALAR |
scalar type of resulting linear system 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 |
control Jacobian type (B) More... | |
typedef Base::dynamics_fct_t | dynamics_fct_t |
dynamics function signature More... | |
Public Types inherited from ct::core::internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME > | |
typedef std::conditional<(std::is_same< SCALAR, CppAD::AD< double >>::value)||(std::is_same< SCALAR, CppAD::AD< CppAD::cg::CG< double >>>::value), double, float >::type | OUT_SCALAR |
scalar type of resulting linear system More... | |
typedef StateVector< STATE_DIM, OUT_SCALAR > | state_vector_t |
typedef ControlVector< CONTROL_DIM, OUT_SCALAR > | control_vector_t |
typedef StateVector< STATE_DIM, SCALAR > | state_vector_ad_t |
typedef ControlVector< CONTROL_DIM, SCALAR > | control_vector_ad_t |
typedef StateMatrix< STATE_DIM, OUT_SCALAR > | state_matrix_t |
typedef StateControlMatrix< STATE_DIM, CONTROL_DIM, OUT_SCALAR > | state_control_matrix_t |
typedef std::function< void(const state_vector_ad_t &, const TIME &, const control_vector_ad_t &, state_vector_ad_t &)> | dynamics_fct_t |
dynamics function signature More... | |
Public Member Functions | |
DynamicsLinearizerADCG (dynamics_fct_t dyn, bool cacheJac=true) | |
default constructor More... | |
DynamicsLinearizerADCG (const DynamicsLinearizerADCG &rhs) | |
copy constructor More... | |
const state_matrix_t & | getDerivativeState (const state_vector_t &x, const control_vector_t &u, const OUT_SCALAR t=0.0) |
compute and return derivative w.r.t. state More... | |
const state_control_matrix_t & | getDerivativeControl (const state_vector_t &x, const control_vector_t &u, const OUT_SCALAR t=0.0) |
compute and return derivative w.r.t. control More... | |
void | compileJIT (const std::string &libName="DynamicsLinearizerADCG", bool verbose=false) |
compile just-in-time More... | |
void | generateCode (std::string &codeJacA, std::string &codeJacB, bool useReverse=false, bool ignoreZero=true) |
generates source code More... | |
void | getMaxTempVarCount (size_t &maxTempVarCountState, size_t &maxTempVarCountControl) const |
accessor to maxTempVarCount variables More... | |
const std::shared_ptr< CppAD::cg::DynamicLib< OUT_SCALAR > > | getDynamicLib () const |
retrieve the dynamic library, e.g. for testing purposes More... | |
Public Member Functions inherited from ct::core::internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME > | |
DynamicsLinearizerADBase (dynamics_fct_t dyn) | |
default constructor More... | |
DynamicsLinearizerADBase (const DynamicsLinearizerADBase &arg) | |
copy constructor More... | |
template<typename T = std::string> | |
std::enable_if< std::is_same< OUT_SCALAR, double >::value, T >::type | getOutScalarType () const |
template<typename T = std::string> | |
std::enable_if< std::is_same< OUT_SCALAR, float >::value, T >::type | getOutScalarType () const |
virtual | ~DynamicsLinearizerADBase () |
destructor More... | |
Public Attributes | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME > | Base |
Public Attributes inherited from ct::core::internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME > | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW | |
Protected Member Functions | |
void | computeJacobian (const state_vector_t &x, const control_vector_t &u) |
computes the Jacobians More... | |
Protected Member Functions inherited from ct::core::internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME > | |
void | initialize () |
initialize all utilities More... | |
void | recordTerms () |
record the model More... | |
void | setupSparsityA () |
setup the sparsity of the state Jacobian More... | |
void | setupSparsityB () |
setup the sparsity of the input Jacobian More... | |
Protected Attributes | |
dynamics_fct_t | dynamics_fct_ |
function handle to system dynamics More... | |
state_matrix_t | dFdx_ |
Jacobian wrt state. More... | |
state_control_matrix_t | dFdu_ |
Jacobian wrt input. More... | |
state_vector_t | x_at_cache_ |
state at which Jacobian has been cached More... | |
control_vector_t | u_at_cache_ |
input at which Jacobian has been cached More... | |
std::string | jitLibName_ |
name of the library compiled with JIT More... | |
bool | compiled_ |
flag if library from generated code is compiled More... | |
bool | cacheJac_ |
flag if Jacobian will be cached More... | |
CppAD::cg::GccCompiler< OUT_SCALAR > | compiler_ |
compiler instance for JIT compilation More... | |
std::shared_ptr< CppAD::cg::DynamicLib< OUT_SCALAR > > | dynamicLib_ |
compiled and dynamically loaded library More... | |
std::shared_ptr< CppAD::cg::GenericModel< OUT_SCALAR > > | model_ |
Auto-Diff model. More... | |
size_t | maxTempVarCountState_ |
number of temporary variables in the source code of the state Jacobian More... | |
size_t | maxTempVarCountControl_ |
number of temporary variables in the source code of the input Jacobian More... | |
Protected Attributes inherited from ct::core::internal::DynamicsLinearizerADBase< STATE_DIM, CONTROL_DIM, SCALAR, TIME > | |
const size_t | A_entries = STATE_DIM * STATE_DIM |
number of entries in the state Jacobian More... | |
const size_t | B_entries = STATE_DIM * CONTROL_DIM |
number of entries in the input Jacobian More... | |
const size_t | FullJac_entries |
number of entries in the stacked Jacobian More... | |
dynamics_fct_t | dynamics_fct_ |
function handle to system dynamics More... | |
CppAD::ADFun< typename SCALAR::value_type > | f_ |
Auto-Diff function. More... | |
SparsityPattern | sparsityA_ |
sparsity pattern of the state Jacobian More... | |
SparsityPattern | sparsityB_ |
sparsity pattern of the input Jacobian More... | |
Computes the linearization of a system dynamics function through autodiff with code generation.
This class takes a function handle representing system dynamics of the form or where the last argument is the result of the evaluation in each case. It then computes the linearization around a given point , .
STATE_DIM | dimension of state vector |
CONTROL_DIM | dimension of control vector |
SCALAR | scalar type |
TIME | type of time variable of dynamics |
typedef Base::OUT_SCALAR ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::OUT_SCALAR |
scalar type of resulting linear system
typedef Base::state_vector_t ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::state_vector_t |
state vector type
typedef Base::control_vector_t ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::control_vector_t |
control vector type
typedef Base::state_matrix_t ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::state_matrix_t |
state Jacobian type (A)
typedef Base::state_control_matrix_t ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::state_control_matrix_t |
control Jacobian type (B)
typedef Base::dynamics_fct_t ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::dynamics_fct_t |
dynamics function signature
|
inline |
default constructor
Initializes the DynamicsLinearizerADCG with the system dynamics
dyn | function handle to system dynamics |
cacheJac | if true, caches the Jacobians to prevent recomputation for same state/control |
|
inline |
copy constructor
|
inline |
compute and return derivative w.r.t. state
x | state to linearize at |
u | control to linearize at |
t | time |
Referenced by ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getAandB(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getDerivativeState(), and ct::core::ADCodegenLinearizer< state_dim, control_dim >::getDerivativeState().
|
inline |
compute and return derivative w.r.t. control
x | state to linearize at |
u | control to linearize at |
t | time |
Referenced by ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getAandB(), ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getDerivativeControl(), and ct::core::ADCodegenLinearizer< state_dim, control_dim >::getDerivativeControl().
|
inline |
compile just-in-time
Generates the source code, compiles it and dynamically loads the resulting library.
Referenced by ct::core::ADCodegenLinearizer< state_dim, control_dim >::compileJIT(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::compileJIT().
|
inline |
generates source code
This generates source code for computing the system linearization. The generated string should be passed to a function which writes the generated code to a file.
This function uses a template file in which it replaces two placeholders, each identified as the string "AUTOGENERATED_CODE_PLACEHOLDER"
[out] | codeJacA | string with the generated code for the A matrix |
[out] | codeJacB | string with the generated code for the B matrix |
[in] | useReverse | if true, uses Auto-Diff reverse mode |
[in] | ignoreZero | if true, zero entries are not assigned zero |
Referenced by ct::core::ADCodegenLinearizer< state_dim, control_dim >::generateCode(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::generateCode().
|
inline |
accessor to maxTempVarCount variables
Referenced by ct::core::ADCodegenLinearizer< state_dim, control_dim >::getLinearizer(), and ct::core::DiscreteSystemLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR >::getLinearizer().
|
inline |
retrieve the dynamic library, e.g. for testing purposes
|
inlineprotected |
computes the Jacobians
Given a state and input this method evaluates both Jacobians and caches them
x | state to linearize around |
u | input to linearize around |
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeControl(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeState().
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef internal::DynamicsLinearizerADBase<STATE_DIM, CONTROL_DIM, SCALAR, TIME> ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, SCALAR, TIME >::Base |
|
protected |
function handle to system dynamics
|
protected |
|
protected |
|
protected |
state at which Jacobian has been cached
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::computeJacobian(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeControl(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeState().
|
protected |
input at which Jacobian has been cached
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::computeJacobian(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeControl(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeState().
|
protected |
name of the library compiled with JIT
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::compileJIT(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::DynamicsLinearizerADCG().
|
protected |
flag if library from generated code is compiled
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::compileJIT(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::DynamicsLinearizerADCG(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeControl(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeState().
|
protected |
flag if Jacobian will be cached
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeControl(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDerivativeState().
|
protected |
compiler instance for JIT compilation
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::compileJIT().
|
protected |
compiled and dynamically loaded library
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::compileJIT(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::DynamicsLinearizerADCG(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getDynamicLib().
|
protected |
Auto-Diff model.
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::compileJIT(), ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::computeJacobian(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::DynamicsLinearizerADCG().
|
protected |
number of temporary variables in the source code of the state Jacobian
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::generateCode(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getMaxTempVarCount().
|
protected |
number of temporary variables in the source code of the input Jacobian
Referenced by ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::generateCode(), and ct::core::DynamicsLinearizerADCG< STATE_DIM, CONTROL_DIM, ADCGScalar, ADCGScalar >::getMaxTempVarCount().