GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/contacts/contact-1d.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 72 81 88.9%
Branches: 59 118 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-1d.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 exposeContact1D() {
19 10 bp::register_ptr_to_python<boost::shared_ptr<ContactModel1D> >();
20
21
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ContactModel1D, bp::bases<ContactModelAbstract> >(
22 "ContactModel1D",
23 "Rigid 1D contact model.\n\n"
24 "It defines a rigid 1D contact model (point contact) based on "
25 "acceleration-based holonomic constraints, in the "
26 "z "
27 "direction.\n"
28 "The calc and calcDiff functions compute the contact Jacobian and drift "
29 "(holonomic constraint) or\n"
30 "the derivatives of the holonomic constraint, respectively.",
31
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, double,
32 pinocchio::ReferenceFrame, Eigen::Matrix3d, std::size_t,
33 bp::optional<Eigen::Vector2d> >(
34 20 bp::args("self", "state", "id", "xref", "type", "rotation", "nu",
35 "gains"),
36 "Initialize the contact model.\n\n"
37 ":param state: state of the multibody system\n"
38 ":param id: reference frame id of the contact\n"
39 ":param xref: contact position used for the Baumgarte stabilization\n"
40 ":param type: type of contact\n"
41 ":param rotation: rotation of the reference frame's z axis"
42 ":param nu: dimension of control vector\n"
43 ":param gains: gains of the contact model (default "
44 "np.matrix([0.,0.]))"))
45
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,
46 double, pinocchio::ReferenceFrame,
47 bp::optional<Eigen::Vector2d> >(
48
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state", "id", "xref", "type", "gains"),
49 "Initialize the contact model.\n\n"
50 ":param state: state of the multibody system\n"
51 ":param id: reference frame id of the contact\n"
52 ":param xref: contact position used for the Baumgarte stabilization\n"
53 ":param type: type of contact\n"
54 ":param gains: gains of the contact model (default "
55 "np.matrix([0.,0.]))"))
56
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("calc", &ContactModel1D::calc, bp::args("self", "data", "x"),
57 "Compute the 1D contact Jacobian and drift.\n\n"
58 "The rigid contact model throught acceleration-base holonomic "
59 "constraint\n"
60 "of the contact frame placement.\n"
61 ":param data: contact data\n"
62 ":param x: state point (dim. state.nx)")
63
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("calcDiff", &ContactModel1D::calcDiff, bp::args("self", "data", "x"),
64 "Compute the derivatives of the 1D contact holonomic constraint.\n\n"
65 "The rigid contact model throught acceleration-base holonomic "
66 "constraint\n"
67 "of the contact frame placement.\n"
68 "It assumes that calc has been run first.\n"
69 ":param data: cost data\n"
70 ":param x: state point (dim. state.nx)")
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("updateForce", &ContactModel1D::updateForce,
72
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "force"),
73 "Convert the force into a stack of spatial forces.\n\n"
74 ":param data: cost data\n"
75 ":param force: force vector (dimension 1)")
76
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("createData", &ContactModel1D::createData,
77 bp::with_custodian_and_ward_postcall<0, 2>(),
78
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
79 "Create the 1D contact data.\n\n"
80 "Each contact model has its own data that needs to be allocated. "
81 "This function\n"
82 "returns the allocated data for a predefined cost.\n"
83 ":param data: Pinocchio data\n"
84 ":return contact data.")
85
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
86 "reference",
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ContactModel1D::get_reference,
88 10 bp::return_value_policy<bp::return_by_value>()),
89 &ContactModel1D::set_reference, "reference contact translation")
90
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Raxis",
91
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ContactModel1D::get_axis_rotation,
92 10 bp::return_internal_reference<>()),
93 &ContactModel1D::set_axis_rotation,
94 "rotation of the reference frame's z axis")
95
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
96 "gains",
97
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ContactModel1D::get_gains,
98 10 bp::return_value_policy<bp::return_by_value>()),
99 "contact gains")
100
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ContactModel1D>());
101
102 10 bp::register_ptr_to_python<boost::shared_ptr<ContactData1D> >();
103
104
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ContactData1D, bp::bases<ContactDataAbstract> >(
105 "ContactData1D", "Data for 1D contact.\n\n",
106
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<ContactModel1D*, pinocchio::Data*>(
107 10 bp::args("self", "model", "data"),
108 "Create 1D contact data.\n\n"
109 ":param model: 1D 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(
113 "v",
114
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::v,
115 10 bp::return_value_policy<bp::return_by_value>()),
116 "spatial velocity of the contact body")
117
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a0_local",
118
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::a0_local,
119 bp::return_internal_reference<>()),
120
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::a0_local),
121 "desired local contact acceleration")
122
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a0_skew",
123
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::a0_skew,
124 bp::return_internal_reference<>()),
125
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::a0_skew),
126 "contact acceleration skew (local)")
127
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a0_world_skew",
128
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::a0_world_skew,
129 bp::return_internal_reference<>()),
130
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::a0_world_skew),
131 "contact acceleration skew (world)")
132
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
133 "dp",
134
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::dp,
135 bp::return_internal_reference<>()),
136
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::dp),
137 "Translation error computed for the Baumgarte regularization term")
138
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dp_local",
139
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::dp_local,
140 bp::return_internal_reference<>()),
141
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::dp_local),
142 "local translation error computed for the Baumgarte "
143 "regularization term")
144
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("f_local",
145
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::f_local,
146 bp::return_internal_reference<>()),
147
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::f_local),
148 "spatial contact force in local coordinates")
149
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("da0_local_dx",
150
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::da0_local_dx,
151 bp::return_internal_reference<>()),
152
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ContactData1D::da0_local_dx),
153 "Jacobian of the desired local contact acceleration")
154
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("fJf",
155
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::fJf,
156 10 bp::return_internal_reference<>()),
157 "local Jacobian of the contact frame")
158
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("v_partial_dq",
159
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::v_partial_dq,
160 10 bp::return_internal_reference<>()),
161 "Jacobian of the spatial body velocity")
162
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a_partial_dq",
163
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::a_partial_dq,
164 10 bp::return_internal_reference<>()),
165 "Jacobian of the spatial body acceleration")
166
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a_partial_dv",
167
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::a_partial_dv,
168 10 bp::return_internal_reference<>()),
169 "Jacobian of the spatial body acceleration")
170
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("a_partial_da",
171
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::a_partial_da,
172 10 bp::return_internal_reference<>()),
173 "Jacobian of the spatial body acceleration")
174
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
175 "oRf",
176
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ContactData1D::oRf,
177 10 bp::return_internal_reference<>()),
178 "Rotation matrix of the contact body expressed in the world frame")
179
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ContactData1D>());
180 10 }
181
182 } // namespace python
183 } // namespace crocoddyl
184