GCC Code Coverage Report


Directory: ./
File: python/quadruped_walkgen/action-base.cpp
Date: 2024-12-02 00:24:10
Exec Total Coverage
Lines: 0 75 0.0%
Branches: 0 116 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2018-2020, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "action-base.hpp"
10
11 #include "core.hpp"
12
13 namespace quadruped_walkgen {
14 namespace python {
15
16 void exposeActionAbstract() {
17 // bp::register_ptr_to_python<boost::shared_ptr<ActionModelAbstract> >();
18
19 bp::class_<ActionModelAbstract_wrap, boost::noncopyable>(
20 "ActionModelAbstract",
21 "Abstract class for action models.\n\n"
22 "In crocoddyl, an action model combines dynamics and cost data. Each "
23 "node, in our optimal\n"
24 "control problem, is described through an action model. Every time that "
25 "we want to describe\n"
26 "a problem, we need to provide ways of computing the dynamics, cost "
27 "functions and their\n"
28 "derivatives. These computations are mainly carry on inside calc() and "
29 "calcDiff(),\n"
30 "respectively.",
31 bp::init<boost::shared_ptr<StateAbstract>, int, bp::optional<int> >(
32 bp::args("self", "state", "nu", "nr"),
33 "Initialize the action model.\n\n"
34 "You can also describe autonomous systems by setting nu = 0.\n"
35 ":param state: state description,\n"
36 ":param nu: dimension of control vector,\n"
37 ":param nr: dimension of the cost-residual vector (default 1)"))
38 .def("calc", pure_virtual(&ActionModelAbstract_wrap::calc),
39 bp::args("self", "data", "x", "u"),
40 "Compute the next state and cost value.\n\n"
41 "It describes the time-discrete evolution of our dynamical system\n"
42 "in which we obtain the next state. Additionally it computes the\n"
43 "cost value associated to this discrete state and control pair.\n"
44 ":param data: action data\n"
45 ":param x: time-discrete state vector\n"
46 ":param u: time-discrete control input")
47 .def<void (ActionModelAbstract::*)(
48 const boost::shared_ptr<ActionDataAbstract>&,
49 const Eigen::Ref<const Eigen::VectorXd>&)>(
50 "calc", &ActionModelAbstract::calc, bp::args("self", "data", "x"))
51 .def("calcDiff", pure_virtual(&ActionModelAbstract_wrap::calcDiff),
52 bp::args("self", "data", "x", "u"),
53 "Compute the derivatives of the dynamics and cost functions.\n\n"
54 "It computes the partial derivatives of the dynamical system and "
55 "the\n"
56 "cost function. It assumes that calc has been run first.\n"
57 "This function builds a quadratic approximation of the\n"
58 "action model (i.e. linear dynamics and quadratic cost).\n"
59 ":param data: action data\n"
60 ":param x: time-discrete state vector\n"
61 ":param u: time-discrete control input\n")
62 .def<void (ActionModelAbstract::*)(
63 const boost::shared_ptr<ActionDataAbstract>&,
64 const Eigen::Ref<const Eigen::VectorXd>&)>(
65 "calcDiff", &ActionModelAbstract::calcDiff,
66 bp::args("self", "data", "x"))
67 .def("createData", &ActionModelAbstract_wrap::createData,
68 bp::args("self"),
69 "Create the action data.\n\n"
70 "Each action model (AM) has its own data that needs to be "
71 "allocated.\n"
72 "This function returns the allocated data for a predefined AM.\n"
73 ":return AM data.")
74 //.def("quasiStatic", &ActionModelAbstract_wrap::quasiStatic_x,
75 // ActionModel_quasiStatic_wraps(
76 // bp::args("self", "data", "x", "maxiter", "tol"),
77 // "Compute the quasic-static control given a state.\n\n"
78 // "It runs an iterative Newton step in order to compute the
79 // quasic-static regime\n"
80 // "given a state configuration.\n"
81 // ":param data: action data\n"
82 // ":param x: discrete-time state vector\n"
83 // ":param maxiter: maximum allowed number of iterations\n"
84 // ":param tol: stopping tolerance criteria (default 1e-9)\n"
85 // ":return u: quasic-static control"))
86 .add_property(
87 "nu",
88 bp::make_function(&ActionModelAbstract_wrap::get_nu,
89 bp::return_value_policy<bp::return_by_value>()),
90 "dimension of control vector")
91 .add_property(
92 "nr",
93 bp::make_function(&ActionModelAbstract_wrap::get_nr,
94 bp::return_value_policy<bp::return_by_value>()),
95 "dimension of cost-residual vector")
96 .add_property(
97 "state",
98 bp::make_function(&ActionModelAbstract_wrap::get_state,
99 bp::return_value_policy<bp::return_by_value>()),
100 "state")
101 .add_property(
102 "has_control_limits",
103 bp::make_function(&ActionModelAbstract_wrap::get_has_control_limits,
104 bp::return_value_policy<bp::return_by_value>()),
105 "indicates whether problem has finite control limits")
106 .add_property("u_lb",
107 bp::make_function(&ActionModelAbstract_wrap::get_u_lb,
108 bp::return_internal_reference<>()),
109 &ActionModelAbstract_wrap::set_u_lb, "lower control limits")
110 .add_property("u_ub",
111 bp::make_function(&ActionModelAbstract_wrap::get_u_ub,
112 bp::return_internal_reference<>()),
113 &ActionModelAbstract_wrap::set_u_ub,
114 "upper control limits");
115
116 // bp::register_ptr_to_python<boost::shared_ptr<ActionDataAbstract> >();
117
118 bp::class_<ActionDataAbstract, boost::noncopyable>(
119 "ActionDataAbstract",
120 "Abstract class for action data.\n\n"
121 "In crocoddyl, an action data contains all the required information for "
122 "processing an\n"
123 "user-defined action model. The action data typically is allocated onces "
124 "by running\n"
125 "model.createData() and contains the first- and second- order "
126 "derivatives of the dynamics\n"
127 "and cost function, respectively.",
128 bp::init<ActionModelAbstract*>(
129 bp::args("self", "model"),
130 "Create common data shared between AMs.\n\n"
131 "The action data uses the model in order to first process it.\n"
132 ":param model: action model"))
133 .add_property(
134 "cost",
135 bp::make_getter(&ActionDataAbstract::cost,
136 bp::return_value_policy<bp::return_by_value>()),
137 bp::make_setter(&ActionDataAbstract::cost), "cost value")
138 .add_property("xnext",
139 bp::make_getter(&ActionDataAbstract::xnext,
140 bp::return_internal_reference<>()),
141 bp::make_setter(&ActionDataAbstract::xnext), "next state")
142 .add_property("r",
143 bp::make_getter(&ActionDataAbstract::r,
144 bp::return_internal_reference<>()),
145 bp::make_setter(&ActionDataAbstract::r), "cost residual")
146 .add_property("Fx",
147 bp::make_getter(&ActionDataAbstract::Fx,
148 bp::return_internal_reference<>()),
149 bp::make_setter(&ActionDataAbstract::Fx),
150 "Jacobian of the dynamics")
151 .add_property("Fu",
152 bp::make_getter(&ActionDataAbstract::Fu,
153 bp::return_internal_reference<>()),
154 bp::make_setter(&ActionDataAbstract::Fu),
155 "Jacobian of the dynamics")
156 .add_property("Lx",
157 bp::make_getter(&ActionDataAbstract::Lx,
158 bp::return_internal_reference<>()),
159 bp::make_setter(&ActionDataAbstract::Lx),
160 "Jacobian of the cost")
161 .add_property("Lu",
162 bp::make_getter(&ActionDataAbstract::Lu,
163 bp::return_internal_reference<>()),
164 bp::make_setter(&ActionDataAbstract::Lu),
165 "Jacobian of the cost")
166 .add_property("Lxx",
167 bp::make_getter(&ActionDataAbstract::Lxx,
168 bp::return_internal_reference<>()),
169 bp::make_setter(&ActionDataAbstract::Lxx),
170 "Hessian of the cost")
171 .add_property("Lxu",
172 bp::make_getter(&ActionDataAbstract::Lxu,
173 bp::return_internal_reference<>()),
174 bp::make_setter(&ActionDataAbstract::Lxu),
175 "Hessian of the cost")
176 .add_property("Luu",
177 bp::make_getter(&ActionDataAbstract::Luu,
178 bp::return_internal_reference<>()),
179 bp::make_setter(&ActionDataAbstract::Luu),
180 "Hessian of the cost");
181 }
182
183 } // namespace python
184 } // namespace quadruped_walkgen
185