GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/residuals/frame-rotation.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 27 28 96.4%
Branches: 57 114 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2025, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/multibody/residuals/frame-rotation.hpp"
10
11 #include "python/crocoddyl/multibody/multibody.hpp"
12
13 namespace crocoddyl {
14 namespace python {
15
16 template <typename Model>
17 struct ResidualModelFrameRotationVisitor
18 : public bp::def_visitor<ResidualModelFrameRotationVisitor<Model>> {
19 typedef typename Model::ResidualDataAbstract Data;
20 typedef typename Model::Base ModelBase;
21 typedef typename Model::StateMultibody State;
22 typedef typename Model::Matrix3s Matrix3s;
23 typedef typename Model::VectorXs VectorXs;
24 template <class PyClass>
25 40 void visit(PyClass& cl) const {
26
2/4
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
40 cl.def(bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Matrix3s>(
27 bp::args("self", "state", "id", "Rref"),
28 "Initialize the frame rotation residual model.\n\n"
29 "The default nu value is obtained from model.nv.\n"
30 ":param state: state of the multibody system\n"
31 ":param id: reference frame id\n"
32 ":param Rref: reference frame rotation"))
33
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
80 .def(
34 "calc",
35 static_cast<void (Model::*)(
36 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
37 const Eigen::Ref<const VectorXs>&)>(&Model::calc),
38 bp::args("self", "data", "x", "u"),
39 "Compute the frame rotation residual.\n\n"
40 ":param data: residual data\n"
41 ":param x: state point (dim. state.nx)\n"
42 ":param u: control input (dim. nu)")
43
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
80 .def(
44 "calc",
45 static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&,
46 const Eigen::Ref<const VectorXs>&)>(
47 &ModelBase::calc),
48 bp::args("self", "data", "x"))
49
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
80 .def(
50 "calcDiff",
51 static_cast<void (Model::*)(
52 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
53 const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff),
54 bp::args("self", "data", "x", "u"),
55 "Compute the Jacobians of the frame rotation residual.\n\n"
56 "It assumes that calc has been run first.\n"
57 ":param data: action data\n"
58 ":param x: state point (dim. state.nx)\n"
59 ":param u: control input (dim. nu)")
60
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
80 .def(
61 "calcDiff",
62 static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&,
63 const Eigen::Ref<const VectorXs>&)>(
64 &ModelBase::calcDiff),
65 bp::args("self", "data", "x"))
66
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
80 .def("createData", &Model::createData,
67 bp::with_custodian_and_ward_postcall<0, 2>(),
68 bp::args("self", "data"),
69 "Create the frame rotation residual data.\n\n"
70 "Each residual model has its own data that needs to be allocated. "
71 "This function\n"
72 "returns the allocated data for the frame rotation residual.\n"
73 ":param data: shared data\n"
74 ":return residual data.")
75
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .add_property("id", &Model::get_id, &Model::set_id,
76 "reference frame id")
77
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
40 .add_property("reference",
78 bp::make_function(
79 &Model::get_reference,
80 40 bp::return_value_policy<bp::copy_const_reference>()),
81 &Model::set_reference, "reference frame rotation");
82 40 }
83 };
84
85 template <typename Data>
86 struct ResidualDataFrameRotationVisitor
87 : public bp::def_visitor<ResidualDataFrameRotationVisitor<Data>> {
88 template <class PyClass>
89 40 void visit(PyClass& cl) const {
90
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 cl.add_property(
91 "pinocchio",
92 40 bp::make_getter(&Data::pinocchio, bp::return_internal_reference<>()),
93 "pinocchio data")
94
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
95 40 "r", bp::make_getter(&Data::r, bp::return_internal_reference<>()),
96 "residual residual")
97
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
98 "rRf",
99 40 bp::make_getter(&Data::rRf, bp::return_internal_reference<>()),
100 "rotation error of the frame")
101
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
102 "rJf",
103 40 bp::make_getter(&Data::rJf, bp::return_internal_reference<>()),
104 "error Jacobian of the frame")
105
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
106 "fJf",
107 40 bp::make_getter(&Data::fJf, bp::return_internal_reference<>()),
108 "local Jacobian of the frame");
109 40 }
110 };
111
112 #define CROCODDYL_RESIDUAL_MODEL_FRAME_ROTATION_PYTHON_BINDINGS(Scalar) \
113 typedef ResidualModelFrameRotationTpl<Scalar> Model; \
114 typedef ResidualModelAbstractTpl<Scalar> ModelBase; \
115 typedef typename Model::StateMultibody State; \
116 typedef typename Model::Matrix3s Matrix3s; \
117 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
118 bp::class_<Model, bp::bases<ModelBase>>( \
119 "ResidualModelFrameRotation", \
120 "This residual function is defined as r = R - Rref, with R and Rref as " \
121 "the current and reference frame rotations, respectively.", \
122 bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Matrix3s, \
123 std::size_t>( \
124 bp::args("self", "state", "id", "Rref", "nu"), \
125 "Initialize the frame rotation residual model.\n\n" \
126 ":param state: state of the multibody system\n" \
127 ":param id: reference frame id\n" \
128 ":param Rref: reference frame rotation\n" \
129 ":param nu: dimension of control vector")) \
130 .def(ResidualModelFrameRotationVisitor<Model>()) \
131 .def(CastVisitor<Model>()) \
132 .def(PrintableVisitor<Model>()) \
133 .def(CopyableVisitor<Model>());
134
135 #define CROCODDYL_RESIDUAL_DATA_FRAME_ROTATION_PYTHON_BINDINGS(Scalar) \
136 typedef ResidualDataFrameRotationTpl<Scalar> Data; \
137 typedef ResidualDataAbstractTpl<Scalar> DataBase; \
138 typedef ResidualModelFrameRotationTpl<Scalar> Model; \
139 typedef Model::DataCollectorAbstract DataCollector; \
140 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
141 bp::class_<Data, bp::bases<DataBase>>( \
142 "ResidualDataFrameRotation", "Data for frame rotation residual.\n\n", \
143 bp::init<Model*, DataCollector*>( \
144 bp::args("self", "model", "data"), \
145 "Create frame rotation residual data.\n\n" \
146 ":param model: frame rotation residual model\n" \
147 ":param data: shared data")[bp::with_custodian_and_ward< \
148 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
149 .def(ResidualDataFrameRotationVisitor<Data>()) \
150 .def(CopyableVisitor<Data>());
151
152 10 void exposeResidualFrameRotation() {
153
17/34
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 10 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 10 times.
✗ Branch 57 not taken.
20 CROCODDYL_PYTHON_SCALARS(
154 CROCODDYL_RESIDUAL_MODEL_FRAME_ROTATION_PYTHON_BINDINGS)
155
15/30
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 32 taken 10 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
20 CROCODDYL_PYTHON_SCALARS(
156 CROCODDYL_RESIDUAL_DATA_FRAME_ROTATION_PYTHON_BINDINGS)
157 10 }
158
159 } // namespace python
160 } // namespace crocoddyl
161