Crocoddyl
Loading...
Searching...
No Matches
frame-rotation.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2021-2026, 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_FRAME_ROTATION_HPP_
11#define CROCODDYL_MULTIBODY_RESIDUALS_FRAME_ROTATION_HPP_
12
13#include "crocoddyl/core/residual-base.hpp"
14#include "crocoddyl/core/utils/conversions.hpp"
15#include "crocoddyl/multibody/data/multibody.hpp"
16#include "crocoddyl/multibody/fwd.hpp"
17#include "crocoddyl/multibody/states/multibody.hpp"
18
19namespace crocoddyl {
20
36template <typename _Scalar>
38 public:
39 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41
42 typedef _Scalar Scalar;
43 typedef MathBaseTpl<Scalar> MathBase;
46 typedef StateMultibodyTpl<Scalar> StateMultibody;
47 typedef ResidualDataAbstractTpl<Scalar> ResidualDataAbstract;
48 typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract;
49 typedef typename MathBase::VectorXs VectorXs;
50 typedef typename MathBase::Matrix3s Matrix3s;
51
60 ResidualModelFrameRotationTpl(std::shared_ptr<StateMultibody> state,
61 const pinocchio::FrameIndex id,
62 const Matrix3s& Rref, const std::size_t nu);
63
73 ResidualModelFrameRotationTpl(std::shared_ptr<StateMultibody> state,
74 const pinocchio::FrameIndex id,
75 const Matrix3s& Rref);
76 virtual ~ResidualModelFrameRotationTpl() = default;
77
85 virtual void calc(const std::shared_ptr<ResidualDataAbstract>& data,
86 const Eigen::Ref<const VectorXs>& x,
87 const Eigen::Ref<const VectorXs>& u) override;
88
96 virtual void calcDiff(const std::shared_ptr<ResidualDataAbstract>& data,
97 const Eigen::Ref<const VectorXs>& x,
98 const Eigen::Ref<const VectorXs>& u) override;
99
103 virtual std::shared_ptr<ResidualDataAbstract> createData(
104 DataCollectorAbstract* const data) override;
105
115 template <typename NewScalar>
117
121 pinocchio::FrameIndex get_id() const;
122
126 const Matrix3s& get_reference() const;
127
131 void set_id(const pinocchio::FrameIndex id);
132
136 void set_reference(const Matrix3s& reference);
137
143 virtual void print(std::ostream& os) const override;
144
145 protected:
146 using Base::nu_;
147 using Base::state_;
150
151 private:
152 pinocchio::FrameIndex id_;
153 Matrix3s Rref_;
154 Matrix3s oRf_inv_;
155 std::shared_ptr<typename StateMultibody::PinocchioModel>
156 pin_model_;
157};
158
159template <typename _Scalar>
160struct ResidualDataFrameRotationTpl : public ResidualDataAbstractTpl<_Scalar> {
161 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
162
163 typedef _Scalar Scalar;
164 typedef MathBaseTpl<Scalar> MathBase;
165 typedef ResidualDataAbstractTpl<Scalar> Base;
166 typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract;
167 typedef typename MathBase::Vector3s Vector3s;
168 typedef typename MathBase::Matrix3s Matrix3s;
169 typedef typename MathBase::Matrix3xs Matrix3xs;
170 typedef typename MathBase::Matrix6xs Matrix6xs;
171
172 template <template <typename Scalar> class Model>
173 ResidualDataFrameRotationTpl(Model<Scalar>* const model,
174 DataCollectorAbstract* const data)
175 : Base(model, data), rJf(3, 3), fJf(6, model->get_state()->get_nv()) {
176 r.setZero();
177 rRf.setIdentity();
178 rJf.setZero();
179 fJf.setZero();
180 // Check that proper shared data has been passed
183 if (d == NULL) {
184 throw_pretty(
185 "Invalid argument: the shared data should be derived from "
186 "DataCollectorMultibody");
187 }
188
189 // Avoids data casting at runtime
190 pinocchio = d->pinocchio;
191 }
192 virtual ~ResidualDataFrameRotationTpl() = default;
193
194 pinocchio::DataTpl<Scalar>* pinocchio;
195 Matrix3s rRf;
196 Matrix3s rJf;
197 Matrix6xs fJf;
198
199 using Base::r;
200 using Base::Ru;
201 using Base::Rx;
202 using Base::shared;
203};
204
205} // namespace crocoddyl
206
207/* --- Details -------------------------------------------------------------- */
208/* --- Details -------------------------------------------------------------- */
209/* --- Details -------------------------------------------------------------- */
210#include "crocoddyl/multibody/residuals/frame-rotation.hxx"
211
212CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
214CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
216
217#endif // CROCODDYL_MULTIBODY_RESIDUALS_FRAME_ROTATION_HPP_
std::shared_ptr< StateAbstract > state_
ResidualModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t nr, const std::size_t nu, const bool q_dependent=true, const bool v_dependent=true, const bool u_dependent=true)
Initialize the residual model.
const Matrix3s & get_reference() const
Return the reference frame rotation.
void set_reference(const Matrix3s &reference)
Modify the reference frame rotation.
void set_id(const pinocchio::FrameIndex id)
Modify the reference frame id.
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 frame rotation residual.
ResidualModelFrameRotationTpl< NewScalar > cast() const
Cast the frame-rotation residual model to a different scalar type.
virtual std::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data) override
Create the frame rotation residual data.
pinocchio::FrameIndex get_id() const
Return the reference frame id.
ResidualModelFrameRotationTpl(std::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Matrix3s &Rref)
Initialize the frame rotation residual model.
ResidualModelFrameRotationTpl(std::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Matrix3s &Rref, const std::size_t nu)
Initialize the frame rotation 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 frame rotation residual.
virtual void print(std::ostream &os) const override
Print relevant information of the frame-rotation residual.
State multibody representation.
Definition multibody.hpp:34
Matrix3s rRf
Rotation error of the frame.
Matrix3s rJf
Error Jacobian of the frame.
Matrix6xs fJf
Local Jacobian of the frame.
DataCollectorAbstract * shared
Shared data allocated by the action model.
pinocchio::DataTpl< Scalar > * pinocchio
Pinocchio data.