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 |
✓✗ |
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 |
✓✗ |
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 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
35 |
|
|
Eigen::Vector3d>( |
36 |
✓✗ |
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 |
✓✗ |
10 |
":param xref: reference frame translation")) |
42 |
|
|
.def<void (ResidualModelFrameTranslation::*)( |
43 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
44 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
45 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
46 |
|
|
"calc", &ResidualModelFrameTranslation::calc, |
47 |
✓✗ |
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 |
✓✗ |
10 |
":param u: control input (dim. nu)") |
52 |
|
|
.def<void (ResidualModelFrameTranslation::*)( |
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 (ResidualModelFrameTranslation::*)( |
57 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
58 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
59 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
60 |
|
|
"calcDiff", &ResidualModelFrameTranslation::calcDiff, |
61 |
✓✗ |
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 |
✓✗✓✗
|
20 |
":param u: control input (dim. nu)") |
67 |
|
|
.def<void (ResidualModelFrameTranslation::*)( |
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", &ResidualModelFrameTranslation::createData, |
73 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
74 |
✓✗ |
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 |
✓✗✓✗
|
20 |
":return residual data.") |
81 |
|
|
.add_property("id", &ResidualModelFrameTranslation::get_id, |
82 |
|
|
&ResidualModelFrameTranslation::set_id, |
83 |
✓✗ |
10 |
"reference frame id") |
84 |
|
|
.add_property( |
85 |
|
|
"reference", |
86 |
|
|
bp::make_function(&ResidualModelFrameTranslation::get_reference, |
87 |
|
10 |
bp::return_internal_reference<>()), |
88 |
|
|
&ResidualModelFrameTranslation::set_reference, |
89 |
✓✗✓✗
|
10 |
"reference frame translation") |
90 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualModelFrameTranslation>()); |
91 |
|
|
|
92 |
|
|
bp::register_ptr_to_python< |
93 |
|
10 |
boost::shared_ptr<ResidualDataFrameTranslation> >(); |
94 |
|
|
|
95 |
✓✗ |
10 |
bp::class_<ResidualDataFrameTranslation, bp::bases<ResidualDataAbstract> >( |
96 |
|
|
"ResidualDataFrameTranslation", |
97 |
|
|
"Data for frame translation residual.\n\n", |
98 |
✓✗ |
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 |
|
10 |
":param data: shared data")[bp::with_custodian_and_ward< |
103 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
104 |
|
|
.add_property("pinocchio", |
105 |
✓✗ |
10 |
bp::make_getter(&ResidualDataFrameTranslation::pinocchio, |
106 |
|
10 |
bp::return_internal_reference<>()), |
107 |
✓✗ |
10 |
"pinocchio data") |
108 |
|
|
.add_property("fJf", |
109 |
✓✗ |
10 |
bp::make_getter(&ResidualDataFrameTranslation::fJf, |
110 |
|
10 |
bp::return_internal_reference<>()), |
111 |
✓✗ |
10 |
"local Jacobian of the frame") |
112 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualDataFrameTranslation>()); |
113 |
|
10 |
} |
114 |
|
|
|
115 |
|
|
} // namespace python |
116 |
|
|
} // namespace crocoddyl |