GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/data/joint.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 23 23 100.0%
Branches: 57 114 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2022-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/core/data/joint.hpp"
10
11 #include "python/crocoddyl/core/core.hpp"
12
13 namespace crocoddyl {
14 namespace python {
15
16 template <typename Data>
17 struct JointDataAbstractVisitor
18 : public bp::def_visitor<JointDataAbstractVisitor<Data>> {
19 template <class PyClass>
20 40 void visit(PyClass& cl) const {
21
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 cl.add_property(
22 40 "tau", bp::make_getter(&Data::tau, bp::return_internal_reference<>()),
23 bp::make_setter(&Data::tau), "joint efforts")
24
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 .add_property(
25 40 "a", bp::make_getter(&Data::a, bp::return_internal_reference<>()),
26 bp::make_setter(&Data::a), "generalized joint accelerations")
27
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 .add_property(
28 "dtau_dx",
29 40 bp::make_getter(&Data::dtau_dx, bp::return_internal_reference<>()),
30 bp::make_setter(&Data::dtau_dx),
31 "partial derivatives of the joint efforts w.r.t. the state point")
32
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 .add_property(
33 "dtau_du",
34 40 bp::make_getter(&Data::dtau_du, bp::return_internal_reference<>()),
35 bp::make_setter(&Data::dtau_du),
36 "partial derivatives of the joint efforts w.r.t. the control input")
37
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 .add_property(
38 "da_dx",
39 40 bp::make_getter(&Data::da_dx, bp::return_internal_reference<>()),
40 bp::make_setter(&Data::da_dx),
41 "partial derivatives of the generalized joint accelerations w.r.t. "
42 "the state point")
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 .add_property(
44 "da_du",
45 40 bp::make_getter(&Data::da_du, bp::return_internal_reference<>()),
46 bp::make_setter(&Data::da_du),
47 "partial derivatives of the generalized joint accelerations w.r.t. "
48 "the control input");
49 40 }
50 };
51
52 template <typename Data>
53 struct DataCollectorJointVisitor
54 : public bp::def_visitor<DataCollectorJointVisitor<Data>> {
55 template <class PyClass>
56 40 void visit(PyClass& cl) const {
57
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 cl.add_property(
58 "joint",
59 bp::make_getter(&Data::joint,
60 40 bp::return_value_policy<bp::return_by_value>()),
61 "joint data");
62 40 }
63 };
64
65 #define CROCODDYL_JOINT_DATA_ABSTRACT_PYTHON_BINDINGS(Scalar) \
66 typedef JointDataAbstractTpl<Scalar> Data; \
67 typedef typename Data::StateAbstract State; \
68 typedef typename Data::ActuationModelAbstract Actuation; \
69 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
70 bp::class_<Data>( \
71 "JointDataAbstract", \
72 "Abstract class for joint datas.\n\n" \
73 "A joint data contains all the required information about joint " \
74 "efforts and accelerations. The joint data typically is allocated once " \
75 "by running model.createData().", \
76 bp::init<std::shared_ptr<State>, std::shared_ptr<Actuation>, \
77 std::size_t>( \
78 bp::args("self", "state", "actuation", "nu"), \
79 "Create the joint data.\n\n" \
80 "The joint data uses the model in order to first process it.\n" \
81 ":param state: state description\n" \
82 ":param actuation: actuation model\n" \
83 ":param nu: dimension of control vector.")) \
84 .def(JointDataAbstractVisitor<Data>()) \
85 .def(CopyableVisitor<Data>());
86
87 #define CROCODDYL_DATA_COLLECTOR_JOINT_PYTHON_BINDINGS(Scalar) \
88 typedef DataCollectorJointTpl<Scalar> Data; \
89 typedef DataCollectorAbstractTpl<Scalar> DataBase; \
90 typedef JointDataAbstractTpl<Scalar> JointData; \
91 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
92 bp::class_<Data, bp::bases<DataBase>>( \
93 "DataCollectorJoint", "Joint data collector.\n\n", \
94 bp::init<std::shared_ptr<JointData>>(bp::args("self", "joint"), \
95 "Create joint data collection.\n\n" \
96 ":param joint: joint data")) \
97 .def(DataCollectorJointVisitor<Data>()) \
98 .def(CopyableVisitor<Data>());
99
100 #define CROCODDYL_DATA_COLLECTOR_ACTUATION_PYTHON_BINDINGS(Scalar) \
101 typedef DataCollectorJointActuationTpl<Scalar> Data; \
102 typedef DataCollectorActuationTpl<Scalar> DataBase; \
103 typedef ActuationDataAbstractTpl<Scalar> ActuationData; \
104 typedef JointDataAbstractTpl<Scalar> JointData; \
105 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
106 bp::class_<Data, bp::bases<DataBase>>( \
107 "DataCollectorJointActuation", "Joint-actuation data collector.\n\n", \
108 bp::init<std::shared_ptr<ActuationData>, std::shared_ptr<JointData>>( \
109 bp::args("self", "actuation", "joint"), \
110 "Create joint-actuation data collection.\n\n" \
111 ":param actuation: actuation data" \
112 ":param joint: joint data")) \
113 .def(CopyableVisitor<Data>());
114
115 10 void exposeDataCollectorJoint() {
116
13/26
✓ 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 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 29 taken 10 times.
✗ Branch 30 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.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_JOINT_DATA_ABSTRACT_PYTHON_BINDINGS)
117
13/26
✓ 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 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 29 taken 10 times.
✗ Branch 30 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.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_DATA_COLLECTOR_JOINT_PYTHON_BINDINGS)
118
11/22
✓ 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 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 26 taken 10 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 10 times.
✗ Branch 30 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.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_DATA_COLLECTOR_ACTUATION_PYTHON_BINDINGS)
119 10 }
120
121 } // namespace python
122 } // namespace crocoddyl
123