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-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 |
✓✗ |
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 |
✓✗ |
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 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
35 |
|
|
pinocchio::SE3>( |
36 |
✓✗ |
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 |
✓✗ |
10 |
":param pref: reference frame placement")) |
42 |
|
|
.def<void (ResidualModelFramePlacement::*)( |
43 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
44 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
45 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
46 |
|
|
"calc", &ResidualModelFramePlacement::calc, |
47 |
✓✗ |
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 |
✓✗ |
10 |
":param u: control input (dim. nu)") |
52 |
|
|
.def<void (ResidualModelFramePlacement::*)( |
53 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
54 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
55 |
✓✗ |
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 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
60 |
|
|
"calcDiff", &ResidualModelFramePlacement::calcDiff, |
61 |
✓✗ |
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 |
✓✗✓✗
|
20 |
":param u: control input (dim. nu)") |
67 |
|
|
.def<void (ResidualModelFramePlacement::*)( |
68 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
69 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
70 |
|
|
"calcDiff", &ResidualModelAbstract::calcDiff, |
71 |
✓✗ |
20 |
bp::args("self", "data", "x")) |
72 |
|
|
.def("createData", &ResidualModelFramePlacement::createData, |
73 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
74 |
✓✗ |
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 |
✓✗✓✗
|
20 |
":return residual data.") |
81 |
|
|
.add_property("id", &ResidualModelFramePlacement::get_id, |
82 |
✓✗ |
10 |
&ResidualModelFramePlacement::set_id, "reference frame id") |
83 |
|
|
.add_property( |
84 |
|
|
"reference", |
85 |
|
|
bp::make_function(&ResidualModelFramePlacement::get_reference, |
86 |
|
10 |
bp::return_internal_reference<>()), |
87 |
|
|
&ResidualModelFramePlacement::set_reference, |
88 |
✓✗✓✗
|
10 |
"reference frame placement") |
89 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualModelFramePlacement>()); |
90 |
|
|
|
91 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ResidualDataFramePlacement> >(); |
92 |
|
|
|
93 |
✓✗ |
10 |
bp::class_<ResidualDataFramePlacement, bp::bases<ResidualDataAbstract> >( |
94 |
|
|
"ResidualDataFramePlacement", "Data for frame placement residual.\n\n", |
95 |
✓✗ |
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 |
|
10 |
":param data: shared data")[bp::with_custodian_and_ward< |
100 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
101 |
|
|
.add_property("pinocchio", |
102 |
✓✗ |
10 |
bp::make_getter(&ResidualDataFramePlacement::pinocchio, |
103 |
|
10 |
bp::return_internal_reference<>()), |
104 |
✓✗ |
10 |
"pinocchio data") |
105 |
|
|
.add_property( |
106 |
|
|
"rMf", |
107 |
✓✗ |
10 |
bp::make_getter(&ResidualDataFramePlacement::rMf, |
108 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
109 |
✓✗ |
10 |
"error frame placement of the frame") |
110 |
|
|
.add_property("rJf", |
111 |
✓✗ |
10 |
bp::make_getter(&ResidualDataFramePlacement::rJf, |
112 |
|
10 |
bp::return_internal_reference<>()), |
113 |
✓✗ |
10 |
"error Jacobian of the frame") |
114 |
|
|
.add_property("fJf", |
115 |
✓✗ |
10 |
bp::make_getter(&ResidualDataFramePlacement::fJf, |
116 |
|
10 |
bp::return_internal_reference<>()), |
117 |
✓✗ |
10 |
"local Jacobian of the frame") |
118 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualDataFramePlacement>()); |
119 |
|
10 |
} |
120 |
|
|
|
121 |
|
|
} // namespace python |
122 |
|
|
} // namespace crocoddyl |