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