GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/contacts/contact-2d.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 51 53 96.2%
Branches: 38 76 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-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 "crocoddyl/multibody/contacts/contact-2d.hpp"
11
12 #include "python/crocoddyl/multibody/multibody.hpp"
13 #include "python/crocoddyl/utils/copyable.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 10 void exposeContact2D() {
19 10 bp::register_ptr_to_python<boost::shared_ptr<ContactModel2D> >();
20
21 #pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has
22 // been removed in a future release
23 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
24
25
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ContactModel2D, bp::bases<ContactModelAbstract> >(
26 "ContactModel2D",
27 "Rigid 2D contact model.\n\n"
28 "It defines a rigid 2D contact models (point contact) based on "
29 "acceleration-based holonomic constraints, in x,z "
30 "directions.\n"
31 "The calc and calcDiff functions compute the contact Jacobian and drift "
32 "(holonomic constraint) or\n"
33 "the derivatives of the holonomic constraint, respectively.",
34
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex,
35 Eigen::Vector2d, std::size_t, bp::optional<Eigen::Vector2d> >(
36 20 bp::args("self", "state", "id", "xref", "nu", "gains"),
37 "Initialize the contact model.\n\n"
38 ":param state: state of the multibody system\n"
39 ":param id: reference frame id of the contact\n"
40 ":param xref: contact position used for the Baumgarte stabilization\n"
41 ":param nu: dimension of control vector\n"
42 ":param gains: gains of the contact model (default "
43 "np.matrix([0.,0.]))"))
44
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex,
45 Eigen::Vector2d, bp::optional<Eigen::Vector2d> >(
46
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state", "id", "xref", "gains"),
47 "Initialize the contact model.\n\n"
48 ":param state: state of the multibody system\n"
49 ":param id: reference frame id of the contact\n"
50 ":param xref: contact position used for the Baumgarte stabilization\n"
51 ":param gains: gains of the contact model (default "
52 "np.matrix([0.,0.]))"))
53
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("calc", &ContactModel2D::calc, bp::args("self", "data", "x"),
54 "Compute the 2D contact Jacobian and drift.\n\n"
55 "The rigid contact model throught acceleration-base holonomic "
56 "constraint\n"
57 "of the contact frame placement.\n"
58 ":param data: contact data\n"
59 ":param x: state point (dim. state.nx)")
60
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("calcDiff", &ContactModel2D::calcDiff, bp::args("self", "data", "x"),
61 "Compute the derivatives of the 2D contact holonomic constraint.\n\n"
62 "The rigid contact model throught acceleration-base holonomic "
63 "constraint\n"
64 "of the contact frame placement.\n"
65 "It assumes that calc has been run first.\n"
66 ":param data: cost data\n"
67 ":param x: state point (dim. state.nx)")
68
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("updateForce", &ContactModel2D::updateForce,
69
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "force"),
70 "Convert the force into a stack of spatial forces.\n\n"
71 ":param data: cost data\n"
72 ":param force: force vector (dimension 2)")
73
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("createData", &ContactModel2D::createData,
74 bp::with_custodian_and_ward_postcall<0, 2>(),
75
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
76 "Create the 2D contact data.\n\n"
77 "Each contact model has its own data that needs to be allocated. "
78 "This function\n"
79 "returns the allocated data for a predefined cost.\n"
80 ":param data: Pinocchio data\n"
81 ":return contact data.")
82
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("reference",
83
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ContactModel2D::get_reference,
84 10 bp::return_internal_reference<>()),
85 &ContactModel2D::set_reference,
86 "reference contact translation")
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
88 "gains",
89
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ContactModel2D::get_gains,
90 10 bp::return_value_policy<bp::return_by_value>()),
91 "contact gains")
92
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ContactModel2D>());
93
94 #pragma GCC diagnostic pop
95
96 10 bp::register_ptr_to_python<boost::shared_ptr<ContactData2D> >();
97
98
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ContactData2D, bp::bases<ContactDataAbstract> >(
99 "ContactData2D", "Data for 2D contact.\n\n",
100
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<ContactModel2D*, pinocchio::Data*>(
101 10 bp::args("self", "model", "data"),
102 "Create 2D contact data.\n\n"
103 ":param model: 2D contact model\n"
104 ":param data: Pinocchio data")[bp::with_custodian_and_ward<
105
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 1, 2, bp::with_custodian_and_ward<1, 3> >()])
106
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
107 "v",
108
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::v,
109 10 bp::return_value_policy<bp::return_by_value>()),
110 "spatial velocity of the contact body")
111
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
112 "a",
113
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::a,
114 10 bp::return_value_policy<bp::return_by_value>()),
115 "spatial acceleration of the contact body")
116
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("fJf",
117
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::fJf,
118 10 bp::return_internal_reference<>()),
119 "local Jacobian of the contact frame")
120
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("v_partial_dq",
121
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::v_partial_dq,
122 10 bp::return_internal_reference<>()),
123 "Jacobian of the spatial body velocity")
124
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a_partial_dq",
125
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::a_partial_dq,
126 10 bp::return_internal_reference<>()),
127 "Jacobian of the spatial body acceleration")
128
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a_partial_dv",
129
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::a_partial_dv,
130 10 bp::return_internal_reference<>()),
131 "Jacobian of the spatial body acceleration")
132
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a_partial_da",
133
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::a_partial_da,
134 10 bp::return_internal_reference<>()),
135 "Jacobian of the spatial body acceleration")
136
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
137 "oRf",
138
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData2D::oRf,
139 10 bp::return_internal_reference<>()),
140 "Rotation matrix of the contact body expressed in the world frame")
141
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ContactData2D>());
142 10 }
143
144 } // namespace python
145 } // namespace crocoddyl
146