10 #ifndef CROCODDYL_CORE_INTEGRATOR_RK4_HPP_
11 #define CROCODDYL_CORE_INTEGRATOR_RK4_HPP_
13 #include "crocoddyl/core/fwd.hpp"
14 #include "crocoddyl/core/integ-action-base.hpp"
15 #include "crocoddyl/core/utils/deprecate.hpp"
36 template <
typename _Scalar>
40 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42 typedef _Scalar Scalar;
51 typedef typename MathBase::VectorXs VectorXs;
52 typedef typename MathBase::MatrixXs MatrixXs;
64 boost::shared_ptr<DifferentialActionModelAbstract> model,
65 boost::shared_ptr<ControlParametrizationModelAbstract> control,
66 const Scalar time_step = Scalar(1e-3),
67 const bool with_cost_residual =
true);)
81 boost::shared_ptr<DifferentialActionModelAbstract> model,
82 const Scalar time_step = Scalar(1e-3),
83 const bool with_cost_residual =
true);)
93 virtual void calc(
const boost::shared_ptr<ActionDataAbstract>& data,
94 const Eigen::Ref<const VectorXs>& x,
95 const Eigen::Ref<const VectorXs>& u);
107 virtual void calc(
const boost::shared_ptr<ActionDataAbstract>& data,
108 const Eigen::Ref<const VectorXs>& x);
117 virtual void calcDiff(
const boost::shared_ptr<ActionDataAbstract>& data,
118 const Eigen::Ref<const VectorXs>& x,
119 const Eigen::Ref<const VectorXs>& u);
131 virtual void calcDiff(
const boost::shared_ptr<ActionDataAbstract>& data,
132 const Eigen::Ref<const VectorXs>& x);
144 virtual bool checkData(
const boost::shared_ptr<ActionDataAbstract>& data);
159 virtual void quasiStatic(
const boost::shared_ptr<ActionDataAbstract>& data,
160 Eigen::Ref<VectorXs> u,
161 const Eigen::Ref<const VectorXs>& x,
162 const std::size_t maxiter = 100,
163 const Scalar tol = Scalar(1e-9));
170 virtual void print(std::ostream& os)
const;
185 std::array<Scalar, 4> rk4_c_;
188 template <
typename _Scalar>
191 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
193 typedef _Scalar Scalar;
200 typedef typename MathBase::VectorXs VectorXs;
201 typedef typename MathBase::MatrixXs MatrixXs;
203 template <
template <
typename Scalar>
class Model>
206 integral(4, Scalar(0.)),
207 dx(model->get_state()->get_ndx()),
208 ki(4, VectorXs::Zero(model->get_state()->get_ndx())),
209 y(4, VectorXs::Zero(model->get_state()->get_nx())),
210 ws(4, VectorXs::Zero(model->get_control()->get_nw())),
211 dx_rk4(4, VectorXs::Zero(model->get_state()->get_ndx())),
212 dki_dx(4, MatrixXs::Zero(model->get_state()->get_ndx(),
213 model->get_state()->get_ndx())),
215 MatrixXs::Zero(model->get_state()->get_ndx(), model->get_nu())),
216 dyi_dx(4, MatrixXs::Zero(model->get_state()->get_ndx(),
217 model->get_state()->get_ndx())),
219 MatrixXs::Zero(model->get_state()->get_ndx(), model->get_nu())),
220 dli_dx(4, VectorXs::Zero(model->get_state()->get_ndx())),
221 dli_du(4, VectorXs::Zero(model->get_nu())),
222 ddli_ddx(4, MatrixXs::Zero(model->get_state()->get_ndx(),
223 model->get_state()->get_ndx())),
224 ddli_ddw(4, MatrixXs::Zero(model->get_control()->get_nw(),
225 model->get_control()->get_nw())),
226 ddli_ddu(4, MatrixXs::Zero(model->get_nu(), model->get_nu())),
227 ddli_dxdw(4, MatrixXs::Zero(model->get_state()->get_ndx(),
228 model->get_control()->get_nw())),
230 4, MatrixXs::Zero(model->get_state()->get_ndx(), model->get_nu())),
232 4, MatrixXs::Zero(model->get_control()->get_nw(), model->get_nu())),
233 Luu_partialx(4, MatrixXs::Zero(model->get_nu(), model->get_nu())),
235 MatrixXs::Zero(model->get_state()->get_ndx(), model->get_nu())),
236 Lxx_partialx(4, MatrixXs::Zero(model->get_state()->get_ndx(),
237 model->get_state()->get_ndx())),
239 4, MatrixXs::Zero(model->get_state()->get_ndx(), model->get_nu())) {
242 for (std::size_t i = 0; i < 4; ++i) {
243 differential.push_back(boost::shared_ptr<DifferentialActionDataAbstract>(
244 model->get_differential()->createData()));
245 control.push_back(boost::shared_ptr<ControlParametrizationDataAbstract>(
246 model->get_control()->createData()));
249 const std::size_t nv = model->get_state()->get_nv();
250 dyi_dx[0].diagonal().setOnes();
251 dki_dx[0].topRightCorner(nv, nv).diagonal().setOnes();
255 std::vector<boost::shared_ptr<DifferentialActionDataAbstract> >
257 std::vector<boost::shared_ptr<ControlParametrizationDataAbstract> >
259 std::vector<Scalar> integral;
261 std::vector<VectorXs>
ki;
262 std::vector<VectorXs>
264 std::vector<VectorXs>
266 std::vector<VectorXs> dx_rk4;
268 std::vector<MatrixXs>
271 std::vector<MatrixXs>
275 std::vector<MatrixXs>
278 std::vector<MatrixXs>
282 std::vector<VectorXs>
285 std::vector<VectorXs>
289 std::vector<MatrixXs>
292 std::vector<MatrixXs>
299 std::vector<MatrixXs>
303 std::vector<MatrixXs>
307 std::vector<MatrixXs>
312 std::vector<MatrixXs> Luu_partialx;
313 std::vector<MatrixXs> Lxu_i;
314 std::vector<MatrixXs> Lxx_partialx;
315 std::vector<MatrixXs> Lxx_partialu;
334 #include "crocoddyl/core/integrator/rk4.hxx"
Abstract class for action model.
std::size_t nh_
Number of equality constraints.
std::size_t ng_
Number of inequality constraints.
Abstract class for the control trajectory parametrization.
Abstract class for differential action model.
Abstract class for an integrated action model.
bool with_cost_residual_
Flag indicating whether a cost residual is used.
Scalar time_step_
Time step used for integration.
boost::shared_ptr< DifferentialActionModelAbstract > differential_
Differential action model that is integrated.
boost::shared_ptr< ControlParametrizationModelAbstract > control_
Model of the control parametrization.
boost::shared_ptr< StateAbstract > state_
< Dimension of the control
std::size_t nu_
< Dimension of the cost residual
Scalar time_step2_
Square of the time step used for integration.
virtual void print(std::ostream &os) const
Print relevant information of the RK4 integrator model.
virtual void calc(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Integrate the differential action model using RK4 scheme.
DEPRECATED("Use IntegratedActionModelRK", IntegratedActionModelRK4Tpl(boost::shared_ptr< DifferentialActionModelAbstract > model, boost::shared_ptr< ControlParametrizationModelAbstract > control, const Scalar time_step=Scalar(1e-3), const bool with_cost_residual=true);) DEPRECATED("Use IntegratedActionModelRK"
Initialize the RK4 integrator.
virtual void calcDiff(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the partial derivatives of the RK4 integrator.
virtual bool checkData(const boost::shared_ptr< ActionDataAbstract > &data)
Checks that a specific data belongs to this model.
virtual void calc(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Integrate the total cost value for nodes that depends only on the state using RK4 scheme.
virtual void calcDiff(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the partial derivatives of the cost.
virtual boost::shared_ptr< ActionDataAbstract > createData()
Create the RK4 integrator data.
virtual void quasiStatic(const boost::shared_ptr< ActionDataAbstract > &data, Eigen::Ref< VectorXs > u, const Eigen::Ref< const VectorXs > &x, const std::size_t maxiter=100, const Scalar tol=Scalar(1e-9))
Computes the quasic static commands.
VectorXs xnext
evolution state
MatrixXs Fx
Jacobian of the dynamics w.r.t. the state .
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
MatrixXs Luu
Hessian of the cost w.r.t. the control .
VectorXs Lx
Jacobian of the cost w.r.t. the state .
MatrixXs Lxx
Hessian of the cost w.r.t. the state .
VectorXs Lu
Jacobian of the cost w.r.t. the control .
std::vector< MatrixXs > ddli_ddx
std::vector< VectorXs > ki
List of RK4 terms related to system dynamics.
std::vector< MatrixXs > dki_du
std::vector< MatrixXs > dki_dx
std::vector< MatrixXs > ddli_ddu
std::vector< MatrixXs > ddli_dxdw
std::vector< MatrixXs > ddli_ddw
std::vector< boost::shared_ptr< DifferentialActionDataAbstract > > differential
List of differential model data.
std::vector< MatrixXs > ddli_dwdu
std::vector< MatrixXs > dyi_du
std::vector< VectorXs > y
List of states where f is evaluated in the RK4 integration.
std::vector< VectorXs > dli_du
std::vector< MatrixXs > ddli_dxdu
std::vector< VectorXs > dli_dx
std::vector< boost::shared_ptr< ControlParametrizationDataAbstract > > control
List of control parametrization data.
std::vector< MatrixXs > dyi_dx
std::vector< VectorXs > ws
Control inputs evaluated in the RK4 integration.