Crocoddyl
impulse-com.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_MULTIBODY_RESIDUALS_IMPULSE_COM_HPP_
10 #define CROCODDYL_MULTIBODY_RESIDUALS_IMPULSE_COM_HPP_
11 
12 #include "crocoddyl/core/residual-base.hpp"
13 #include "crocoddyl/core/utils/exception.hpp"
14 #include "crocoddyl/multibody/data/impulses.hpp"
15 #include "crocoddyl/multibody/fwd.hpp"
16 #include "crocoddyl/multibody/impulse-base.hpp"
17 #include "crocoddyl/multibody/states/multibody.hpp"
18 
19 namespace crocoddyl {
20 
37 template <typename _Scalar>
39  public:
40  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 
42  typedef _Scalar Scalar;
50  typedef typename MathBase::VectorXs VectorXs;
51 
57  ResidualModelImpulseCoMTpl(boost::shared_ptr<StateMultibody> state);
58  virtual ~ResidualModelImpulseCoMTpl();
59 
67  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data,
68  const Eigen::Ref<const VectorXs>& x,
69  const Eigen::Ref<const VectorXs>& u);
70 
78  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data,
79  const Eigen::Ref<const VectorXs>& x,
80  const Eigen::Ref<const VectorXs>& u);
81 
85  virtual boost::shared_ptr<ResidualDataAbstract> createData(
86  DataCollectorAbstract* const data);
87 
93  virtual void print(std::ostream& os) const;
94 
95  protected:
96  using Base::nu_;
97  using Base::state_;
98  using Base::u_dependent_;
99 
100  private:
101  boost::shared_ptr<typename StateMultibody::PinocchioModel> pin_model_;
102 };
103 
104 template <typename _Scalar>
106  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
107 
108  typedef _Scalar Scalar;
113  typedef typename MathBase::MatrixXs MatrixXs;
114  typedef typename MathBase::Matrix3xs Matrix3xs;
115 
116  template <template <typename Scalar> class Model>
117  ResidualDataImpulseCoMTpl(Model<Scalar>* const model,
118  DataCollectorAbstract* const data)
119  : Base(model, data),
120  dvc_dq(3, model->get_state()->get_nv()),
121  ddv_dv(model->get_state()->get_nv(), model->get_state()->get_nv()) {
122  dvc_dq.setZero();
123  ddv_dv.setZero();
124  const boost::shared_ptr<StateMultibody>& state =
125  boost::static_pointer_cast<StateMultibody>(model->get_state());
127  pinocchio::DataTpl<Scalar>(*state->get_pinocchio().get());
128  // Check that proper shared data has been passed
131  if (d == NULL) {
132  throw_pretty(
133  "Invalid argument: the shared data should be derived from "
134  "DataCollectorMultibodyInImpulse");
135  }
136  pinocchio = d->pinocchio;
137  impulses = d->impulses;
138  }
139 
140  pinocchio::DataTpl<Scalar>* pinocchio;
141  boost::shared_ptr<crocoddyl::ImpulseDataMultipleTpl<Scalar> >
143  Matrix3xs dvc_dq;
144  MatrixXs ddv_dv;
145  pinocchio::DataTpl<Scalar>
147  using Base::r;
148  using Base::Ru;
149  using Base::Rx;
150  using Base::shared;
151 };
152 
153 } // namespace crocoddyl
154 
155 /* --- Details -------------------------------------------------------------- */
156 /* --- Details -------------------------------------------------------------- */
157 /* --- Details -------------------------------------------------------------- */
158 #include "crocoddyl/multibody/residuals/impulse-com.hxx"
159 
160 #endif // CROCODDYL_MULTIBODY_RESIDUALS_IMPULSE_COM_HPP_
Abstract class for residual models.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
virtual void print(std::ostream &os) const
Print relevant information of the impulse-com residual.
ResidualModelImpulseCoMTpl(boost::shared_ptr< StateMultibody > state)
Initialize the impulse CoM residual model.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the impulse CoM residual.
virtual void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the Jacobians of the impulse CoM residual.
virtual boost::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data)
Create the impulse CoM residual data.
State multibody representation.
Definition: multibody.hpp:35
MatrixXs Ru
Jacobian of the residual vector with respect the control.
MatrixXs Rx
Jacobian of the residual vector with respect the state.
DataCollectorAbstract * shared
Shared data allocated by the action model.
pinocchio::DataTpl< Scalar > pinocchio_internal
Pinocchio data for internal computation.
MatrixXs ddv_dv
Jacobian of the CoM velocity.
Matrix3xs dvc_dq
Jacobian of the CoM velocity.
DataCollectorAbstract * shared
Shared data allocated by the action model.
boost::shared_ptr< crocoddyl::ImpulseDataMultipleTpl< Scalar > > impulses
Impulses data.
pinocchio::DataTpl< Scalar > * pinocchio
Pinocchio data.