crocoddyl  1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
com-position.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_COM_POSITION_HPP_
10 #define CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_
11 
12 #include "crocoddyl/multibody/fwd.hpp"
13 #include "crocoddyl/core/residual-base.hpp"
14 #include "crocoddyl/multibody/states/multibody.hpp"
15 #include "crocoddyl/multibody/data/multibody.hpp"
16 
17 namespace crocoddyl {
18 
32 template <typename _Scalar>
34  public:
35  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36 
37  typedef _Scalar Scalar;
44  typedef typename MathBase::Vector3s Vector3s;
45  typedef typename MathBase::VectorXs VectorXs;
46 
54  ResidualModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state, const Vector3s& cref, const std::size_t nu);
55 
64  ResidualModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state, const Vector3s& cref);
65  virtual ~ResidualModelCoMPositionTpl();
66 
74  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
75  const Eigen::Ref<const VectorXs>& u);
76 
84  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
85  const Eigen::Ref<const VectorXs>& u);
86  virtual boost::shared_ptr<ResidualDataAbstract> createData(DataCollectorAbstract* const data);
87 
91  const Vector3s& get_reference() const;
92 
96  void set_reference(const Vector3s& cref);
97 
103  virtual void print(std::ostream& os) const;
104 
105  protected:
106  using Base::nu_;
107  using Base::state_;
108  using Base::u_dependent_;
109  using Base::unone_;
110  using Base::v_dependent_;
111 
112  private:
113  Vector3s cref_;
114 };
115 
116 template <typename _Scalar>
118  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
119 
120  typedef _Scalar Scalar;
124  typedef typename MathBase::Matrix3xs Matrix3xs;
125 
126  template <template <typename Scalar> class Model>
127  ResidualDataCoMPositionTpl(Model<Scalar>* const model, DataCollectorAbstract* const data) : Base(model, data) {
128  // Check that proper shared data has been passed
130  if (d == NULL) {
131  throw_pretty("Invalid argument: the shared data should be derived from DataCollectorMultibody");
132  }
133 
134  // Avoids data casting at runtime
135  pinocchio = d->pinocchio;
136  }
137 
138  pinocchio::DataTpl<Scalar>* pinocchio;
139  using Base::r;
140  using Base::Ru;
141  using Base::Rx;
142  using Base::shared;
143 };
144 
145 } // namespace crocoddyl
146 
147 /* --- Details -------------------------------------------------------------- */
148 /* --- Details -------------------------------------------------------------- */
149 /* --- Details -------------------------------------------------------------- */
150 #include "crocoddyl/multibody/residuals/com-position.hxx"
151 
152 #endif // CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_
Abstract class for residual models.
bool u_dependent_
Label that indicates if the residual function depends on u.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
bool v_dependent_
Label that indicates if the residual function depends on v.
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:31
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.