Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-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/core/actions/unicycle.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/core/action-base.hpp" |
14 |
|
|
#include "python/crocoddyl/core/core.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Model> |
20 |
|
|
struct ActionModelUnicycleVisitor |
21 |
|
|
: public bp::def_visitor<ActionModelUnicycleVisitor<Model>> { |
22 |
|
|
typedef typename Model::ActionDataAbstract Data; |
23 |
|
|
typedef typename Model::VectorXs VectorXs; |
24 |
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS(ActionModelLQR_Random_wrap, Model::Random, 2, |
25 |
|
|
4) |
26 |
|
|
template <class PyClass> |
27 |
|
✗ |
void visit(PyClass& cl) const { |
28 |
|
✗ |
cl.def("calc", |
29 |
|
|
static_cast<void (Model::*)( |
30 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
31 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calc), |
32 |
|
|
bp::args("self", "data", "x", "u"), |
33 |
|
|
"Compute the next state and cost value.\n\n" |
34 |
|
|
"It describes the time-discrete evolution of the unicycle system. " |
35 |
|
|
"Additionally it computes the cost value associated to this " |
36 |
|
|
"discrete state and control pair.\n" |
37 |
|
|
":param data: action data\n" |
38 |
|
|
":param x: state point (dim. state.nx)\n" |
39 |
|
|
":param u: control input (dim. nu)") |
40 |
|
✗ |
.def("calc", |
41 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
42 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
43 |
|
|
&Model::calc), |
44 |
|
|
bp::args("self", "data", "x")) |
45 |
|
✗ |
.def( |
46 |
|
|
"calcDiff", |
47 |
|
|
static_cast<void (Model::*)( |
48 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
49 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), |
50 |
|
|
bp::args("self", "data", "x", "u"), |
51 |
|
|
"Compute the derivatives of the unicycle dynamics and cost " |
52 |
|
|
"functions.\n\n" |
53 |
|
|
"It computes the partial derivatives of the unicycle system and " |
54 |
|
|
"the cost function. It assumes that calc has been run first. This " |
55 |
|
|
"function builds a quadratic approximation of the action model " |
56 |
|
|
"(i.e. dynamical system and cost function).\n" |
57 |
|
|
":param data: action data\n" |
58 |
|
|
":param x: state point (dim. state.nx)\n" |
59 |
|
|
":param u: control input (dim. nu)") |
60 |
|
✗ |
.def("calcDiff", |
61 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
62 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
63 |
|
|
&Model::calcDiff), |
64 |
|
|
bp::args("self", "data", "x")) |
65 |
|
✗ |
.def("createData", &Model::createData, bp::args("self"), |
66 |
|
|
"Create the unicycle action data.") |
67 |
|
✗ |
.add_property( |
68 |
|
|
"ng", bp::make_function(&Model::get_ng), "number of equality constraints") |
69 |
|
✗ |
.add_property( |
70 |
|
|
"nh", bp::make_function(&Model::get_nh), "number of inequality constraints") |
71 |
|
✗ |
.add_property( |
72 |
|
|
"ng_T", bp::make_function(&Model::get_ng_T), "number of equality terminal constraints") |
73 |
|
✗ |
.add_property( |
74 |
|
|
"nh_T", bp::make_function(&Model::get_nh_T), "number of inequality terminal constraints") |
75 |
|
✗ |
.add_property("dt", bp::make_function(&Model::get_dt), |
76 |
|
|
bp::make_function(&Model::set_dt), "integration time") |
77 |
|
✗ |
.add_property("costWeights", |
78 |
|
|
bp::make_function(&Model::get_cost_weights, |
79 |
|
✗ |
bp::return_internal_reference<>()), |
80 |
|
|
bp::make_function(&Model::set_cost_weights), |
81 |
|
|
"cost weights"); |
82 |
|
|
} |
83 |
|
|
}; |
84 |
|
|
|
85 |
|
|
#define CROCODDYL_ACTION_MODEL_UNICYCLE_PYTHON_BINDINGS(Scalar) \ |
86 |
|
|
typedef ActionModelUnicycleTpl<Scalar> Model; \ |
87 |
|
|
typedef ActionModelAbstractTpl<Scalar> ModelBase; \ |
88 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
89 |
|
|
bp::class_<Model, bp::bases<ModelBase>>( \ |
90 |
|
|
"ActionModelUnicycle", \ |
91 |
|
|
"Unicycle action model.\n\n" \ |
92 |
|
|
"The transition model of an unicycle system is described as\n" \ |
93 |
|
|
" xnext = [v*cos(theta); v*sin(theta); w],\n" \ |
94 |
|
|
"where the position is defined by (x, y, theta) and the control input " \ |
95 |
|
|
"by (v,w). Note that the state is defined only with the position. On " \ |
96 |
|
|
"the other hand, we define the quadratic cost functions for the state " \ |
97 |
|
|
"and control.", \ |
98 |
|
|
bp::init<>(bp::args("self"), "Initialize the unicycle action model.")) \ |
99 |
|
|
.def(ActionModelUnicycleVisitor<Model>()) \ |
100 |
|
|
.def(CastVisitor<Model>()) \ |
101 |
|
|
.def(PrintableVisitor<Model>()) \ |
102 |
|
|
.def(CopyableVisitor<Model>()); |
103 |
|
|
|
104 |
|
|
#define CROCODDYL_ACTION_DATA_UNICYCLE_PYTHON_BINDINGS(Scalar) \ |
105 |
|
|
typedef ActionDataUnicycleTpl<Scalar> Data; \ |
106 |
|
|
typedef ActionDataAbstractTpl<Scalar> DataBase; \ |
107 |
|
|
typedef ActionModelUnicycleTpl<Scalar> Model; \ |
108 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
109 |
|
|
bp::class_<Data, bp::bases<DataBase>>( \ |
110 |
|
|
"ActionDataUnicycle", \ |
111 |
|
|
"Action data for the Unicycle system.\n\n" \ |
112 |
|
|
"The unicycle data, apart of common one, contains the cost residuals " \ |
113 |
|
|
"used for the computation of calc and calcDiff.", \ |
114 |
|
|
bp::init<Model*>(bp::args("self", "model"), \ |
115 |
|
|
"Create unicycle data.\n\n" \ |
116 |
|
|
":param model: unicycle action model")) \ |
117 |
|
|
.def(CopyableVisitor<Data>()); |
118 |
|
|
|
119 |
|
✗ |
void exposeActionUnicycle() { |
120 |
|
✗ |
CROCODDYL_ACTION_MODEL_UNICYCLE_PYTHON_BINDINGS(double) |
121 |
|
✗ |
CROCODDYL_ACTION_DATA_UNICYCLE_PYTHON_BINDINGS(double) |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
} // namespace python |
125 |
|
|
} // namespace crocoddyl |
126 |
|
|
|