GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/state-base.cpp Lines: 52 53 98.1 %
Date: 2024-02-13 11:12:33 Branches: 49 98 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2023, 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
#include "python/crocoddyl/core/state-base.hpp"
11
12
#include "python/crocoddyl/core/core.hpp"
13
#include "python/crocoddyl/utils/copyable.hpp"
14
15
namespace crocoddyl {
16
namespace python {
17
18
10
void exposeStateAbstract() {
19
10
  bp::register_ptr_to_python<boost::shared_ptr<StateAbstract> >();
20
21
20
  bp::enum_<Jcomponent>("Jcomponent")
22
10
      .value("both", both)
23
10
      .value("first", first)
24
10
      .export_values()
25
10
      .value("second", second);
26
27
20
  bp::enum_<AssignmentOp>("AssignmentOp")
28
10
      .value("setto", setto)
29
10
      .value("addto", addto)
30
10
      .value("rmfrom", rmfrom)
31
10
      .export_values();
32
33
10
  bp::class_<StateAbstract_wrap, boost::noncopyable>(
34
      "StateAbstract",
35
      "Abstract class for the state representation.\n\n"
36
      "A state is represented by its operators: difference, integrates and "
37
      "their derivatives.\n"
38
      "The difference operator returns the value of x1 [-] x0 operation. "
39
      "Instead the integrate\n"
40
      "operator returns the value of x [+] dx. These operators are used to "
41
      "compared two points\n"
42
      "on the state manifold M or to advance the state given a tangential "
43
      "velocity (Tx M).\n"
44
      "Therefore the points x, x0 and x1 belong to the manifold M; and dx or "
45
      "x1 [-] x0 lie\n"
46
      "on its tangential space.",
47
20
      bp::init<int, int>(bp::args("self", "nx", "ndx"),
48
                         "Initialize the state dimensions.\n\n"
49
                         ":param nx: dimension of state configuration tuple\n"
50
                         ":param ndx: dimension of state tangent vector"))
51
20
      .def("zero", pure_virtual(&StateAbstract_wrap::zero), bp::args("self"),
52
           "Generate a zero reference state.\n\n"
53

10
           ":return zero reference state")
54
20
      .def("rand", pure_virtual(&StateAbstract_wrap::rand), bp::args("self"),
55
           "Generate a random reference state.\n\n"
56

10
           ":return random reference state")
57
      .def("diff", pure_virtual(&StateAbstract_wrap::diff_wrap),
58
20
           bp::args("self", "x0", "x1"),
59
           "Compute the state manifold differentiation.\n\n"
60
           "It returns the value of x1 [-] x0 operation. Note tha x0 and x1 "
61
           "are points in the state\n"
62
           "manifold (in M). Instead the operator result lies in the "
63
           "tangent-space of M.\n"
64
           ":param x0: previous state point (dim state.nx).\n"
65
           ":param x1: current state point (dim state.nx).\n"
66

10
           ":return x1 [-] x0 value (dim state.ndx).")
67
      .def("integrate", pure_virtual(&StateAbstract_wrap::integrate_wrap),
68
20
           bp::args("self", "x", "dx"),
69
           "Compute the state manifold integration.\n\n"
70
           "It returns the value of x [+] dx operation. x and dx are points in "
71
           "the state.diff(x0,x1) (in M)\n"
72
           "and its tangent, respectively. Note that the operator result lies "
73
           "on M too.\n"
74
           ":param x: state point (dim. state.nx).\n"
75
           ":param dx: velocity vector (dim state.ndx).\n"
76

10
           ":return x [+] dx value (dim state.nx).")
77
      .def("Jdiff", pure_virtual(&StateAbstract_wrap::Jdiff_wrap),
78
20
           bp::args("self", "x0", "x1", "firstsecond"),
79
           "Compute the partial derivatives of difference operator.\n\n"
80
           "The difference operator (x1 [-] x0) is defined by diff(x0, x1). "
81
           "Instead Jdiff\n"
82
           "computes its partial derivatives, i.e. \\partial{diff(x0, x1)}{x0} "
83
           "and\n"
84
           "\\partial{diff(x0, x1)}{x1}. By default, this function returns the "
85
           "derivatives of the\n"
86
           "first and second argument (i.e. firstsecond='both'). However we "
87
           "can also specific the\n"
88
           "partial derivative for the first and second variables by setting "
89
           "firstsecond='first'\n"
90
           "or firstsecond='second', respectively.\n"
91
           ":param x0: previous state point (dim state.nx).\n"
92
           ":param x1: current state point (dim state.nx).\n"
93
           ":param firstsecond: derivative w.r.t x0 or x1 or both\n"
94

10
           ":return the partial derivative(s) of the diff(x0, x1) function")
95
      .def("Jintegrate", pure_virtual(&StateAbstract_wrap::Jintegrate_wrap),
96
20
           bp::args("self", "x", "dx", "firstsecond"),
97
           "Compute the partial derivatives of integrate operator.\n\n"
98
           "The integrate operator (x [+] dx) is defined by integrate(x, dx). "
99
           "Instead Jintegrate\n"
100
           "computes its partial derivatives, i.e. \\partial{integrate(x, "
101
           "dx)}{x} and\n"
102
           "\\partial{integrate(x, dx)}{dx}. By default, this function returns "
103
           "the derivatives of\n"
104
           "the first and second argument (i.e. firstsecond='both').\n"
105
           "partial derivative by setting firstsecond='first' or "
106
           "firstsecond='second'.\n"
107
           ":param x: state point (dim. state.nx).\n"
108
           ":param dx: velocity vector (dim state.ndx).\n"
109
           ":param firstsecond: derivative w.r.t x or dx or both\n"
110

10
           ":return the partial derivative(s) of the integrate(x, dx) function")
111
      .def("JintegrateTransport",
112
           pure_virtual(&StateAbstract_wrap::JintegrateTransport_wrap),
113
20
           bp::args("self", "x", "dx", "Jin", "firstsecond"),
114
           "Parallel transport from integrate(x, dx) to x.\n\n"
115
           "This function performs the parallel transportation of an input "
116
           "matrix whose columns\n"
117
           "are expressed in the tangent space at integrate(x, dx) to the "
118
           "tangent space at x point\n"
119
           ":param x: state point (dim. state.nx).\n"
120
           ":param dx: velocity vector (dim state.ndx).\n"
121
           ":param Jin: input matrix (number of rows = state.nv).\n"
122

10
           ":param firstsecond: derivative w.r.t x or dx")
123
10
      .add_property("nx", bp::make_function(&StateAbstract_wrap::get_nx),
124
20
                    bp::make_setter(&StateAbstract_wrap::nx_,
125
10
                                    bp::return_internal_reference<>()),
126
10
                    "dimension of state tuple")
127
10
      .add_property("ndx", bp::make_function(&StateAbstract_wrap::get_ndx),
128
20
                    bp::make_setter(&StateAbstract_wrap::ndx_,
129
10
                                    bp::return_internal_reference<>()),
130
10
                    "dimension of the tangent space of the state manifold")
131
10
      .add_property("nq", bp::make_function(&StateAbstract_wrap::get_nq),
132
20
                    bp::make_setter(&StateAbstract_wrap::nq_,
133
10
                                    bp::return_internal_reference<>()),
134
10
                    "dimension of the configuration tuple")
135
10
      .add_property("nv", bp::make_function(&StateAbstract_wrap::get_nv),
136
20
                    bp::make_setter(&StateAbstract_wrap::nv_,
137
10
                                    bp::return_internal_reference<>()),
138
10
                    "dimension of tangent space of the configuration manifold")
139
      .add_property("has_limits",
140
20
                    bp::make_function(&StateAbstract_wrap::get_has_limits),
141
10
                    "indicates whether problem has finite state limits")
142
      .add_property("lb",
143
                    bp::make_getter(&StateAbstract_wrap::lb_,
144
10
                                    bp::return_internal_reference<>()),
145

10
                    &StateAbstract_wrap::set_lb, "lower state limits")
146
      .add_property("ub",
147
10
                    bp::make_getter(&StateAbstract_wrap::ub_,
148
10
                                    bp::return_internal_reference<>()),
149

10
                    &StateAbstract_wrap::set_ub, "upper state limits");
150
10
}
151
152
}  // namespace python
153
}  // namespace crocoddyl