GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/residuals/frame-placement.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 25 26 96.2%
Branches: 55 110 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-placement.hpp"
10
11 #include "python/crocoddyl/multibody/multibody.hpp"
12
13 namespace crocoddyl {
14 namespace python {
15
16 template <typename Model>
17 struct ResidualModelFramePlacementVisitor
18 : public bp::def_visitor<ResidualModelFramePlacementVisitor<Model>> {
19 typedef typename Model::ResidualDataAbstract Data;
20 typedef typename Model::Base ModelBase;
21 typedef typename Model::StateMultibody State;
22 typedef typename Model::SE3 SE3;
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, SE3>(
27 bp::args("self", "state", "id", "pref"),
28 "Initialize the frame placement residual model.\n\n"
29 "The default nu value is obtained from state.nv.\n"
30 ":param state: state of the multibody system\n"
31 ":param id: reference frame id\n"
32 ":param pref: reference frame placement"))
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 placement 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 placement 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", &ResidualModelFramePlacement::createData,
67 bp::with_custodian_and_ward_postcall<0, 2>(),
68 bp::args("self", "data"),
69 "Create the frame placement residual data.\n\n"
70 "Each residual model has its own data that needs to be allocated. "
71 "This function returns the allocated data for the frame placement "
72 "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 placement");
82 40 }
83 };
84
85 template <typename Data>
86 struct ResidualDataFramePlacementVisitor
87 : public bp::def_visitor<ResidualDataFramePlacementVisitor<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 "rMf",
96 bp::make_getter(&Data::rMf,
97 40 bp::return_value_policy<bp::return_by_value>()),
98 "error frame placement of the frame")
99
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
100 "rJf",
101 40 bp::make_getter(&Data::rJf, bp::return_internal_reference<>()),
102 "error Jacobian of the frame")
103
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
104 "fJf",
105 40 bp::make_getter(&Data::fJf, bp::return_internal_reference<>()),
106 "local Jacobian of the frame");
107 40 }
108 };
109
110 #define CROCODDYL_RESIDUAL_MODEL_FRAME_PLACEMENT_PYTHON_BINDINGS(Scalar) \
111 typedef ResidualModelFramePlacementTpl<Scalar> Model; \
112 typedef ResidualModelAbstractTpl<Scalar> ModelBase; \
113 typedef typename Model::StateMultibody State; \
114 typedef typename Model::SE3 SE3; \
115 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
116 bp::class_<Model, bp::bases<ModelBase>>( \
117 "ResidualModelFramePlacement", \
118 "This residual function defines the tracking of theframe placement " \
119 "residual as r = p - pref, with p and pref as the current and " \
120 "reference frame placements, respectively.", \
121 bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, SE3, \
122 std::size_t>( \
123 bp::args("self", "state", "id", "pref", "nu"), \
124 "Initialize the frame placement residual model.\n\n" \
125 ":param state: state of the multibody system\n" \
126 ":param id: reference frame id\n" \
127 ":param pref: reference frame placement\n" \
128 ":param nu: dimension of control vector")) \
129 .def(ResidualModelFramePlacementVisitor<Model>()) \
130 .def(CastVisitor<Model>()) \
131 .def(PrintableVisitor<Model>()) \
132 .def(CopyableVisitor<Model>());
133
134 #define CROCODDYL_RESIDUAL_DATA_FRAME_PLACEMENT_PYTHON_BINDINGS(Scalar) \
135 typedef ResidualDataFramePlacementTpl<Scalar> Data; \
136 typedef ResidualDataAbstractTpl<Scalar> DataBase; \
137 typedef ResidualModelFramePlacementTpl<Scalar> Model; \
138 typedef Model::DataCollectorAbstract DataCollector; \
139 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
140 bp::class_<Data, bp::bases<DataBase>>( \
141 "ResidualDataFramePlacement", "Data for frame placement residual.\n\n", \
142 bp::init<Model*, DataCollector*>( \
143 bp::args("self", "model", "data"), \
144 "Create frame placement residual data.\n\n" \
145 ":param model: frame placement residual model\n" \
146 ":param data: shared data")[bp::with_custodian_and_ward< \
147 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
148 .def(ResidualDataFramePlacementVisitor<Data>()) \
149 .def(CopyableVisitor<Data>());
150
151 10 void exposeResidualFramePlacement() {
152
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(
153 CROCODDYL_RESIDUAL_MODEL_FRAME_PLACEMENT_PYTHON_BINDINGS)
154
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(
155 CROCODDYL_RESIDUAL_DATA_FRAME_PLACEMENT_PYTHON_BINDINGS)
156 10 }
157
158 } // namespace python
159 } // namespace crocoddyl
160