GCC Code Coverage Report


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