GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/force-base.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 20 21 95.2%
Branches: 35 70 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/force-base.hpp"
10
11 #include "python/crocoddyl/multibody/contact-base.hpp"
12 #include "python/crocoddyl/multibody/impulse-base.hpp"
13 #include "python/crocoddyl/multibody/multibody.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 template <typename Data>
19 struct ForceDataAbstractVisitor
20 : public bp::def_visitor<ForceDataAbstractVisitor<Data>> {
21 typedef typename Data::Scalar Scalar;
22 typedef ImpulseModelAbstractTpl<Scalar> ImpulseModel;
23 typedef pinocchio::DataTpl<Scalar> PinocchioData;
24 template <class PyClass>
25 40 void visit(PyClass& cl) const {
26
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 cl.def(
27
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
40 bp::init<ImpulseModel*, PinocchioData*>()[bp::with_custodian_and_ward<
28 1, 2, bp::with_custodian_and_ward<1, 3>>()])
29
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property("pinocchio",
30 bp::make_getter(&Data::pinocchio,
31 bp::return_internal_reference<>()),
32 "pinocchio data")
33
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("frame", &Data::frame, "frame id of the contact")
34
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("type", &Data::type, "type of contact")
35
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(
36 "jMf",
37 bp::make_getter(&Data::jMf,
38 40 bp::return_value_policy<bp::return_by_value>()),
39 bp::make_setter(&Data::jMf),
40 "local frame placement of the contact frame")
41
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(
42 40 "Jc", bp::make_getter(&Data::Jc, bp::return_internal_reference<>()),
43 bp::make_setter(&Data::Jc), "contact Jacobian")
44
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite(
45 "f", &Data::f,
46 "contact force expressed in the coordinate defined by type")
47
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite(
48 "fext", &Data::fext,
49 "external spatial force at the parent joint level. Note "
50 "that we could compute the force at the "
51 "contact frame by using jMf (i.e. data.jMf.actInv(data.f)")
52
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(
53 "df_dx",
54 40 bp::make_getter(&Data::df_dx, bp::return_internal_reference<>()),
55 bp::make_setter(&Data::df_dx),
56 "Jacobian of the contact forces expressed in the "
57 "coordinate defined by type")
58
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(
59 "df_du",
60 40 bp::make_getter(&Data::df_du, bp::return_internal_reference<>()),
61 bp::make_setter(&Data::df_du),
62 "Jacobian of the contact forces expressed in the "
63 "coordinate defined by type");
64 40 }
65 };
66
67 #define CROCODDYL_FORCE_DATA_ABSTRACT_PYTHON_BINDINGS(Scalar) \
68 typedef ForceDataAbstractTpl<Scalar> Data; \
69 typedef ContactModelAbstractTpl<Scalar> ContactModel; \
70 typedef pinocchio::DataTpl<Scalar> PinocchioData; \
71 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
72 bp::class_<Data>( \
73 "ForceDataAbstract", "Abstract class for force datas.\n\n", \
74 bp::init<ContactModel*, PinocchioData*>( \
75 bp::args("self", "model", "data"), \
76 "Create common data shared between force models.\n\n" \
77 ":param model: force/impulse model\n" \
78 ":param data: Pinocchio data")[bp::with_custodian_and_ward< \
79 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
80 .def(ForceDataAbstractVisitor<Data>()) \
81 .def(CopyableVisitor<Data>());
82
83 10 void exposeForceAbstract() {
84
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(CROCODDYL_FORCE_DATA_ABSTRACT_PYTHON_BINDINGS)
85 10 }
86
87 } // namespace python
88 } // namespace crocoddyl
89