GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/impulse-base-double.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 29 0.0%
Branches: 0 100 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 double
11 #include "python/crocoddyl/multibody/impulse-base.hpp"
12
13 #include "python/crocoddyl/multibody/multibody.hpp"
14 #include "python/crocoddyl/utils/deprecate.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 template <typename Model>
20 struct ImpulseModelAbstractVisitor
21 : public bp::def_visitor<ImpulseModelAbstractVisitor<Model>> {
22 typedef typename Model::StateMultibody State;
23 template <class PyClass>
24 void visit(PyClass& cl) const {
25 cl.def(bp::init<std::shared_ptr<State>, std::size_t>(
26 bp::args("self", "state", "nc"),
27 "Initialize the impulse model.\n\n"
28 ":param state: state of the multibody system\n"
29 ":param nc: dimension of impulse model"))
30 .def("calc", pure_virtual(&Model::calc), bp::args("self", "data", "x"),
31 "Compute the impulse Jacobian\n"
32 ":param data: impulse data\n"
33 ":param x: state point (dim. state.nx)")
34 .def("calcDiff", pure_virtual(&Model::calcDiff),
35 bp::args("self", "data", "x"),
36 "Compute the derivatives of impulse Jacobian\n"
37 "It assumes that calc has been run first.\n"
38 ":param data: impulse data\n"
39 ":param x: state point (dim. state.nx)")
40 .def("updateForce", pure_virtual(&Model::updateForce),
41 bp::args("self", "data", "force"),
42 "Convert the force into a stack of spatial forces.\n\n"
43 ":param data: impulse data\n"
44 ":param force: force vector (dimension nc)")
45 .def("updateForceDiff", &Model::updateForceDiff,
46 bp::args("self", "data", "df_dx"),
47 "Update the Jacobian of the impulse force.\n\n"
48 ":param data: impulse data\n"
49 ":param df_dx: Jacobian of the impulse force (dimension nc*ndx)")
50 .def("setZeroForce", &Model::setZeroForce, bp::args("self", "data"),
51 "Set zero the spatial force.\n\n"
52 ":param data: contact data")
53 .def("setZeroForceDiff", &Model::setZeroForceDiff,
54 bp::args("self", "data"),
55 "Set zero the derivatives of the spatial force.\n\n"
56 ":param data: contact data")
57 .def("createData", &Model::createData,
58 bp::with_custodian_and_ward_postcall<0, 2>(),
59 bp::args("self", "data"),
60 "Create the impulse data.\n\n"
61 "Each impulse model has its own data that needs to be allocated. "
62 "This function\n"
63 "returns the allocated data for a predefined impulse.\n"
64 ":param data: Pinocchio data\n"
65 ":return impulse data.")
66 .def("createData", &Model::default_createData,
67 bp::with_custodian_and_ward_postcall<0, 2>())
68 .add_property(
69 "state",
70 bp::make_function(&Model::get_state,
71 bp::return_value_policy<bp::return_by_value>()),
72 "state of the multibody system")
73 .add_property("ni",
74 bp::make_function(&Model::get_nc,
75 deprecated<>("Deprecated. Use nc")),
76 "dimension of impulse")
77 .add_property("nc", bp::make_function(&Model::get_nc),
78 "dimension of impulse")
79 .add_property("id", &Model::get_id, &Model::set_id,
80 "reference frame id")
81 .add_property("type", bp::make_function(&Model::get_type),
82 &Model::set_type, "type of impulse");
83 }
84 };
85
86 template <typename Data>
87 struct ImpulseDataAbstractVisitor
88 : public bp::def_visitor<ImpulseDataAbstractVisitor<Data>> {
89 template <class PyClass>
90 void visit(PyClass& cl) const {
91 cl.add_property(
92 "fXj", bp::make_getter(&Data::fXj, bp::return_internal_reference<>()),
93 bp::make_setter(&Data::fXj),
94 "action matrix from contact to local frames")
95 .add_property(
96 "dv0_dq",
97 bp::make_getter(&Data::dv0_dq, bp::return_internal_reference<>()),
98 bp::make_setter(&Data::dv0_dq),
99 "Jacobian of the previous impulse velocity")
100 .add_property(
101 "dtau_dq",
102 bp::make_getter(&Data::dtau_dq, bp::return_internal_reference<>()),
103 bp::make_setter(&Data::dtau_dq), "force contribution to dtau_dq");
104 }
105 };
106
107 #define CROCODDYL_IMPULSE_MODEL_ABSTRACT_PYTHON_BINDINGS(Scalar) \
108 typedef ImpulseModelAbstractTpl<Scalar> Model; \
109 typedef ImpulseModelAbstractTpl_wrap<Scalar> Model_wrap; \
110 typedef Model::StateMultibody State; \
111 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
112 bp::class_<Model_wrap, boost::noncopyable>( \
113 "ImpulseModelAbstract", \
114 "Abstract impulse model.\n\n" \
115 "It defines a template for impulse models.\n" \
116 "The calc and calcDiff functions compute the impulse Jacobian the " \
117 "derivatives respectively.", \
118 bp::init<std::shared_ptr<State>, pinocchio::ReferenceFrame, \
119 std::size_t>(bp::args("self", "state", "type", "nc"), \
120 "Initialize the impulse model.\n\n" \
121 ":param state: state of the multibody system\n" \
122 ":param type: type of impulse\n" \
123 ":param nc: dimension of impulse model")) \
124 .def(ImpulseModelAbstractVisitor<Model_wrap>()) \
125 .def(PrintableVisitor<Model_wrap>()) \
126 .def(CopyableVisitor<Model_wrap>());
127
128 #define CROCODDYL_IMPULSE_DATA_ABSTRACT_PYTHON_BINDINGS(Scalar) \
129 typedef ImpulseDataAbstractTpl<Scalar> Data; \
130 typedef ImpulseModelAbstractTpl<Scalar> Model; \
131 typedef ForceDataAbstractTpl<Scalar> ForceData; \
132 typedef pinocchio::DataTpl<Scalar> PinocchioData; \
133 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
134 bp::class_<Data, bp::bases<ForceData>>( \
135 "ImpulseDataAbstract", "Abstract class for impulse data.\n\n", \
136 bp::init<Model*, PinocchioData*>( \
137 bp::args("self", "model", "data"), \
138 "Create common data shared between impulse models.\n\n" \
139 ":param model: impulse model\n" \
140 ":param data: Pinocchio data")[bp::with_custodian_and_ward<1, 3>()]) \
141 .def(ImpulseDataAbstractVisitor<Data>()) \
142 .def(CopyableVisitor<Data>());
143
144 void exposeImpulseAbstract() {
145 CROCODDYL_IMPULSE_MODEL_ABSTRACT_PYTHON_BINDINGS(double)
146 CROCODDYL_IMPULSE_DATA_ABSTRACT_PYTHON_BINDINGS(double)
147 }
148
149 } // namespace python
150 } // namespace crocoddyl
151