Crocoddyl
com-position.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-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_COM_POSITION_HPP_
11 #define CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_
12 
13 #include "crocoddyl/core/residual-base.hpp"
14 #include "crocoddyl/multibody/data/multibody.hpp"
15 #include "crocoddyl/multibody/fwd.hpp"
16 #include "crocoddyl/multibody/states/multibody.hpp"
17 
18 namespace crocoddyl {
19 
35 template <typename _Scalar>
37  public:
38  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
39 
40  typedef _Scalar Scalar;
47  typedef typename MathBase::Vector3s Vector3s;
48  typedef typename MathBase::VectorXs VectorXs;
49 
57  ResidualModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state,
58  const Vector3s& cref, const std::size_t nu);
59 
68  ResidualModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state,
69  const Vector3s& cref);
70  virtual ~ResidualModelCoMPositionTpl();
71 
79  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data,
80  const Eigen::Ref<const VectorXs>& x,
81  const Eigen::Ref<const VectorXs>& u);
82 
90  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data,
91  const Eigen::Ref<const VectorXs>& x,
92  const Eigen::Ref<const VectorXs>& u);
93  virtual boost::shared_ptr<ResidualDataAbstract> createData(
94  DataCollectorAbstract* const data);
95 
99  const Vector3s& get_reference() const;
100 
104  void set_reference(const Vector3s& cref);
105 
111  virtual void print(std::ostream& os) const;
112 
113  protected:
114  using Base::nu_;
115  using Base::state_;
116  using Base::u_dependent_;
117  using Base::v_dependent_;
118 
119  private:
120  Vector3s cref_;
121 };
122 
123 template <typename _Scalar>
125  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
126 
127  typedef _Scalar Scalar;
131  typedef typename MathBase::Matrix3xs Matrix3xs;
132 
133  template <template <typename Scalar> class Model>
134  ResidualDataCoMPositionTpl(Model<Scalar>* const model,
135  DataCollectorAbstract* const data)
136  : Base(model, data) {
137  // Check that proper shared data has been passed
140  if (d == NULL) {
141  throw_pretty(
142  "Invalid argument: the shared data should be derived from "
143  "DataCollectorMultibody");
144  }
145 
146  // Avoids data casting at runtime
147  pinocchio = d->pinocchio;
148  }
149 
150  pinocchio::DataTpl<Scalar>* pinocchio;
151  using Base::r;
152  using Base::Ru;
153  using Base::Rx;
154  using Base::shared;
155 };
156 
157 } // namespace crocoddyl
158 
159 /* --- Details -------------------------------------------------------------- */
160 /* --- Details -------------------------------------------------------------- */
161 /* --- Details -------------------------------------------------------------- */
162 #include "crocoddyl/multibody/residuals/com-position.hxx"
163 
164 #endif // CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_
Abstract class for residual models.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
ResidualModelCoMPositionTpl(boost::shared_ptr< StateMultibody > state, const Vector3s &cref)
Initialize the CoM position residual model.
const Vector3s & get_reference() const
Return the CoM position reference.
virtual void print(std::ostream &os) const
Print relevant information of the com-position residual.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the CoM position residual.
void set_reference(const Vector3s &cref)
Modify the CoM position reference.
virtual void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the CoM position residual.
virtual boost::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual data.
ResidualModelCoMPositionTpl(boost::shared_ptr< StateMultibody > state, const Vector3s &cref, const std::size_t nu)
Initialize the CoM position residual model.
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.
DataCollectorAbstract * shared
Shared data allocated by the action model.
pinocchio::DataTpl< Scalar > * pinocchio
Pinocchio data.