25 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR,
typename TIME>
26 class DynamicsLinearizerADBase
29 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
32 static_assert((std::is_same<
SCALAR, CppAD::AD<double>>::value) ||
33 (std::is_same<
SCALAR, CppAD::AD<CppAD::cg::CG<double>>>::value) ||
34 (std::is_same<
SCALAR, CppAD::AD<float>>::value) ||
35 (std::is_same<
SCALAR, CppAD::AD<CppAD::cg::CG<float>>>::value),
36 "SCALAR template parameter in ADLinearizerBase should either be of CppAD::AD<XX> or " 37 "CppAD::AD<CppAD::cg::XX> type with XX being float or double");
39 typedef typename std::conditional<(std::is_same<SCALAR, CppAD::AD<double>>::value) ||
40 (std::is_same<
SCALAR, CppAD::AD<CppAD::cg::CG<double>>>::value),
42 float>::type OUT_SCALAR;
47 typedef StateVector<STATE_DIM, SCALAR> state_vector_ad_t;
48 typedef ControlVector<CONTROL_DIM, SCALAR> control_vector_ad_t;
51 typedef StateControlMatrix<STATE_DIM, CONTROL_DIM, OUT_SCALAR> state_control_matrix_t;
53 typedef std::function<void(const state_vector_ad_t&, const TIME&, const control_vector_ad_t&, state_vector_ad_t&)>
60 DynamicsLinearizerADBase(dynamics_fct_t dyn) : dynamics_fct_(dyn) { initialize(); }
62 DynamicsLinearizerADBase(
const DynamicsLinearizerADBase& arg) : dynamics_fct_(arg.dynamics_fct_)
69 template <
typename T = std::
string>
70 typename std::enable_if<std::is_same<OUT_SCALAR, double>::value, T>::type getOutScalarType()
const 75 template <
typename T = std::
string>
76 typename std::enable_if<std::is_same<OUT_SCALAR, float>::value, T>::type getOutScalarType()
const 81 virtual ~DynamicsLinearizerADBase() =
default;
84 const size_t A_entries = STATE_DIM * STATE_DIM;
85 const size_t B_entries = STATE_DIM * CONTROL_DIM;
86 const size_t FullJac_entries =
87 (STATE_DIM + CONTROL_DIM) * STATE_DIM;
104 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>
x(STATE_DIM + CONTROL_DIM);
109 CppAD::Independent(x);
112 state_vector_ad_t xFixed =
x.template head<STATE_DIM>();
113 control_vector_ad_t uFixed =
x.template tail<CONTROL_DIM>();
115 state_vector_ad_t dxFixed;
117 dynamics_fct_(xFixed, TIME(0.0), uFixed, dxFixed);
120 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> dx(STATE_DIM);
124 CppAD::ADFun<typename SCALAR::value_type> f(x, dx);
132 void setupSparsityA()
136 Eigen::Matrix<bool, STATE_DIM + CONTROL_DIM, STATE_DIM> sparsity;
138 sparsity.template topRows<STATE_DIM>().setOnes();
140 sparsityA_.initPattern(sparsity);
141 sparsityA_.clearWork();
145 void setupSparsityB()
149 Eigen::Matrix<bool, STATE_DIM + CONTROL_DIM, STATE_DIM> sparsity;
151 sparsity.template bottomRows<CONTROL_DIM>().setOnes();
153 sparsityB_.initPattern(sparsity);
154 sparsityB_.clearWork();
157 dynamics_fct_t dynamics_fct_;
158 CppAD::ADFun<typename SCALAR::value_type> f_;
160 SparsityPattern sparsityA_;
161 SparsityPattern sparsityB_;
Eigen::Matrix< double, nControls, 1 > control_vector_t
CppAD::AD< CppAD::cg::CG< double > > SCALAR
ct::core::StateVector< state_dim > x
Eigen::Matrix< double, nStates, nStates > state_matrix_t
Eigen::Matrix< double, nStates, 1 > state_vector_t