Crocoddyl
 
Loading...
Searching...
No Matches
frame-translation.hpp
1
3// BSD 3-Clause License
4//
5// Copyright (C) 2021-2025, LAAS-CNRS, University of Edinburgh,
6// Heriot-Watt University
7// Copyright note valid unless otherwise stated in individual files.
8// All rights reserved.
10
11#ifndef CROCODDYL_MULTIBODY_RESIDUALS_FRAME_TRANSLATION_HPP_
12#define CROCODDYL_MULTIBODY_RESIDUALS_FRAME_TRANSLATION_HPP_
13
14#include "crocoddyl/core/residual-base.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 ResidualModelAbstractTpl<_Scalar> {
39 public:
40 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42
43 typedef _Scalar Scalar;
50 typedef typename MathBase::VectorXs VectorXs;
51 typedef typename MathBase::Vector3s Vector3s;
52
61 ResidualModelFrameTranslationTpl(std::shared_ptr<StateMultibody> state,
62 const pinocchio::FrameIndex id,
63 const Vector3s& xref, const std::size_t nu);
64
74 ResidualModelFrameTranslationTpl(std::shared_ptr<StateMultibody> state,
75 const pinocchio::FrameIndex id,
76 const Vector3s& xref);
77 virtual ~ResidualModelFrameTranslationTpl() = default;
78
86 virtual void calc(const std::shared_ptr<ResidualDataAbstract>& data,
87 const Eigen::Ref<const VectorXs>& x,
88 const Eigen::Ref<const VectorXs>& u) override;
89
97 virtual void calcDiff(const std::shared_ptr<ResidualDataAbstract>& data,
98 const Eigen::Ref<const VectorXs>& x,
99 const Eigen::Ref<const VectorXs>& u) override;
100
104 virtual std::shared_ptr<ResidualDataAbstract> createData(
105 DataCollectorAbstract* const data) override;
106
117 template <typename NewScalar>
119
123 pinocchio::FrameIndex get_id() const;
124
128 const Vector3s& get_reference() const;
129
133 void set_id(const pinocchio::FrameIndex id);
134
138 void set_reference(const Vector3s& reference);
139
145 virtual void print(std::ostream& os) const override;
146
147 protected:
148 using Base::nu_;
149 using Base::state_;
150 using Base::u_dependent_;
151 using Base::v_dependent_;
152
153 private:
154 pinocchio::FrameIndex id_;
155 Vector3s xref_;
156 std::shared_ptr<typename StateMultibody::PinocchioModel>
157 pin_model_;
158};
159
160template <typename _Scalar>
162 : public ResidualDataAbstractTpl<_Scalar> {
163 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
164
165 typedef _Scalar Scalar;
169 typedef typename MathBase::Matrix6xs Matrix6xs;
170
171 template <template <typename Scalar> class Model>
172 ResidualDataFrameTranslationTpl(Model<Scalar>* const model,
173 DataCollectorAbstract* const data)
174 : Base(model, data), fJf(6, model->get_state()->get_nv()) {
175 fJf.setZero();
176 // Check that proper shared data has been passed
179 if (d == NULL) {
180 throw_pretty(
181 "Invalid argument: the shared data should be derived from "
182 "DataCollectorMultibody");
183 }
184
185 // Avoids data casting at runtime
186 pinocchio = d->pinocchio;
187 }
188 virtual ~ResidualDataFrameTranslationTpl() = default;
189
190 pinocchio::DataTpl<Scalar>* pinocchio;
191 Matrix6xs fJf;
192
193 using Base::r;
194 using Base::Ru;
195 using Base::Rx;
196 using Base::shared;
197};
198
199} // namespace crocoddyl
200
201/* --- Details -------------------------------------------------------------- */
202/* --- Details -------------------------------------------------------------- */
203/* --- Details -------------------------------------------------------------- */
204#include "crocoddyl/multibody/residuals/frame-translation.hxx"
205
206CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
208CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
210
211#endif // CROCODDYL_MULTIBODY_RESIDUALS_FRAME_TRANSLATION_HPP_
Abstract class for residual models.
std::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
void set_reference(const Vector3s &reference)
Modify the reference frame translation reference.
const Vector3s & get_reference() const
Return the reference frame translation.
ResidualModelFrameTranslationTpl(std::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Vector3s &xref)
Initialize the frame translation residual model.
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 translation residual.
ResidualModelFrameTranslationTpl(std::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Vector3s &xref, const std::size_t nu)
Initialize the frame translation residual model.
virtual std::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data) override
Create the frame translation residual data.
pinocchio::FrameIndex get_id() const
Return the reference frame id.
ResidualModelFrameTranslationTpl< NewScalar > cast() const
Cast the frame-translation residual model to a different scalar type.
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 translation residual.
virtual void print(std::ostream &os) const override
Print relevant information of the frame-translation residual.
State multibody representation.
Definition multibody.hpp:34
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.
Matrix6xs fJf
Local Jacobian of the frame.
DataCollectorAbstract * shared
Shared data allocated by the action model.
pinocchio::DataTpl< Scalar > * pinocchio
Pinocchio data.