Directory: | ./ |
---|---|
File: | include/crocoddyl/multibody/residuals/frame-velocity.hxx |
Date: | 2025-03-26 19:23:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 34 | 54 | 63.0% |
Branches: | 31 | 86 | 36.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 | #include <pinocchio/algorithm/frames-derivatives.hpp> | ||
11 | #include <pinocchio/algorithm/frames.hpp> | ||
12 | #include <pinocchio/algorithm/kinematics-derivatives.hpp> | ||
13 | |||
14 | #include "crocoddyl/multibody/residuals/frame-velocity.hpp" | ||
15 | |||
16 | namespace crocoddyl { | ||
17 | |||
18 | template <typename Scalar> | ||
19 | 595 | ResidualModelFrameVelocityTpl<Scalar>::ResidualModelFrameVelocityTpl( | |
20 | std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
21 | const Motion& vref, const pinocchio::ReferenceFrame type, | ||
22 | const std::size_t nu) | ||
23 | : Base(state, 6, nu, true, true, false), | ||
24 | 595 | id_(id), | |
25 | 595 | vref_(vref), | |
26 | 595 | type_(type), | |
27 |
3/6✓ Branch 2 taken 595 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 595 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 595 times.
✗ Branch 11 not taken.
|
595 | pin_model_(state->get_pinocchio()) { |
28 |
2/4✓ Branch 2 taken 595 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 595 times.
|
595 | if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <= |
29 | id) { | ||
30 | ✗ | throw_pretty( | |
31 | "Invalid argument: " | ||
32 | << "the frame index is wrong (it does not exist in the robot)"); | ||
33 | } | ||
34 | 595 | } | |
35 | |||
36 | template <typename Scalar> | ||
37 | 3 | ResidualModelFrameVelocityTpl<Scalar>::ResidualModelFrameVelocityTpl( | |
38 | std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
39 | const Motion& vref, const pinocchio::ReferenceFrame type) | ||
40 | : Base(state, 6, true, true, false), | ||
41 | 3 | id_(id), | |
42 | 3 | vref_(vref), | |
43 | 3 | type_(type), | |
44 |
3/6✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
|
3 | pin_model_(state->get_pinocchio()) { |
45 |
2/4✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
|
3 | if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <= |
46 | id) { | ||
47 | ✗ | throw_pretty( | |
48 | "Invalid argument: " | ||
49 | << "the frame index is wrong (it does not exist in the robot)"); | ||
50 | } | ||
51 | 3 | } | |
52 | |||
53 | template <typename Scalar> | ||
54 | 21164 | void ResidualModelFrameVelocityTpl<Scalar>::calc( | |
55 | const std::shared_ptr<ResidualDataAbstract>& data, | ||
56 | const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) { | ||
57 | 21164 | Data* d = static_cast<Data*>(data.get()); | |
58 | |||
59 | // Compute the frame velocity w.r.t. the reference frame | ||
60 |
1/2✓ Branch 1 taken 21164 times.
✗ Branch 2 not taken.
|
21164 | data->r = (pinocchio::getFrameVelocity(*pin_model_.get(), *d->pinocchio, id_, |
61 | type_) - | ||
62 | 21164 | vref_) | |
63 |
2/4✓ Branch 3 taken 21164 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 21164 times.
✗ Branch 7 not taken.
|
21164 | .toVector(); |
64 | 21164 | } | |
65 | |||
66 | template <typename Scalar> | ||
67 | 3537 | void ResidualModelFrameVelocityTpl<Scalar>::calcDiff( | |
68 | const std::shared_ptr<ResidualDataAbstract>& data, | ||
69 | const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) { | ||
70 | // Get the partial derivatives of the local frame velocity | ||
71 | 3537 | Data* d = static_cast<Data*>(data.get()); | |
72 | 3537 | const std::size_t nv = state_->get_nv(); | |
73 |
1/2✓ Branch 2 taken 3537 times.
✗ Branch 3 not taken.
|
3537 | pinocchio::getFrameVelocityDerivatives(*pin_model_.get(), *d->pinocchio, id_, |
74 |
1/2✓ Branch 2 taken 3537 times.
✗ Branch 3 not taken.
|
3537 | type_, data->Rx.leftCols(nv), |
75 | 3537 | data->Rx.rightCols(nv)); | |
76 | 3537 | } | |
77 | |||
78 | template <typename Scalar> | ||
79 | std::shared_ptr<ResidualDataAbstractTpl<Scalar> > | ||
80 | 26111 | ResidualModelFrameVelocityTpl<Scalar>::createData( | |
81 | DataCollectorAbstract* const data) { | ||
82 | ✗ | return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this, | |
83 |
1/2✓ Branch 2 taken 26111 times.
✗ Branch 3 not taken.
|
26111 | data); |
84 | } | ||
85 | |||
86 | template <typename Scalar> | ||
87 | template <typename NewScalar> | ||
88 | ResidualModelFrameVelocityTpl<NewScalar> | ||
89 | ✗ | ResidualModelFrameVelocityTpl<Scalar>::cast() const { | |
90 | typedef ResidualModelFrameVelocityTpl<NewScalar> ReturnType; | ||
91 | typedef StateMultibodyTpl<NewScalar> StateType; | ||
92 | ✗ | ReturnType ret( | |
93 | ✗ | std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()), | |
94 | ✗ | id_, vref_.template cast<NewScalar>(), type_, nu_); | |
95 | ✗ | return ret; | |
96 | } | ||
97 | |||
98 | template <typename Scalar> | ||
99 | 63 | void ResidualModelFrameVelocityTpl<Scalar>::print(std::ostream& os) const { | |
100 |
7/14✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 63 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 63 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 63 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 63 times.
✗ Branch 19 not taken.
✓ Branch 22 taken 63 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 63 times.
✗ Branch 26 not taken.
|
126 | const Eigen::IOFormat fmt(2, Eigen::DontAlignCols, ", ", ";\n", "", "", "[", |
101 | "]"); | ||
102 | 63 | os << "ResidualModelFrameVelocity {frame=" << pin_model_->frames[id_].name | |
103 |
8/16✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 63 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 63 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 63 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 63 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 63 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 63 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 63 times.
✗ Branch 24 not taken.
|
126 | << ", vref=" << vref_.toVector().transpose().format(fmt) << "}"; |
104 | 63 | } | |
105 | |||
106 | template <typename Scalar> | ||
107 | ✗ | pinocchio::FrameIndex ResidualModelFrameVelocityTpl<Scalar>::get_id() const { | |
108 | ✗ | return id_; | |
109 | } | ||
110 | |||
111 | template <typename Scalar> | ||
112 | const pinocchio::MotionTpl<Scalar>& | ||
113 | ✗ | ResidualModelFrameVelocityTpl<Scalar>::get_reference() const { | |
114 | ✗ | return vref_; | |
115 | } | ||
116 | |||
117 | template <typename Scalar> | ||
118 | ✗ | pinocchio::ReferenceFrame ResidualModelFrameVelocityTpl<Scalar>::get_type() | |
119 | const { | ||
120 | ✗ | return type_; | |
121 | } | ||
122 | |||
123 | template <typename Scalar> | ||
124 | ✗ | void ResidualModelFrameVelocityTpl<Scalar>::set_id( | |
125 | const pinocchio::FrameIndex id) { | ||
126 | ✗ | id_ = id; | |
127 | } | ||
128 | |||
129 | template <typename Scalar> | ||
130 | ✗ | void ResidualModelFrameVelocityTpl<Scalar>::set_reference( | |
131 | const Motion& velocity) { | ||
132 | ✗ | vref_ = velocity; | |
133 | } | ||
134 | |||
135 | template <typename Scalar> | ||
136 | ✗ | void ResidualModelFrameVelocityTpl<Scalar>::set_type( | |
137 | const pinocchio::ReferenceFrame type) { | ||
138 | ✗ | type_ = type; | |
139 | } | ||
140 | |||
141 | } // namespace crocoddyl | ||
142 |