GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/residuals/frame-translation.hxx
Date: 2025-05-13 10:30:51
Exec Total Coverage
Lines: 0 43 0.0%
Branches: 0 88 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2025, LAAS-CNRS, University of Edinburgh,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 namespace crocoddyl {
11
12 template <typename Scalar>
13 ResidualModelFrameTranslationTpl<Scalar>::ResidualModelFrameTranslationTpl(
14 std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
15 const Vector3s& xref, const std::size_t nu)
16 : Base(state, 3, nu, true, false, false),
17 id_(id),
18 xref_(xref),
19 pin_model_(state->get_pinocchio()) {
20 if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <=
21 id) {
22 throw_pretty(
23 "Invalid argument: "
24 << "the frame index is wrong (it does not exist in the robot)");
25 }
26 }
27
28 template <typename Scalar>
29 ResidualModelFrameTranslationTpl<Scalar>::ResidualModelFrameTranslationTpl(
30 std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
31 const Vector3s& xref)
32 : Base(state, 3, true, false, false),
33 id_(id),
34 xref_(xref),
35 pin_model_(state->get_pinocchio()) {
36 if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <=
37 id) {
38 throw_pretty(
39 "Invalid argument: "
40 << "the frame index is wrong (it does not exist in the robot)");
41 }
42 }
43
44 template <typename Scalar>
45 void ResidualModelFrameTranslationTpl<Scalar>::calc(
46 const std::shared_ptr<ResidualDataAbstract>& data,
47 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
48 // Compute the frame translation w.r.t. the reference frame
49 Data* d = static_cast<Data*>(data.get());
50 pinocchio::updateFramePlacement(*pin_model_.get(), *d->pinocchio, id_);
51 data->r = d->pinocchio->oMf[id_].translation() - xref_;
52 }
53
54 template <typename Scalar>
55 void ResidualModelFrameTranslationTpl<Scalar>::calcDiff(
56 const std::shared_ptr<ResidualDataAbstract>& data,
57 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
58 Data* d = static_cast<Data*>(data.get());
59
60 // Compute the derivatives of the frame translation
61 const std::size_t nv = state_->get_nv();
62 pinocchio::getFrameJacobian(*pin_model_.get(), *d->pinocchio, id_,
63 pinocchio::LOCAL, d->fJf);
64 d->Rx.leftCols(nv).noalias() =
65 d->pinocchio->oMf[id_].rotation() * d->fJf.template topRows<3>();
66 ;
67 }
68
69 template <typename Scalar>
70 std::shared_ptr<ResidualDataAbstractTpl<Scalar> >
71 ResidualModelFrameTranslationTpl<Scalar>::createData(
72 DataCollectorAbstract* const data) {
73 return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this,
74 data);
75 }
76
77 template <typename Scalar>
78 template <typename NewScalar>
79 ResidualModelFrameTranslationTpl<NewScalar>
80 ResidualModelFrameTranslationTpl<Scalar>::cast() const {
81 typedef ResidualModelFrameTranslationTpl<NewScalar> ReturnType;
82 typedef StateMultibodyTpl<NewScalar> StateType;
83 ReturnType ret(
84 std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()),
85 id_, xref_.template cast<NewScalar>(), nu_);
86 return ret;
87 }
88
89 template <typename Scalar>
90 void ResidualModelFrameTranslationTpl<Scalar>::print(std::ostream& os) const {
91 const Eigen::IOFormat fmt(2, Eigen::DontAlignCols, ", ", ";\n", "", "", "[",
92 "]");
93 os << "ResidualModelFrameTranslation {frame=" << pin_model_->frames[id_].name
94 << ", tref=" << xref_.transpose().format(fmt) << "}";
95 }
96
97 template <typename Scalar>
98 pinocchio::FrameIndex ResidualModelFrameTranslationTpl<Scalar>::get_id() const {
99 return id_;
100 }
101
102 template <typename Scalar>
103 const typename MathBaseTpl<Scalar>::Vector3s&
104 ResidualModelFrameTranslationTpl<Scalar>::get_reference() const {
105 return xref_;
106 }
107
108 template <typename Scalar>
109 void ResidualModelFrameTranslationTpl<Scalar>::set_id(
110 const pinocchio::FrameIndex id) {
111 id_ = id;
112 }
113
114 template <typename Scalar>
115 void ResidualModelFrameTranslationTpl<Scalar>::set_reference(
116 const Vector3s& translation) {
117 xref_ = translation;
118 }
119
120 } // namespace crocoddyl
121