GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/contacts/contact-3d-float.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 37 0.0%
Branches: 0 104 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, 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 // Auto-generated file for float
11 #include "crocoddyl/multibody/contacts/contact-3d.hpp"
12
13 #include "python/crocoddyl/multibody/multibody.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 template <typename Model>
19 struct ContactModel3DVisitor
20 : public bp::def_visitor<ContactModel3DVisitor<Model>> {
21 typedef typename Model::StateMultibody State;
22 typedef typename Model::Vector3s Vector3s;
23 typedef typename Model::Vector2s Vector2s;
24 template <class PyClass>
25 void visit(PyClass& cl) const {
26 cl.def(bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Vector3s,
27 pinocchio::ReferenceFrame, bp::optional<Vector2s>>(
28 bp::args("self", "state", "id", "xref", "type", "gains"),
29 "Initialize the contact model.\n\n"
30 ":param state: state of the multibody system\n"
31 ":param id: reference frame id of the contact\n"
32 ":param xref: contact position used for the Baumgarte "
33 "stabilization\n"
34 ":param type: type of contact\n"
35 ":param gains: gains of the contact model (default "
36 "np.matrix([0.,0.]))"))
37 .def("calc", &Model::calc, bp::args("self", "data", "x"),
38 "Compute the 3d contact Jacobian and drift.\n\n"
39 "The rigid contact model throught acceleration-base holonomic "
40 "constraint of the contact frame placement.\n"
41 ":param data: contact data\n"
42 ":param x: state point (dim. state.nx)")
43 .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x"),
44 "Compute the derivatives of the 3d contact holonomic "
45 "constraint.\n\n"
46 "The rigid contact model throught acceleration-base holonomic "
47 "constraint of the contact frame placement. It assumes that calc "
48 "has been run first.\n"
49 ":param data: cost data\n"
50 ":param x: state point (dim. state.nx)")
51 .def("updateForce", &Model::updateForce,
52 bp::args("self", "data", "force"),
53 "Convert the force into a stack of spatial forces.\n\n"
54 ":param data: cost data\n"
55 ":param force: force vector (dimension 3)")
56 .def("createData", &Model::createData,
57 bp::with_custodian_and_ward_postcall<0, 2>(),
58 bp::args("self", "data"),
59 "Create the 3D contact data.\n\n"
60 "Each contact model has its own data that needs to be allocated. "
61 "This function returns the allocated data for a predefined cost.\n"
62 ":param data: Pinocchio data\n"
63 ":return contact data.")
64 .add_property("reference",
65 bp::make_function(&Model::get_reference,
66 bp::return_internal_reference<>()),
67 &Model::set_reference, "reference contact translation")
68 .add_property(
69 "gains",
70 bp::make_function(&Model::get_gains,
71 bp::return_value_policy<bp::return_by_value>()),
72 "contact gains");
73 }
74 };
75
76 template <typename Data>
77 struct ContactData3DVisitor
78 : public bp::def_visitor<ContactData3DVisitor<Data>> {
79 template <class PyClass>
80 void visit(PyClass& cl) const {
81 cl.add_property(
82 "v",
83 bp::make_getter(&Data::v,
84 bp::return_value_policy<bp::return_by_value>()),
85 "spatial velocity of the contact body")
86 .add_property(
87 "a0_local",
88 bp::make_getter(&Data::a0_local, bp::return_internal_reference<>()),
89 bp::make_setter(&Data::a0_local),
90 "desired local contact acceleration")
91 .add_property(
92 "dp", bp::make_getter(&Data::dp, bp::return_internal_reference<>()),
93 bp::make_setter(&Data::dp),
94 "Translation error computed for the Baumgarte regularization term")
95 .add_property(
96 "dp_local",
97 bp::make_getter(&Data::dp_local, bp::return_internal_reference<>()),
98 bp::make_setter(&Data::dp_local),
99 "local translation error computed for the Baumgarte "
100 "regularization term")
101 .add_property(
102 "f_local",
103 bp::make_getter(&Data::f_local, bp::return_internal_reference<>()),
104 bp::make_setter(&Data::f_local),
105 "spatial contact force in local coordinates")
106 .add_property("da0_local_dx",
107 bp::make_getter(&Data::da0_local_dx,
108 bp::return_internal_reference<>()),
109 bp::make_setter(&Data::da0_local_dx),
110 "Jacobian of the desired local contact acceleration")
111 .add_property(
112 "fJf",
113 bp::make_getter(&Data::fJf, bp::return_internal_reference<>()),
114 "local Jacobian of the contact frame")
115 .add_property("v_partial_dq",
116 bp::make_getter(&Data::v_partial_dq,
117 bp::return_internal_reference<>()),
118 "Jacobian of the spatial body velocity")
119 .add_property("a_partial_dq",
120 bp::make_getter(&Data::a_partial_dq,
121 bp::return_internal_reference<>()),
122 "Jacobian of the spatial body acceleration")
123 .add_property("a_partial_dv",
124 bp::make_getter(&Data::a_partial_dv,
125 bp::return_internal_reference<>()),
126 "Jacobian of the spatial body acceleration")
127 .add_property("a_partial_da",
128 bp::make_getter(&Data::a_partial_da,
129 bp::return_internal_reference<>()),
130 "Jacobian of the spatial body acceleration");
131 }
132 };
133
134 #define CROCODDYL_CONTACT_MODEL_3D_PYTHON_BINDINGS(Scalar) \
135 typedef ContactModel3DTpl<Scalar> Model; \
136 typedef ContactModelAbstractTpl<Scalar> ModelBase; \
137 typedef Model::StateMultibody State; \
138 typedef Model::Vector3s Vector3s; \
139 typedef Model::Vector2s Vector2s; \
140 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
141 bp::class_<Model, bp::bases<ModelBase>>( \
142 "ContactModel3D", \
143 "Rigid 3D contact model.\n\n" \
144 "It defines a rigid 3D contact models (point contact) based on " \
145 "acceleration-based holonomic constraints. The calc and calcDiff " \
146 "functions compute the contact Jacobian and drift (holonomic " \
147 "constraint) or the derivatives of the holonomic constraint, " \
148 "respectively.", \
149 bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Vector3s, \
150 pinocchio::ReferenceFrame, \
151 bp::optional<std::size_t, Vector2s>>( \
152 bp::args("self", "state", "id", "xref", "type", "nu", "gains"), \
153 "Initialize the contact model.\n\n" \
154 ":param state: state of the multibody system\n" \
155 ":param id: reference frame id of the contact\n" \
156 ":param xref: contact position used for the Baumgarte " \
157 "stabilization\n" \
158 ":param type: type of contact\n" \
159 ":param nu: dimension of control vector (default state.nv)\n" \
160 ":param gains: gains of the contact model (default " \
161 "np.array([0.,0.]))")) \
162 .def(ContactModel3DVisitor<Model>()) \
163 .def(CastVisitor<Model>()) \
164 .def(PrintableVisitor<Model>()) \
165 .def(CopyableVisitor<Model>());
166
167 #define CROCODDYL_CONTACT_DATA_3D_PYTHON_BINDINGS(Scalar) \
168 typedef ContactData3DTpl<Scalar> Data; \
169 typedef ContactDataAbstractTpl<Scalar> DataBase; \
170 typedef ContactModel3DTpl<Scalar> Model; \
171 typedef pinocchio::DataTpl<Scalar> PinocchioData; \
172 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
173 bp::class_<Data, bp::bases<DataBase>>( \
174 "ContactData3D", "Data for 3D contact.\n\n", \
175 bp::init<Model*, PinocchioData*>( \
176 bp::args("self", "model", "data"), \
177 "Create 3D contact data.\n\n" \
178 ":param model: 3D contact model\n" \
179 ":param data: Pinocchio data")[bp::with_custodian_and_ward< \
180 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
181 .def(ContactData3DVisitor<Data>()) \
182 .def(CopyableVisitor<Data>());
183
184 void exposeContact3D() {
185 #pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has
186 // been removed in a future release
187 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
188
189 CROCODDYL_CONTACT_MODEL_3D_PYTHON_BINDINGS(float)
190
191 #pragma GCC diagnostic pop
192
193 CROCODDYL_CONTACT_DATA_3D_PYTHON_BINDINGS(float)
194 }
195
196 } // namespace python
197 } // namespace crocoddyl
198