Crocoddyl
joint-acceleration.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2022-2025, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_CORE_RESIDUALS_JOINT_ACCELERATION_HPP_
10 #define CROCODDYL_CORE_RESIDUALS_JOINT_ACCELERATION_HPP_
11 
12 #include "crocoddyl/core/actuation-base.hpp"
13 #include "crocoddyl/core/data/joint.hpp"
14 #include "crocoddyl/core/fwd.hpp"
15 #include "crocoddyl/core/residual-base.hpp"
16 
17 namespace crocoddyl {
18 
36 template <typename _Scalar>
38  : public ResidualModelAbstractTpl<_Scalar> {
39  public:
40  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42 
43  typedef _Scalar Scalar;
51  typedef typename MathBase::VectorXs VectorXs;
52  typedef typename MathBase::MatrixXs MatrixXs;
53 
61  ResidualModelJointAccelerationTpl(std::shared_ptr<StateAbstract> state,
62  const VectorXs& aref, const std::size_t nu);
63 
72  ResidualModelJointAccelerationTpl(std::shared_ptr<StateAbstract> state,
73  const VectorXs& aref);
74 
84  ResidualModelJointAccelerationTpl(std::shared_ptr<StateAbstract> state,
85  const std::size_t nu);
86 
96  ResidualModelJointAccelerationTpl(std::shared_ptr<StateAbstract> state);
97 
98  virtual ~ResidualModelJointAccelerationTpl() = default;
99 
107  virtual void calc(const std::shared_ptr<ResidualDataAbstract>& data,
108  const Eigen::Ref<const VectorXs>& x,
109  const Eigen::Ref<const VectorXs>& u) override;
110 
115  virtual void calc(const std::shared_ptr<ResidualDataAbstract>& data,
116  const Eigen::Ref<const VectorXs>& x) override;
117 
125  virtual void calcDiff(const std::shared_ptr<ResidualDataAbstract>& data,
126  const Eigen::Ref<const VectorXs>& x,
127  const Eigen::Ref<const VectorXs>& u) override;
128 
132  virtual std::shared_ptr<ResidualDataAbstract> createData(
133  DataCollectorAbstract* const data) override;
134 
145  template <typename NewScalar>
147 
151  const VectorXs& get_reference() const;
152 
156  void set_reference(const VectorXs& reference);
157 
163  virtual void print(std::ostream& os) const override;
164 
165  protected:
166  using Base::nr_;
167  using Base::nu_;
168  using Base::state_;
169 
170  private:
171  VectorXs aref_;
172 };
173 
174 template <typename _Scalar>
176  : public ResidualDataAbstractTpl<_Scalar> {
177  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
178 
179  typedef _Scalar Scalar;
183 
184  template <template <typename Scalar> class Model>
185  ResidualDataJointAccelerationTpl(Model<Scalar>* const model,
186  DataCollectorAbstract* const data)
187  : Base(model, data) {
188  // Check that proper shared data has been passed
190  dynamic_cast<DataCollectorJointTpl<Scalar>*>(shared);
191  if (d == nullptr) {
192  throw_pretty(
193  "Invalid argument: the shared data should be derived from "
194  "DataCollectorJoint");
195  }
196  joint = d->joint;
197  }
198  virtual ~ResidualDataJointAccelerationTpl() = default;
199 
200  std::shared_ptr<JointDataAbstractTpl<Scalar> > joint;
201  using Base::r;
202  using Base::Ru;
203  using Base::Rx;
204  using Base::shared;
205 };
206 
207 } // namespace crocoddyl
208 
209 /* --- Details -------------------------------------------------------------- */
210 /* --- Details -------------------------------------------------------------- */
211 /* --- Details -------------------------------------------------------------- */
212 #include "crocoddyl/core/residuals/joint-acceleration.hxx"
213 
214 CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
216 CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
218 
219 #endif // CROCODDYL_CORE_RESIDUALS_JOINT_ACCELERATION_HPP_
Abstract class for the actuation-mapping model.
Abstract class for residual models.
std::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
std::size_t nr_
Residual vector dimension.
Define a joint-acceleration residual.
ResidualModelJointAccelerationTpl(std::shared_ptr< StateAbstract > state, const std::size_t nu)
Initialize the joint-acceleration residual model.
ResidualModelJointAccelerationTpl(std::shared_ptr< StateAbstract > state)
Initialize the joint-acceleration residual model.
ResidualModelJointAccelerationTpl(std::shared_ptr< StateAbstract > state, const VectorXs &aref)
Initialize the joint-acceleration residual model.
virtual void calc(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
virtual void calcDiff(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the derivatives of the joint-acceleration residual.
ResidualModelJointAccelerationTpl< NewScalar > cast() const
Cast the joint-acceleration residual model to a different scalar type.
void set_reference(const VectorXs &reference)
Modify the reference joint-acceleration vector.
const VectorXs & get_reference() const
Return the reference joint-acceleration vector.
ResidualModelJointAccelerationTpl(std::shared_ptr< StateAbstract > state, const VectorXs &aref, const std::size_t nu)
Initialize the joint-acceleration residual model.
virtual void calc(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the joint-acceleration residual.
virtual void print(std::ostream &os) const override
Print relevant information of the joint-acceleration residual.
virtual std::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data) override
Create the joint-acceleration residual data.
Abstract class for the state representation.
Definition: state-base.hpp:48
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.
std::shared_ptr< JointDataAbstractTpl< Scalar > > joint
Joint data.
DataCollectorAbstract * shared
Shared data allocated by the action model.