Crocoddyl
impulse-3d.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
9 
10 #ifndef CROCODDYL_MULTIBODY_IMPULSES_IMPULSE_3D_HPP_
11 #define CROCODDYL_MULTIBODY_IMPULSES_IMPULSE_3D_HPP_
12 
13 #include <pinocchio/multibody/data.hpp>
14 #include <pinocchio/spatial/motion.hpp>
15 
16 #include "crocoddyl/multibody/fwd.hpp"
17 #include "crocoddyl/multibody/impulse-base.hpp"
18 
19 namespace crocoddyl {
20 
21 template <typename _Scalar>
22 class ImpulseModel3DTpl : public ImpulseModelAbstractTpl<_Scalar> {
23  public:
24  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 
26  typedef _Scalar Scalar;
32  typedef typename MathBase::Vector2s Vector2s;
33  typedef typename MathBase::Vector3s Vector3s;
34  typedef typename MathBase::VectorXs VectorXs;
35  typedef typename MathBase::MatrixXs Matrix3s;
36  typedef typename MathBase::MatrixXs MatrixXs;
37 
46  boost::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
47  const pinocchio::ReferenceFrame type = pinocchio::ReferenceFrame::LOCAL);
48  virtual ~ImpulseModel3DTpl();
49 
56  virtual void calc(const boost::shared_ptr<ImpulseDataAbstract>& data,
57  const Eigen::Ref<const VectorXs>& x);
58 
65  virtual void calcDiff(const boost::shared_ptr<ImpulseDataAbstract>& data,
66  const Eigen::Ref<const VectorXs>& x);
67 
74  virtual void updateForce(const boost::shared_ptr<ImpulseDataAbstract>& data,
75  const VectorXs& force);
76 
80  virtual boost::shared_ptr<ImpulseDataAbstract> createData(
81  pinocchio::DataTpl<Scalar>* const data);
82 
88  virtual void print(std::ostream& os) const;
89 
90  protected:
91  using Base::id_;
92  using Base::state_;
93  using Base::type_;
94 };
95 
96 template <typename _Scalar>
97 struct ImpulseData3DTpl : public ImpulseDataAbstractTpl<_Scalar> {
98  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
99 
100  typedef _Scalar Scalar;
103  typedef typename MathBase::Vector3s Vector3s;
104  typedef typename MathBase::Matrix3s Matrix3s;
105  typedef typename MathBase::Matrix3xs Matrix3xs;
106  typedef typename MathBase::Matrix6xs Matrix6xs;
107  typedef typename pinocchio::ForceTpl<Scalar> Force;
108 
109  template <template <typename Scalar> class Model>
110  ImpulseData3DTpl(Model<Scalar>* const model,
111  pinocchio::DataTpl<Scalar>* const data)
112  : Base(model, data),
113  f_local(Force::Zero()),
114  dv0_local_dq(3, model->get_state()->get_nv()),
115  fJf(6, model->get_state()->get_nv()),
116  v_partial_dq(6, model->get_state()->get_nv()),
117  v_partial_dv(6, model->get_state()->get_nv()),
118  fJf_df(3, model->get_state()->get_nv()) {
119  frame = model->get_id();
120  jMf =
121  model->get_state()->get_pinocchio()->frames[model->get_id()].placement;
122  fXj = jMf.inverse().toActionMatrix();
123  v0.setZero();
124  dv0_local_dq.setZero();
125  fJf.setZero();
126  v_partial_dq.setZero();
127  v_partial_dv.setZero();
128  v0_skew.setZero();
129  v0_world_skew.setZero();
130  f_skew.setZero();
131  fJf_df.setZero();
132  }
133 
134  using Base::df_dx;
135  using Base::dv0_dq;
136  using Base::f;
137  using Base::frame;
138  using Base::fXj;
139  using Base::Jc;
140  using Base::jMf;
141  using Base::pinocchio;
142 
143  Vector3s v0;
144  Force f_local;
145  Matrix3xs dv0_local_dq;
146  Matrix6xs fJf;
147  Matrix6xs v_partial_dq;
148  Matrix6xs v_partial_dv;
149  Matrix3s v0_skew;
150  Matrix3s v0_world_skew;
151  Matrix3s f_skew;
152  Matrix3xs fJf_df;
153 };
154 
155 } // namespace crocoddyl
156 
157 /* --- Details -------------------------------------------------------------- */
158 /* --- Details -------------------------------------------------------------- */
159 /* --- Details -------------------------------------------------------------- */
160 #include "crocoddyl/multibody/impulses/impulse-3d.hxx"
161 
162 #endif // CROCODDYL_MULTIBODY_IMPULSES_IMPULSE_3D_HPP_
ImpulseModel3DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const pinocchio::ReferenceFrame type=pinocchio::ReferenceFrame::LOCAL)
Initialize the 3d impulse model.
virtual void calcDiff(const boost::shared_ptr< ImpulseDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the 6d impulse holonomic constraint.
virtual void print(std::ostream &os) const
Print relevant information of the 3d impulse model.
virtual boost::shared_ptr< ImpulseDataAbstract > createData(pinocchio::DataTpl< Scalar > *const data)
Create the 6d impulse data.
virtual void calc(const boost::shared_ptr< ImpulseDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the 6d impulse Jacobian.
virtual void updateForce(const boost::shared_ptr< ImpulseDataAbstract > &data, const VectorXs &force)
Convert the force into a stack of spatial forces.
pinocchio::ReferenceFrame type_
Type of contact.
pinocchio::FrameIndex id_
Reference frame id of the contact.
State multibody representation.
Definition: multibody.hpp:35
pinocchio::FrameIndex frame
Frame index of the contact frame.
Definition: force-base.hpp:50
SE3 jMf
Local frame placement of the contact frame.
Definition: force-base.hpp:52
PinocchioData * pinocchio
Pinocchio data.
Definition: force-base.hpp:49
pinocchio::FrameIndex frame
Frame index of the contact frame.
Definition: force-base.hpp:50
SE3 jMf
Local frame placement of the contact frame.
Definition: force-base.hpp:52
MatrixXs Jc
Contact Jacobian.
Definition: force-base.hpp:53
Force f
Contact force expressed in the coordinate defined by type.
Definition: force-base.hpp:54