GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/contact-base.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 49 56 87.5%
Branches: 47 94 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, 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 #include "python/crocoddyl/multibody/contact-base.hpp"
11
12 #include "python/crocoddyl/multibody/multibody.hpp"
13 #include "python/crocoddyl/utils/copyable.hpp"
14 #include "python/crocoddyl/utils/printable.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 10 void exposeContactAbstract() {
20 10 bp::register_ptr_to_python<boost::shared_ptr<ContactModelAbstract> >();
21
22
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ContactModelAbstract_wrap, boost::noncopyable>(
23 "ContactModelAbstract",
24 "Abstract rigid contact model.\n\n"
25 "It defines a template for rigid contact models based on "
26 "acceleration-based holonomic constraints.\n"
27 "The calc and calcDiff functions compute the contact Jacobian and drift "
28 "(holonomic constraint) or\n"
29 "the derivatives of the holonomic constraint, respectively.",
30
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateMultibody>, pinocchio::ReferenceFrame,
31 std::size_t, bp::optional<std::size_t> >(
32 20 bp::args("self", "state", "type", "nc", "nu"),
33 "Initialize the contact model.\n\n"
34 ":param state: state of the multibody system\n"
35 ":param type: type of contact\n"
36 ":param nc: dimension of contact model\n"
37 ":param nu: dimension of the control vector (default state.nv)"))
38
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def("calc", pure_virtual(&ContactModelAbstract_wrap::calc),
39
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"),
40 "Compute the contact Jacobian and drift.\n\n"
41 "The rigid contact model throught acceleration-base holonomic "
42 "constraint\n"
43 "of the contact frame placement.\n"
44 ":param data: contact data\n"
45 ":param x: state point (dim. state.nx)")
46
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def("calcDiff", pure_virtual(&ContactModelAbstract_wrap::calcDiff),
47
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"),
48 "Compute the derivatives of contact holonomic constraint.\n\n"
49 "The rigid contact model throught acceleration-base holonomic "
50 "constraint\n"
51 "of the contact frame placement.\n"
52 "It assumes that calc has been run first.\n"
53 ":param data: contact data\n"
54 ":param x: state point (dim. state.nx)")
55
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def("updateForce", pure_virtual(&ContactModelAbstract_wrap::updateForce),
56
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "force"),
57 "Convert the force into a stack of spatial forces.\n\n"
58 ":param data: contact data\n"
59 ":param force: force vector (dimension nc)")
60
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("updateForceDiff", &ContactModelAbstract_wrap::updateForceDiff,
61
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "df_dx", "df_du"),
62 "Update the Jacobians of the force.\n\n"
63 ":param data: contact data\n"
64 ":param df_dx: Jacobian of the force with respect to the state\n"
65 ":param df_du: Jacobian of the force with respect to the control")
66
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("setZeroForce", &ContactModelAbstract_wrap::setZeroForce,
67
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
68 "Set zero the spatial force.\n\n"
69 ":param data: contact data")
70
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("setZeroForceDiff", &ContactModelAbstract_wrap::setZeroForceDiff,
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
72 "Set zero the derivatives of the spatial force.\n\n"
73 ":param data: contact data")
74
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("createData", &ContactModelAbstract_wrap::createData,
75 bp::with_custodian_and_ward_postcall<0, 2>(),
76
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
77 "Create the contact data.\n\n"
78 "Each contact model has its own data that needs to be allocated. "
79 "This function\n"
80 "returns the allocated data for a predefined contact.\n"
81 ":param data: Pinocchio data\n"
82 ":return contact data.")
83
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("createData", &ContactModelAbstract_wrap::default_createData,
84 bp::with_custodian_and_ward_postcall<0, 2>())
85
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
86 "state",
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ContactModelAbstract_wrap::get_state,
88 10 bp::return_value_policy<bp::return_by_value>()),
89 "state of the multibody system")
90
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .add_property("nc", bp::make_function(&ContactModelAbstract_wrap::get_nc),
91 "dimension of contact")
92
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .add_property("nu", bp::make_function(&ContactModelAbstract_wrap::get_nu),
93 "dimension of control")
94
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("id", &ContactModelAbstract_wrap::get_id,
95 &ContactModelAbstract_wrap::set_id, "reference frame id")
96
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("type",
97
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ContactModelAbstract_wrap::get_type),
98 &ContactModelAbstract_wrap::set_type, "type of contact")
99
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ContactModelAbstract_wrap>())
100
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(PrintableVisitor<ContactModelAbstract>());
101
102 10 bp::register_ptr_to_python<boost::shared_ptr<ContactDataAbstract> >();
103
104
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ContactDataAbstract, bp::bases<ForceDataAbstract> >(
105 "ContactDataAbstract", "Abstract class for contact datas.\n\n",
106
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<ContactModelAbstract*, pinocchio::Data*>(
107 10 bp::args("self", "model", "data"),
108 "Create common data shared between contact models.\n\n"
109 ":param model: contact model\n"
110 ":param data: Pinocchio data")[bp::with_custodian_and_ward<
111
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 1, 2, bp::with_custodian_and_ward<1, 3> >()])
112
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("fXj",
113
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactDataAbstract::fXj,
114 bp::return_internal_reference<>()),
115
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactDataAbstract::fXj),
116 "action matrix from contact to local frames")
117
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a0",
118
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactDataAbstract::a0,
119 bp::return_internal_reference<>()),
120
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactDataAbstract::a0),
121 "desired contact acceleration")
122
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("da0_dx",
123
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactDataAbstract::da0_dx,
124 bp::return_internal_reference<>()),
125
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactDataAbstract::da0_dx),
126 "Jacobian of the desired contact acceleration")
127
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dtau_dq",
128
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactDataAbstract::dtau_dq,
129 bp::return_internal_reference<>()),
130
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactDataAbstract::dtau_dq),
131 "Force contribution to dtau_dq")
132
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ContactDataAbstract>());
133 10 }
134
135 } // namespace python
136 } // namespace crocoddyl
137