Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/residuals/frame-translation.cpp |
Date: | 2025-02-24 23:41:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 35 | 37 | 94.6% |
Branches: | 27 | 54 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include "crocoddyl/multibody/residuals/frame-translation.hpp" | ||
10 | |||
11 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
12 | #include "python/crocoddyl/utils/copyable.hpp" | ||
13 | |||
14 | namespace crocoddyl { | ||
15 | namespace python { | ||
16 | |||
17 | 10 | void exposeResidualFrameTranslation() { | |
18 | 10 | bp::register_ptr_to_python<std::shared_ptr<ResidualModelFrameTranslation> >(); | |
19 | |||
20 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualModelFrameTranslation, bp::bases<ResidualModelAbstract> >( |
21 | "ResidualModelFrameTranslation", | ||
22 | "This residual function defines the the frame translation tracking as as " | ||
23 | "r = t - tref, with t and tref as the\n" | ||
24 | "current and reference frame translations, respectively.", | ||
25 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
26 | Eigen::Vector3d, std::size_t>( | ||
27 | 20 | bp::args("self", "state", "id", "xref", "nu"), | |
28 | "Initialize the frame translation residual model.\n\n" | ||
29 | ":param state: state of the multibody system\n" | ||
30 | ":param id: reference frame id\n" | ||
31 | ":param xref: reference frame translation\n" | ||
32 | ":param nu: dimension of control vector")) | ||
33 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<std::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
34 | Eigen::Vector3d>( | ||
35 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "state", "id", "xref"), |
36 | "Initialize the frame translation residual model.\n\n" | ||
37 | "The default nu is obtained from state.nv.\n" | ||
38 | ":param state: state of the multibody system\n" | ||
39 | ":param id: reference frame id\n" | ||
40 | ":param xref: reference frame translation")) | ||
41 | .def<void (ResidualModelFrameTranslation::*)( | ||
42 | const std::shared_ptr<ResidualDataAbstract>&, | ||
43 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
44 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
45 | "calc", &ResidualModelFrameTranslation::calc, | ||
46 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
47 | "Compute the frame translation residual.\n\n" | ||
48 | ":param data: residual data\n" | ||
49 | ":param x: state point (dim. state.nx)\n" | ||
50 | ":param u: control input (dim. nu)") | ||
51 | .def<void (ResidualModelFrameTranslation::*)( | ||
52 | const std::shared_ptr<ResidualDataAbstract>&, | ||
53 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
54 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x")) |
55 | .def<void (ResidualModelFrameTranslation::*)( | ||
56 | const std::shared_ptr<ResidualDataAbstract>&, | ||
57 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
58 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
59 | "calcDiff", &ResidualModelFrameTranslation::calcDiff, | ||
60 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
61 | "Compute the derivatives of the frame translation residual.\n\n" | ||
62 | "It assumes that calc has been run first.\n" | ||
63 | ":param data: action data\n" | ||
64 | ":param x: state point (dim. state.nx)\n" | ||
65 | ":param u: control input (dim. nu)") | ||
66 | .def<void (ResidualModelFrameTranslation::*)( | ||
67 | const std::shared_ptr<ResidualDataAbstract>&, | ||
68 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
69 | "calcDiff", &ResidualModelAbstract::calcDiff, | ||
70 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
71 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("createData", &ResidualModelFrameTranslation::createData, |
72 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
73 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
74 | "Create the frame translation residual data.\n\n" | ||
75 | "Each residual model has its own data that needs to be allocated. " | ||
76 | "This function\n" | ||
77 | "returns the allocated data for the frame translation residual.\n" | ||
78 | ":param data: shared data\n" | ||
79 | ":return residual data.") | ||
80 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("id", &ResidualModelFrameTranslation::get_id, |
81 | &ResidualModelFrameTranslation::set_id, | ||
82 | "reference frame id") | ||
83 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
84 | "reference", | ||
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ResidualModelFrameTranslation::get_reference, |
86 | 10 | bp::return_internal_reference<>()), | |
87 | &ResidualModelFrameTranslation::set_reference, | ||
88 | "reference frame translation") | ||
89 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualModelFrameTranslation>()); |
90 | |||
91 | 10 | bp::register_ptr_to_python<std::shared_ptr<ResidualDataFrameTranslation> >(); | |
92 | |||
93 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualDataFrameTranslation, bp::bases<ResidualDataAbstract> >( |
94 | "ResidualDataFrameTranslation", | ||
95 | "Data for frame translation residual.\n\n", | ||
96 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ResidualModelFrameTranslation*, DataCollectorAbstract*>( |
97 | 10 | bp::args("self", "model", "data"), | |
98 | "Create frame translation residual data.\n\n" | ||
99 | ":param model: frame translation residual model\n" | ||
100 | ✗ | ":param data: shared data")[bp::with_custodian_and_ward< | |
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
102 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("pinocchio", |
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataFrameTranslation::pinocchio, |
104 | 10 | bp::return_internal_reference<>()), | |
105 | "pinocchio data") | ||
106 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("fJf", |
107 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataFrameTranslation::fJf, |
108 | 10 | bp::return_internal_reference<>()), | |
109 | "local Jacobian of the frame") | ||
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualDataFrameTranslation>()); |
111 | 10 | } | |
112 | |||
113 | } // namespace python | ||
114 | } // namespace crocoddyl | ||
115 |