47 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR =
double>
48 class DiscreteSystemLinearizerAD :
public DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>
51 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53 typedef DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR> Base;
55 typedef CppAD::AD<SCALAR> ADScalar;
56 typedef DiscreteControlledSystem<STATE_DIM, CONTROL_DIM, ADScalar> system_t;
57 typedef DynamicsLinearizerAD<STATE_DIM, CONTROL_DIM, ADScalar, int>
63 typedef typename Base::state_control_matrix_t state_control_matrix_t;
69 DiscreteSystemLinearizerAD(std::shared_ptr<system_t> nonlinearSystem)
70 : Base(nonlinearSystem->getType()),
71 dFdx_(state_matrix_t::Zero()),
72 dFdu_(state_control_matrix_t::Zero()),
73 nonlinearSystem_(nonlinearSystem),
74 linearizer_(std::bind(&system_t::propagateControlledDynamics,
75 nonlinearSystem_.get(),
76 std::placeholders::_1,
77 std::placeholders::_2,
78 std::placeholders::_3,
79 std::placeholders::_4))
84 DiscreteSystemLinearizerAD(
const DiscreteSystemLinearizerAD& arg)
85 : Base(arg.nonlinearSystem_->getType()),
88 nonlinearSystem_(arg.nonlinearSystem_->clone()),
89 linearizer_(std::bind(&system_t::propagateControlledDynamics,
90 nonlinearSystem_.get(),
91 std::placeholders::_1,
92 std::placeholders::_2,
93 std::placeholders::_3,
94 std::placeholders::_4))
99 virtual ~DiscreteSystemLinearizerAD() {}
101 DiscreteSystemLinearizerAD<STATE_DIM, CONTROL_DIM, SCALAR>* clone()
const override 103 return new DiscreteSystemLinearizerAD<STATE_DIM, CONTROL_DIM, SCALAR>(*this);
120 const state_matrix_t& getDerivativeState(
const state_vector_t& x,
const control_vector_t& u,
const int t = 0)
122 dFdx_ = linearizer_.getDerivativeState(x, u, t);
141 const state_control_matrix_t& getDerivativeControl(
const state_vector_t& x,
142 const control_vector_t& u,
145 dFdu_ = linearizer_.getDerivativeControl(x, u, t);
166 void getAandB(
const state_vector_t& x,
167 const control_vector_t& u,
168 const state_vector_t& x_next,
172 state_control_matrix_t& B)
override 174 dFdx_ = linearizer_.getDerivativeState(x, u, n);
175 dFdu_ = linearizer_.getDerivativeControl(x, u, n);
182 state_matrix_t dFdx_;
183 state_control_matrix_t dFdu_;
185 std::shared_ptr<system_t> nonlinearSystem_;
187 linearizer_t linearizer_;
Eigen::Matrix< double, nControls, 1 > control_vector_t
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
Eigen::Matrix< double, nStates, nStates > state_matrix_t
Eigen::Matrix< double, nStates, 1 > state_vector_t