Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/residuals/frame-placement.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 41 | 43 | 95.3% |
Branches: | 31 | 62 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2025, 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-placement.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 exposeResidualFramePlacement() { | |
18 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ResidualModelFramePlacement> >(); | |
19 | |||
20 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualModelFramePlacement, bp::bases<ResidualModelAbstract> >( |
21 | "ResidualModelFramePlacement", | ||
22 | "This residual function defines the tracking of theframe placement " | ||
23 | "residual as r = p - pref, with p and pref " | ||
24 | "as\n" | ||
25 | "the current and reference frame placements, respectively.", | ||
26 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
27 | pinocchio::SE3, std::size_t>( | ||
28 | 20 | bp::args("self", "state", "id", "pref", "nu"), | |
29 | "Initialize the frame placement residual model.\n\n" | ||
30 | ":param state: state of the multibody system\n" | ||
31 | ":param id: reference frame id\n" | ||
32 | ":param pref: reference frame placement\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 | pinocchio::SE3>( | ||
36 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "state", "id", "pref"), |
37 | "Initialize the frame placement residual model.\n\n" | ||
38 | "The default nu value is obtained from state.nv.\n" | ||
39 | ":param state: state of the multibody system\n" | ||
40 | ":param id: reference frame id\n" | ||
41 | ":param pref: reference frame placement")) | ||
42 | .def<void (ResidualModelFramePlacement::*)( | ||
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", &ResidualModelFramePlacement::calc, | ||
47 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
48 | "Compute the frame placement 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 (ResidualModelFramePlacement::*)( | ||
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 (ResidualModelFramePlacement::*)( | ||
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", &ResidualModelFramePlacement::calcDiff, | ||
61 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
62 | "Compute the Jacobians of the frame placement 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 (ResidualModelFramePlacement::*)( | ||
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", &ResidualModelFramePlacement::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 placement 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 placement 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", &ResidualModelFramePlacement::get_id, |
82 | &ResidualModelFramePlacement::set_id, "reference frame id") | ||
83 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("reference", |
84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function( |
85 | &ResidualModelFramePlacement::get_reference, | ||
86 | 10 | bp::return_value_policy<bp::copy_const_reference>()), | |
87 | &ResidualModelFramePlacement::set_reference, | ||
88 | "reference frame placement") | ||
89 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualModelFramePlacement>()); |
90 | |||
91 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ResidualDataFramePlacement> >(); | |
92 | |||
93 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualDataFramePlacement, bp::bases<ResidualDataAbstract> >( |
94 | "ResidualDataFramePlacement", "Data for frame placement residual.\n\n", | ||
95 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ResidualModelFramePlacement*, DataCollectorAbstract*>( |
96 | 10 | bp::args("self", "model", "data"), | |
97 | "Create frame placement residual data.\n\n" | ||
98 | ":param model: frame placement residual model\n" | ||
99 | ✗ | ":param data: shared data")[bp::with_custodian_and_ward< | |
100 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("pinocchio", |
102 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataFramePlacement::pinocchio, |
103 | 10 | bp::return_internal_reference<>()), | |
104 | "pinocchio data") | ||
105 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
106 | "rMf", | ||
107 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataFramePlacement::rMf, |
108 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
109 | "error frame placement of the frame") | ||
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("rJf", |
111 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataFramePlacement::rJf, |
112 | 10 | bp::return_internal_reference<>()), | |
113 | "error Jacobian of the frame") | ||
114 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("fJf", |
115 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataFramePlacement::fJf, |
116 | 10 | bp::return_internal_reference<>()), | |
117 | "local Jacobian of the frame") | ||
118 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualDataFramePlacement>()); |
119 | 10 | } | |
120 | |||
121 | } // namespace python | ||
122 | } // namespace crocoddyl | ||
123 |