GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/residuals/state-float.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 14 0.0%
Branches: 0 52 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2025, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // Auto-generated file for float
10 #include "crocoddyl/multibody/residuals/state.hpp"
11
12 #include "python/crocoddyl/multibody/multibody.hpp"
13
14 namespace crocoddyl {
15 namespace python {
16
17 template <typename Model>
18 struct ResidualModelStateVisitor
19 : public bp::def_visitor<ResidualModelStateVisitor<Model>> {
20 typedef typename Model::ResidualDataAbstract Data;
21 typedef typename Model::Base ModelBase;
22 typedef typename Model::StateAbstract State;
23 typedef typename Model::VectorXs VectorXs;
24 template <class PyClass>
25 void visit(PyClass& cl) const {
26 cl.def(bp::init<std::shared_ptr<State>, VectorXs>(
27 bp::args("self", "state", "xref"),
28 "Initialize the state cost model.\n\n"
29 "The default nu value is obtained from state.nv.\n"
30 ":param state: state description\n"
31 ":param xref: reference state"))
32 .def(bp::init<std::shared_ptr<State>, std::size_t>(
33 bp::args("self", "state", "nu"),
34 "Initialize the state cost model.\n\n"
35 "The default reference state is obtained from state.zero().\n"
36 ":param state: state description\n"
37 ":param nu: dimension of control vector"))
38 .def(bp::init<std::shared_ptr<State>>(
39 bp::args("self", "state"),
40 "Initialize the state cost model.\n\n"
41 "The default reference state is obtained from state.zero(), and nu "
42 "from state.nv.\n"
43 ":param state: state description"))
44 .def(
45 "calc",
46 static_cast<void (Model::*)(
47 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
48 const Eigen::Ref<const VectorXs>&)>(&Model::calc),
49 bp::args("self", "data", "x", "u"),
50 "Compute the state cost.\n\n"
51 ":param data: cost data\n"
52 ":param x: state point (dim. state.nx)\n"
53 ":param u: control input (dim. nu)")
54 .def(
55 "calc",
56 static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&,
57 const Eigen::Ref<const VectorXs>&)>(
58 &ModelBase::calc),
59 bp::args("self", "data", "x"))
60 .def(
61 "calcDiff",
62 static_cast<void (Model::*)(
63 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
64 const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff),
65 bp::args("self", "data", "x", "u"),
66 "Compute the derivatives of the state cost.\n\n"
67 "It assumes that calc has been run first.\n"
68 ":param data: action data\n"
69 ":param x: state point (dim. state.nx)\n"
70 ":param u: control input (dim. nu)")
71 .def(
72 "calcDiff",
73 static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&,
74 const Eigen::Ref<const VectorXs>&)>(
75 &ModelBase::calcDiff),
76 bp::args("self", "data", "x"))
77 .def("createData", &Model::createData,
78 bp::with_custodian_and_ward_postcall<0, 2>(),
79 bp::args("self", "data"),
80 "Create the stae residual data.\n\n"
81 "Each residual model has its own data that needs to be allocated. "
82 "This function\n"
83 "returns the allocated data for the control residual.\n"
84 ":param data: shared data\n"
85 ":return residual data.")
86 .add_property("reference",
87 bp::make_function(&Model::get_reference,
88 bp::return_internal_reference<>()),
89 &Model::set_reference, "reference state");
90 }
91 };
92
93 #define CROCODDYL_RESIDUAL_MODEL_STATE_PYTHON_BINDINGS(Scalar) \
94 typedef ResidualModelStateTpl<Scalar> Model; \
95 typedef ResidualModelAbstractTpl<Scalar> ModelBase; \
96 typedef typename ModelBase::StateAbstract State; \
97 typedef typename ModelBase::VectorXs VectorXs; \
98 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
99 bp::class_<Model, bp::bases<ModelBase>>( \
100 "ResidualModelState", \
101 "This cost function defines a residual vector as r = x - xref, with x " \
102 "and xref as the current and reference state, respectively.", \
103 bp::init<std::shared_ptr<State>, VectorXs, std::size_t>( \
104 bp::args("self", "state", "xref", "nu"), \
105 "Initialize the state cost model.\n\n" \
106 ":param state: state description\n" \
107 ":param xref: reference state (default state.zero())\n" \
108 ":param nu: dimension of control vector")) \
109 .def(ResidualModelStateVisitor<Model>()) \
110 .def(CastVisitor<Model>()) \
111 .def(PrintableVisitor<Model>()) \
112 .def(CopyableVisitor<Model>());
113
114 void exposeResidualState() {
115 CROCODDYL_RESIDUAL_MODEL_STATE_PYTHON_BINDINGS(float)
116 }
117
118 } // namespace python
119 } // namespace crocoddyl
120