Crocoddyl
contact-control-gravity.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-2024, 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_RESIDUALS_CONTACT_CONTROL_GRAVITY_HPP_
11 #define CROCODDYL_MULTIBODY_RESIDUALS_CONTACT_CONTROL_GRAVITY_HPP_
12 
13 #include "crocoddyl/core/residual-base.hpp"
14 #include "crocoddyl/core/utils/exception.hpp"
15 #include "crocoddyl/multibody/data/contacts.hpp"
16 #include "crocoddyl/multibody/states/multibody.hpp"
17 
18 namespace crocoddyl {
19 
39 template <typename _Scalar>
41  : public ResidualModelAbstractTpl<_Scalar> {
42  public:
43  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44 
45  typedef _Scalar Scalar;
53  typedef typename MathBase::VectorXs VectorXs;
54  typedef typename MathBase::MatrixXs MatrixXs;
55 
62  ResidualModelContactControlGravTpl(boost::shared_ptr<StateMultibody> state,
63  const std::size_t nu);
64 
73  boost::shared_ptr<StateMultibody> state);
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 
97  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data,
98  const Eigen::Ref<const VectorXs>& x);
99 
108  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data,
109  const Eigen::Ref<const VectorXs>& x,
110  const Eigen::Ref<const VectorXs>& u);
111 
123  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data,
124  const Eigen::Ref<const VectorXs>& x);
125 
129  virtual boost::shared_ptr<ResidualDataAbstract> createData(
130  DataCollectorAbstract* const data);
131 
137  virtual void print(std::ostream& os) const;
138 
139  protected:
140  using Base::nu_;
141  using Base::state_;
142  using Base::v_dependent_;
143 
144  private:
145  typename StateMultibody::PinocchioModel pin_model_;
146 };
147 
148 template <typename _Scalar>
150  : public ResidualDataAbstractTpl<_Scalar> {
151  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
152 
153  typedef _Scalar Scalar;
158  typedef pinocchio::DataTpl<Scalar> PinocchioData;
159 
160  template <template <typename Scalar> class Model>
161  ResidualDataContactControlGravTpl(Model<Scalar>* const model,
162  DataCollectorAbstract* const data)
163  : Base(model, data) {
164  StateMultibody* sm = static_cast<StateMultibody*>(model->get_state().get());
165  pinocchio = PinocchioData(*(sm->get_pinocchio().get()));
166 
167  // Check that proper shared data has been passed
170  if (d == NULL) {
171  throw_pretty(
172  "Invalid argument: the shared data should be derived from "
173  "DataCollectorActMultibodyInContactTpl");
174  }
175  // Avoids data casting at runtime
176  // pinocchio = d->pinocchio;
177  fext = d->contacts->fext;
178  actuation = d->actuation;
179  }
180 
181  PinocchioData pinocchio;
182  boost::shared_ptr<ActuationDataAbstractTpl<Scalar> >
184  pinocchio::container::aligned_vector<pinocchio::ForceTpl<Scalar> >
186  using Base::r;
187  using Base::Ru;
188  using Base::Rx;
189  using Base::shared;
190 };
191 
192 } // namespace crocoddyl
193 
194 /* --- Details -------------------------------------------------------------- */
195 /* --- Details -------------------------------------------------------------- */
196 /* --- Details -------------------------------------------------------------- */
197 #include "crocoddyl/multibody/residuals/contact-control-gravity.hxx"
198 
199 #endif // CROCODDYL_MULTIBODY_RESIDUALS_CONTACT_CONTROL_GRAVITY_HPP_
Abstract class for the actuation-mapping model.
Abstract class for residual models.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
Control gravity residual under contact.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the residual vector for nodes that depends only on the state.
virtual void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the Jacobian of the residual functions with respect to the state only.
virtual void print(std::ostream &os) const
Print relevant information of the contact-control-grav residual.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the contact control gravity contact residual.
ResidualModelContactControlGravTpl(boost::shared_ptr< StateMultibody > state)
Initialize the contact control gravity contact residual model.
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 contact control gravity contact residual.
virtual boost::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data)
Create the contact-control-gravity residual data.
ResidualModelContactControlGravTpl(boost::shared_ptr< StateMultibody > state, const std::size_t nu)
Initialize the contact control gravity contact residual model.
State multibody representation.
Definition: multibody.hpp:35
const boost::shared_ptr< PinocchioModel > & get_pinocchio() const
Return the Pinocchio model (i.e., model of the rigid body system)
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.
boost::shared_ptr< ActuationDataAbstractTpl< Scalar > > actuation
Actuation data.
pinocchio::container::aligned_vector< pinocchio::ForceTpl< Scalar > > fext
External spatial forces.
DataCollectorAbstract * shared
Shared data allocated by the action model.