residual-fly-high.hpp
Go to the documentation of this file.
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2022 LAAS-CNRS
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef SOBEC_RESIDUAL_FLY_HIGH_HPP_
10 #define SOBEC_RESIDUAL_FLY_HIGH_HPP_
11 
12 #include <crocoddyl/core/residual-base.hpp>
13 #include <crocoddyl/multibody/data/multibody.hpp>
14 #include <crocoddyl/multibody/fwd.hpp>
15 #include <crocoddyl/multibody/states/multibody.hpp>
16 
17 #include "sobec/fwd.hpp"
18 
19 namespace sobec {
20 using namespace crocoddyl;
31 template <typename _Scalar>
32 class ResidualModelFlyHighTpl : public ResidualModelAbstractTpl<_Scalar> {
33  public:
34  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
35 
36  typedef _Scalar Scalar;
37  typedef MathBaseTpl<Scalar> MathBase;
38  typedef ResidualModelAbstractTpl<Scalar> Base;
40  typedef StateMultibodyTpl<Scalar> StateMultibody;
41  typedef ResidualDataAbstractTpl<Scalar> ResidualDataAbstract;
42  typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract;
43  typedef typename MathBase::Vector3s Vector3s;
44  typedef typename MathBase::VectorXs VectorXs;
45  typedef typename MathBase::MatrixXs MatrixXs;
46  typedef typename MathBase::Matrix3s Matrix3s;
47 
57  ResidualModelFlyHighTpl(boost::shared_ptr<StateMultibody> state,
58  const pinocchio::FrameIndex frame_id,
59  const Scalar slope, const std::size_t nu);
60 
71  ResidualModelFlyHighTpl(boost::shared_ptr<StateMultibody> state,
72  const pinocchio::FrameIndex frame_id,
73  const Scalar slope);
74  virtual ~ResidualModelFlyHighTpl();
75 
83  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data,
84  const Eigen::Ref<const VectorXs>& x,
85  const Eigen::Ref<const VectorXs>& u);
86 
94  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data,
95  const Eigen::Ref<const VectorXs>& x,
96  const Eigen::Ref<const VectorXs>& u);
97  virtual boost::shared_ptr<ResidualDataAbstract> createData(
98  DataCollectorAbstract* const data);
99 
103  const pinocchio::FrameIndex& get_frame_id() const;
104 
108  void set_frame_id(const pinocchio::FrameIndex& fid);
109 
110  const Scalar getSlope() const { return slope; }
111  void setSlope(const Scalar s) { slope = s; }
112 
113  protected:
114  using Base::nu_;
115  using Base::state_;
116  using Base::u_dependent_;
117  using Base::unone_;
118  using Base::v_dependent_;
119 
120  private:
121  pinocchio::FrameIndex frame_id;
122  Scalar slope; // multiplication in front of the altitude in the cost
123  typename StateMultibody::PinocchioModel
124  pin_model_;
125 };
126 
127 template <typename _Scalar>
128 struct ResidualDataFlyHighTpl : public ResidualDataAbstractTpl<_Scalar> {
129  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
130 
131  typedef _Scalar Scalar;
132  typedef MathBaseTpl<Scalar> MathBase;
133  typedef ResidualDataAbstractTpl<Scalar> Base;
134  typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract;
135  typedef typename MathBase::Matrix6xs Matrix6xs;
136  typedef typename MathBase::Matrix3xs Matrix3xs;
137  typedef typename MathBase::VectorXs VectorXs;
138 
139  template <template <typename Scalar> class Model>
140  ResidualDataFlyHighTpl(Model<Scalar>* const model,
141  DataCollectorAbstract* const data)
142  : Base(model, data),
143  d_dq(6, model->get_state()->get_nv()),
144  d_dv(6, model->get_state()->get_nv()),
145  l_dnu_dq(6, model->get_state()->get_nv()),
146  l_dnu_dv(6, model->get_state()->get_nv()),
147  o_dv_dq(3, model->get_state()->get_nv()),
148  o_dv_dv(3, model->get_state()->get_nv()),
149  o_Jw(3, model->get_state()->get_nv()),
150  vxJ(3, model->get_state()->get_nv()) {
151  // dvcom_dq.setZero();
152  // Check that proper shared data has been passed
153  DataCollectorMultibodyTpl<Scalar>* d =
154  dynamic_cast<DataCollectorMultibodyTpl<Scalar>*>(shared);
155  if (d == NULL) {
156  throw_pretty(
157  "Invalid argument: the shared data should be derived from "
158  "DataCollectorMultibody");
159  }
160 
161  // Avoids data casting at runtime
162  pinocchio = d->pinocchio;
163  // Clean buffer as pinocchio not necessarily initialize the memory.
164  d_dq.fill(0);
165  d_dv.fill(0);
166  l_dnu_dq.fill(0);
167  l_dnu_dv.fill(0);
168  o_dv_dq.fill(0);
169  o_dv_dv.fill(0);
170  o_Jw.fill(0);
171  vxJ.fill(0);
172  }
173 
174  pinocchio::DataTpl<Scalar>* pinocchio;
176  Matrix6xs l_dnu_dq, l_dnu_dv;
177  Matrix3xs o_dv_dq, o_dv_dv, o_Jw, vxJ;
178 
179  Scalar ez;
180  using Base::r;
181  using Base::Ru;
182  using Base::Rx;
183  using Base::shared;
184 };
185 
186 } // namespace sobec
187 
188 /* --- Details -------------------------------------------------------------- */
189 /* --- Details -------------------------------------------------------------- */
190 /* --- Details -------------------------------------------------------------- */
191 
193 
194 #endif // SOBEC_RESIDUAL_FLY_HIGH_HPP_
sobec::ResidualModelFlyHighTpl::ResidualDataAbstract
ResidualDataAbstractTpl< Scalar > ResidualDataAbstract
Definition: residual-fly-high.hpp:41
sobec::ResidualDataFlyHighTpl::d_dv
Matrix6xs d_dv
Definition: residual-fly-high.hpp:175
sobec::ResidualDataFlyHighTpl::pinocchio
pinocchio::DataTpl< Scalar > * pinocchio
Pinocchio data.
Definition: residual-fly-high.hpp:174
sobec::ResidualModelFlyHighTpl::Vector3s
MathBase::Vector3s Vector3s
Definition: residual-fly-high.hpp:43
sobec::ResidualDataFlyHighTpl
Definition: residual-fly-high.hpp:128
sobec::ResidualDataFlyHighTpl::Scalar
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Definition: residual-fly-high.hpp:131
sobec::ResidualDataFlyHighTpl::VectorXs
MathBase::VectorXs VectorXs
Definition: residual-fly-high.hpp:137
fwd.hpp
sobec::ResidualModelFlyHighTpl::MathBase
MathBaseTpl< Scalar > MathBase
Definition: residual-fly-high.hpp:37
sobec::ResidualDataFlyHighTpl::DataCollectorAbstract
DataCollectorAbstractTpl< Scalar > DataCollectorAbstract
Definition: residual-fly-high.hpp:134
sobec::ResidualDataFlyHighTpl::MathBase
MathBaseTpl< Scalar > MathBase
Definition: residual-fly-high.hpp:132
sobec::ResidualModelFlyHighTpl::Base
ResidualModelAbstractTpl< Scalar > Base
Definition: residual-fly-high.hpp:38
sobec::ResidualModelFlyHighTpl::VectorXs
MathBase::VectorXs VectorXs
Definition: residual-fly-high.hpp:44
sobec::ResidualModelFlyHighTpl::DataCollectorAbstract
DataCollectorAbstractTpl< Scalar > DataCollectorAbstract
Definition: residual-fly-high.hpp:42
sobec::ResidualDataFlyHighTpl::vxJ
Matrix3xs vxJ
Definition: residual-fly-high.hpp:177
sobec::ResidualDataFlyHighTpl::ResidualDataFlyHighTpl
ResidualDataFlyHighTpl(Model< Scalar > *const model, DataCollectorAbstract *const data)
Definition: residual-fly-high.hpp:140
sobec
Definition: activation-quad-ref.hpp:19
sobec::ResidualDataFlyHighTpl::l_dnu_dv
Matrix6xs l_dnu_dv
Definition: residual-fly-high.hpp:176
sobec::ResidualModelFlyHighTpl::setSlope
void setSlope(const Scalar s)
Definition: residual-fly-high.hpp:111
sobec::ResidualModelFlyHighTpl::Scalar
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Definition: residual-fly-high.hpp:36
sobec::ResidualModelFlyHighTpl::Matrix3s
MathBase::Matrix3s Matrix3s
Definition: residual-fly-high.hpp:46
sobec::ResidualModelFlyHighTpl::Data
ResidualDataFlyHighTpl< Scalar > Data
Definition: residual-fly-high.hpp:39
sobec::newcontacts::x
@ x
Definition: contact1d.hpp:26
sobec::ResidualModelFlyHighTpl::MatrixXs
MathBase::MatrixXs MatrixXs
Definition: residual-fly-high.hpp:45
sobec::ResidualModelFlyHighTpl::getSlope
const Scalar getSlope() const
Definition: residual-fly-high.hpp:110
sobec::ResidualDataFlyHighTpl::ez
Scalar ez
Definition: residual-fly-high.hpp:179
sobec::ResidualModelFlyHighTpl
Cost penalizing high horizontal velocity near zero altitude.
Definition: residual-fly-high.hpp:32
sobec::ResidualModelFlyHighTpl::StateMultibody
StateMultibodyTpl< Scalar > StateMultibody
Definition: residual-fly-high.hpp:40
residual-fly-high.hxx
sobec::ResidualDataFlyHighTpl::Matrix6xs
MathBase::Matrix6xs Matrix6xs
Definition: residual-fly-high.hpp:135
sobec::ResidualDataFlyHighTpl::Matrix3xs
MathBase::Matrix3xs Matrix3xs
Definition: residual-fly-high.hpp:136
sobec::ResidualDataFlyHighTpl::Base
ResidualDataAbstractTpl< Scalar > Base
Definition: residual-fly-high.hpp:133