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