GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/contacts/contact-6d-float.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 29 0.0%
Branches: 0 78 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-6d.hpp"
12
13 #include "python/crocoddyl/multibody/multibody.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 template <typename Model>
19 struct ContactModel6DVisitor
20 : public bp::def_visitor<ContactModel6DVisitor<Model>> {
21 typedef typename Model::StateMultibody State;
22 typedef typename Model::SE3 SE3;
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, SE3,
27 pinocchio::ReferenceFrame, bp::optional<Vector2s>>(
28 bp::args("self", "state", "id", "pref", "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 pref: contact placement 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 6D 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 6D 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 Lagrangian into a stack of spatial forces.\n\n"
54 ":param data: cost data\n"
55 ":param force: force vector (dimension 6)")
56 .def("createData", &Model::createData,
57 bp::with_custodian_and_ward_postcall<0, 2>(),
58 bp::args("self", "data"),
59 "Create the 6D 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 placement")
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 ContactData6DVisitor
78 : public bp::def_visitor<ContactData6DVisitor<Data>> {
79 template <class PyClass>
80 void visit(PyClass& cl) const {
81 cl.add_property(
82 "rMf",
83 bp::make_getter(&Data::jMf,
84 bp::return_value_policy<bp::return_by_value>()),
85 "error frame placement of the contact frame")
86 .add_property(
87 "v",
88 bp::make_getter(&Data::v,
89 bp::return_value_policy<bp::return_by_value>()),
90 "spatial velocity of the contact body")
91 .add_property(
92 "a0_local",
93 bp::make_getter(&Data::a0_local,
94 bp::return_value_policy<bp::return_by_value>()),
95 "desired local contact acceleration")
96 .add_property("v_partial_dq",
97 bp::make_getter(&Data::v_partial_dq,
98 bp::return_internal_reference<>()),
99 "Jacobian of the spatial body velocity")
100 .add_property("a_partial_dq",
101 bp::make_getter(&Data::a_partial_dq,
102 bp::return_internal_reference<>()),
103 "Jacobian of the spatial body acceleration")
104 .add_property("a_partial_dv",
105 bp::make_getter(&Data::a_partial_dv,
106 bp::return_internal_reference<>()),
107 "Jacobian of the spatial body acceleration")
108 .add_property("a_partial_da",
109 bp::make_getter(&Data::a_partial_da,
110 bp::return_internal_reference<>()),
111 "Jacobian of the spatial body acceleration");
112 }
113 };
114
115 #define CROCODDYL_CONTACT_MODEL_6D_PYTHON_BINDINGS(Scalar) \
116 typedef ContactModel6DTpl<Scalar> Model; \
117 typedef ContactModelAbstractTpl<Scalar> ModelBase; \
118 typedef Model::StateMultibody State; \
119 typedef Model::SE3 SE3; \
120 typedef Model::Vector2s Vector2s; \
121 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
122 bp::class_<Model, bp::bases<ModelBase>>( \
123 "ContactModel6D", \
124 "Rigid 6D contact model.\n\n" \
125 "It defines a rigid 6D contact models based on acceleration-based " \
126 "holonomic constraints. The calc and calcDiff functions compute the " \
127 "contact Jacobian and drift (holonomic constraint) or the derivatives " \
128 "of the holonomic constraint, respectively.", \
129 bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, SE3, \
130 pinocchio::ReferenceFrame, std::size_t, \
131 bp::optional<Vector2s>>( \
132 bp::args("self", "state", "id", "pref", "type", "nu", "gains"), \
133 "Initialize the contact model.\n\n" \
134 ":param state: state of the multibody system\n" \
135 ":param id: reference frame id of the contact\n" \
136 ":param pref: contact placement used for the Baumgarte " \
137 "stabilization\n" \
138 ":param type: type of contact\n" \
139 ":param nu: dimension of control vector\n" \
140 ":param gains: gains of the contact model (default " \
141 "np.matrix([0.,0.]))")) \
142 .def(ContactModel6DVisitor<Model>()) \
143 .def(CastVisitor<Model>()) \
144 .def(PrintableVisitor<Model>()) \
145 .def(CopyableVisitor<Model>());
146
147 #define CROCODDYL_CONTACT_DATA_6D_PYTHON_BINDINGS(Scalar) \
148 typedef ContactData6DTpl<Scalar> Data; \
149 typedef ContactDataAbstractTpl<Scalar> DataBase; \
150 typedef ContactModel6DTpl<Scalar> Model; \
151 typedef pinocchio::DataTpl<Scalar> PinocchioData; \
152 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
153 bp::class_<Data, bp::bases<DataBase>>( \
154 "ContactData6D", "Data for 6D contact.\n\n", \
155 bp::init<Model*, PinocchioData*>( \
156 bp::args("self", "model", "data"), \
157 "Create 6D contact data.\n\n" \
158 ":param model: 6D contact model\n" \
159 ":param data: Pinocchio data")[bp::with_custodian_and_ward< \
160 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
161 .def(ContactData6DVisitor<Data>()) \
162 .def(CopyableVisitor<Data>());
163
164 void exposeContact6D() {
165 #pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has
166 // been removed in a future release
167 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
168
169 CROCODDYL_CONTACT_MODEL_6D_PYTHON_BINDINGS(float)
170
171 #pragma GCC diagnostic pop
172
173 CROCODDYL_CONTACT_DATA_6D_PYTHON_BINDINGS(float)
174 }
175
176 } // namespace python
177 } // namespace crocoddyl
178