Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/impulse-base.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 50 | 55 | 90.9% |
Branches: | 49 | 98 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-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 "python/crocoddyl/multibody/impulse-base.hpp" | ||
11 | |||
12 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
13 | #include "python/crocoddyl/utils/copyable.hpp" | ||
14 | #include "python/crocoddyl/utils/deprecate.hpp" | ||
15 | #include "python/crocoddyl/utils/printable.hpp" | ||
16 | |||
17 | namespace crocoddyl { | ||
18 | namespace python { | ||
19 | |||
20 | 10 | void exposeImpulseAbstract() { | |
21 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ImpulseModelAbstract> >(); | |
22 | |||
23 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ImpulseModelAbstract_wrap, boost::noncopyable>( |
24 | "ImpulseModelAbstract", | ||
25 | "Abstract impulse model.\n\n" | ||
26 | "It defines a template for impulse models.\n" | ||
27 | "The calc and calcDiff functions compute the impulse Jacobian\n" | ||
28 | "the derivatives respectively.", | ||
29 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<StateMultibody>, pinocchio::ReferenceFrame, |
30 | 20 | std::size_t>(bp::args("self", "state", "type", "nc"), | |
31 | "Initialize the impulse model.\n\n" | ||
32 | ":param state: state of the multibody system\n" | ||
33 | ":param type: type of impulse\n" | ||
34 | ":param nc: dimension of impulse model")) | ||
35 |
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>, std::size_t>( |
36 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "state", "nc"), |
37 | "Initialize the impulse model.\n\n" | ||
38 | ":param state: state of the multibody system\n" | ||
39 | ":param nc: dimension of impulse model")) | ||
40 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calc", pure_virtual(&ImpulseModelAbstract_wrap::calc), |
41 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x"), |
42 | "Compute the impulse Jacobian\n" | ||
43 | ":param data: impulse data\n" | ||
44 | ":param x: state point (dim. state.nx)") | ||
45 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calcDiff", pure_virtual(&ImpulseModelAbstract_wrap::calcDiff), |
46 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x"), |
47 | "Compute the derivatives of impulse Jacobian\n" | ||
48 | "It assumes that calc has been run first.\n" | ||
49 | ":param data: impulse data\n" | ||
50 | ":param x: state point (dim. state.nx)") | ||
51 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("updateForce", pure_virtual(&ImpulseModelAbstract_wrap::updateForce), |
52 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "force"), |
53 | "Convert the force into a stack of spatial forces.\n\n" | ||
54 | ":param data: impulse data\n" | ||
55 | ":param force: force vector (dimension nc)") | ||
56 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateForceDiff", &ImpulseModelAbstract_wrap::updateForceDiff, |
57 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "df_dx"), |
58 | "Update the Jacobian of the impulse force.\n\n" | ||
59 | ":param data: impulse data\n" | ||
60 | ":param df_dx: Jacobian of the impulse force (dimension nc*ndx)") | ||
61 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("setZeroForce", &ImpulseModelAbstract_wrap::setZeroForce, |
62 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
63 | "Set zero the spatial force.\n\n" | ||
64 | ":param data: contact data") | ||
65 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("setZeroForceDiff", &ImpulseModelAbstract_wrap::setZeroForceDiff, |
66 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
67 | "Set zero the derivatives of the spatial force.\n\n" | ||
68 | ":param data: contact data") | ||
69 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &ImpulseModelAbstract_wrap::createData, |
70 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
71 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
72 | "Create the impulse data.\n\n" | ||
73 | "Each impulse model has its own data that needs to be allocated. " | ||
74 | "This function\n" | ||
75 | "returns the allocated data for a predefined impulse.\n" | ||
76 | ":param data: Pinocchio data\n" | ||
77 | ":return impulse data.") | ||
78 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &ImpulseModelAbstract_wrap::default_createData, |
79 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>()) | |
80 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
81 | "state", | ||
82 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ImpulseModelAbstract_wrap::get_state, |
83 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
84 | "state of the multibody system") | ||
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("ni", |
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ImpulseModelAbstract_wrap::get_nc, |
87 |
2/4✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
|
20 | deprecated<>("Deprecated. Use nc")), |
88 | "dimension of impulse") | ||
89 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .add_property("nc", bp::make_function(&ImpulseModelAbstract_wrap::get_nc), |
90 | "dimension of impulse") | ||
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("id", &ImpulseModelAbstract_wrap::get_id, |
92 | &ImpulseModelAbstract_wrap::set_id, "reference frame id") | ||
93 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("type", |
94 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ImpulseModelAbstract_wrap::get_type), |
95 | &ImpulseModelAbstract_wrap::set_type, "type of impulse") | ||
96 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ImpulseModelAbstract_wrap>()) |
97 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(PrintableVisitor<ImpulseModelAbstract>()); |
98 | |||
99 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ImpulseDataAbstract> >(); | |
100 | |||
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ImpulseDataAbstract, bp::bases<ForceDataAbstract> >( |
102 | "ImpulseDataAbstract", "Abstract class for impulse data.\n\n", | ||
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ImpulseModelAbstract*, pinocchio::Data*>( |
104 | 10 | bp::args("self", "model", "data"), | |
105 | "Create common data shared between impulse models.\n\n" | ||
106 | ":param model: impulse model\n" | ||
107 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | ":param data: Pinocchio data")[bp::with_custodian_and_ward<1, 3>()]) |
108 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("fXj", |
109 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataAbstract::fXj, |
110 | ✗ | bp::return_internal_reference<>()), | |
111 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataAbstract::fXj), |
112 | "action matrix from contact to local frames") | ||
113 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dv0_dq", |
114 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataAbstract::dv0_dq, |
115 | ✗ | bp::return_internal_reference<>()), | |
116 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataAbstract::dv0_dq), |
117 | "Jacobian of the previous impulse velocity") | ||
118 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dtau_dq", |
119 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataAbstract::dtau_dq, |
120 | ✗ | bp::return_internal_reference<>()), | |
121 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataAbstract::dtau_dq), |
122 | "force contribution to dtau_dq") | ||
123 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ImpulseDataAbstract>()); |
124 | 10 | } | |
125 | |||
126 | } // namespace python | ||
127 | } // namespace crocoddyl | ||
128 |