Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2020-2025, LAAS-CNRS, University of Edinburgh, |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
// Auto-generated file for double |
11 |
|
|
#include "crocoddyl/multibody/residuals/control-gravity.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Model> |
20 |
|
|
struct ResidualModelControlGravVisitor |
21 |
|
|
: public bp::def_visitor<ResidualModelControlGravVisitor<Model>> { |
22 |
|
|
typedef typename Model::ResidualDataAbstract Data; |
23 |
|
|
typedef typename Model::Base ModelBase; |
24 |
|
|
typedef typename Model::StateMultibody State; |
25 |
|
|
typedef typename Model::VectorXs VectorXs; |
26 |
|
|
template <class PyClass> |
27 |
|
✗ |
void visit(PyClass& cl) const { |
28 |
|
✗ |
cl.def(bp::init<std::shared_ptr<State>>( |
29 |
|
|
bp::args("self", "state"), |
30 |
|
|
"Initialize the control-gravity residual model.\n\n" |
31 |
|
|
"The default nu is obtained from state.nv.\n" |
32 |
|
|
":param state: state description")) |
33 |
|
✗ |
.def( |
34 |
|
|
"calc", |
35 |
|
|
static_cast<void (Model::*)( |
36 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
37 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calc), |
38 |
|
|
bp::args("self", "data", "x", "u"), |
39 |
|
|
"Compute the control residual.\n\n" |
40 |
|
|
":param data: residual data\n" |
41 |
|
|
":param x: state point (dim. state.nx)\n" |
42 |
|
|
":param u: control input (dim. nu)") |
43 |
|
✗ |
.def("calc", |
44 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
45 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
46 |
|
|
&Model::calc), |
47 |
|
|
bp::args("self", "data", "x")) |
48 |
|
✗ |
.def( |
49 |
|
|
"calcDiff", |
50 |
|
|
static_cast<void (Model::*)( |
51 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
52 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), |
53 |
|
|
bp::args("self", "data", "x", "u"), |
54 |
|
|
"Compute the derivatives of the control residual.\n\n" |
55 |
|
|
":param data: action data\n" |
56 |
|
|
":param x: state point (dim. state.nx)\n" |
57 |
|
|
":param u: control input (dim. nu)") |
58 |
|
✗ |
.def("calcDiff", |
59 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
60 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
61 |
|
|
&Model::calcDiff), |
62 |
|
|
bp::args("self", "data", "x")) |
63 |
|
✗ |
.def("createData", &Model::createData, |
64 |
|
✗ |
bp::with_custodian_and_ward_postcall<0, 2>(), |
65 |
|
|
bp::args("self", "data"), |
66 |
|
|
"Create the control residual data.\n\n" |
67 |
|
|
"Each residual model has its own data that needs to be allocated. " |
68 |
|
|
"This " |
69 |
|
|
"function\n" |
70 |
|
|
"returns the allocated data for the control gravity residual.\n" |
71 |
|
|
":param data: shared data\n" |
72 |
|
|
":return residual data."); |
73 |
|
|
} |
74 |
|
|
}; |
75 |
|
|
|
76 |
|
|
template <typename Data> |
77 |
|
|
struct ResidualDataControlGravVisitor |
78 |
|
|
: public bp::def_visitor<ResidualDataControlGravVisitor<Data>> { |
79 |
|
|
template <class PyClass> |
80 |
|
✗ |
void visit(PyClass& cl) const { |
81 |
|
✗ |
cl.add_property("pinocchio", bp::make_getter(&Data::pinocchio), |
82 |
|
|
"Pinocchio data used for internal computations") |
83 |
|
✗ |
.add_property("actuation", |
84 |
|
|
bp::make_getter(&Data::actuation, |
85 |
|
✗ |
bp::return_internal_reference<>()), |
86 |
|
|
"actuation model"); |
87 |
|
|
} |
88 |
|
|
}; |
89 |
|
|
|
90 |
|
|
#define CROCODDYL_RESIDUAL_MODEL_CONTROL_GRAV_PYTHON_BINDINGS(Scalar) \ |
91 |
|
|
typedef ResidualModelControlGravTpl<Scalar> Model; \ |
92 |
|
|
typedef ResidualModelAbstractTpl<Scalar> ModelBase; \ |
93 |
|
|
typedef typename Model::StateMultibody State; \ |
94 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
95 |
|
|
bp::class_<Model, bp::bases<ModelBase>>( \ |
96 |
|
|
"ResidualModelControlGrav", \ |
97 |
|
|
"This residual function is defined as r = a(u) - g(q), where a(u) is " \ |
98 |
|
|
"the actuated torque; and q, g(q) are the generalized position and " \ |
99 |
|
|
"gravity vector, respectively.", \ |
100 |
|
|
bp::init<std::shared_ptr<State>, std::size_t>( \ |
101 |
|
|
bp::args("self", "state", "nu"), \ |
102 |
|
|
"Initialize the control-gravity residual model.\n\n" \ |
103 |
|
|
":param state: state description\n" \ |
104 |
|
|
":param nu: dimension of the control vector")) \ |
105 |
|
|
.def(ResidualModelControlGravVisitor<Model>()) \ |
106 |
|
|
.def(CastVisitor<Model>()) \ |
107 |
|
|
.def(PrintableVisitor<Model>()) \ |
108 |
|
|
.def(CopyableVisitor<Model>()); |
109 |
|
|
|
110 |
|
|
#define CROCODDYL_RESIDUAL_DATA_CONTROL_GRAV_PYTHON_BINDINGS(Scalar) \ |
111 |
|
|
typedef ResidualDataControlGravTpl<Scalar> Data; \ |
112 |
|
|
typedef ResidualDataAbstractTpl<Scalar> DataBase; \ |
113 |
|
|
typedef ResidualModelControlGravTpl<Scalar> Model; \ |
114 |
|
|
typedef Model::DataCollectorAbstract DataCollector; \ |
115 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
116 |
|
|
bp::class_<Data, bp::bases<DataBase>>( \ |
117 |
|
|
"ResidualDataControlGrav", "Data for control gravity residual.\n\n", \ |
118 |
|
|
bp::init<Model*, DataCollector*>( \ |
119 |
|
|
bp::args("self", "model", "data"), \ |
120 |
|
|
"Create control gravity residual data.\n\n" \ |
121 |
|
|
":param model: control gravity residual model\n" \ |
122 |
|
|
":param data: shared data")[bp::with_custodian_and_ward< \ |
123 |
|
|
1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ |
124 |
|
|
.def(ResidualDataControlGravVisitor<Data>()) \ |
125 |
|
|
.def(CopyableVisitor<Data>()); |
126 |
|
|
|
127 |
|
✗ |
void exposeResidualControlGrav() { |
128 |
|
✗ |
CROCODDYL_RESIDUAL_MODEL_CONTROL_GRAV_PYTHON_BINDINGS(double) |
129 |
|
✗ |
CROCODDYL_RESIDUAL_DATA_CONTROL_GRAV_PYTHON_BINDINGS(double) |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
} // namespace python |
133 |
|
|
} // namespace crocoddyl |
134 |
|
|
|