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