GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/residuals/frame-rotation-double.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 25 0.0%
Branches: 0 72 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 double
10 #include "crocoddyl/multibody/residuals/frame-rotation.hpp"
11
12 #include "python/crocoddyl/multibody/multibody.hpp"
13
14 namespace crocoddyl {
15 namespace python {
16
17 template <typename Model>
18 struct ResidualModelFrameRotationVisitor
19 : public bp::def_visitor<ResidualModelFrameRotationVisitor<Model>> {
20 typedef typename Model::ResidualDataAbstract Data;
21 typedef typename Model::Base ModelBase;
22 typedef typename Model::StateMultibody State;
23 typedef typename Model::Matrix3s Matrix3s;
24 typedef typename Model::VectorXs VectorXs;
25 template <class PyClass>
26 void visit(PyClass& cl) const {
27 cl.def(bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Matrix3s>(
28 bp::args("self", "state", "id", "Rref"),
29 "Initialize the frame rotation residual model.\n\n"
30 "The default nu value is obtained from model.nv.\n"
31 ":param state: state of the multibody system\n"
32 ":param id: reference frame id\n"
33 ":param Rref: reference frame rotation"))
34 .def(
35 "calc",
36 static_cast<void (Model::*)(
37 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
38 const Eigen::Ref<const VectorXs>&)>(&Model::calc),
39 bp::args("self", "data", "x", "u"),
40 "Compute the frame rotation residual.\n\n"
41 ":param data: residual data\n"
42 ":param x: state point (dim. state.nx)\n"
43 ":param u: control input (dim. nu)")
44 .def(
45 "calc",
46 static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&,
47 const Eigen::Ref<const VectorXs>&)>(
48 &ModelBase::calc),
49 bp::args("self", "data", "x"))
50 .def(
51 "calcDiff",
52 static_cast<void (Model::*)(
53 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
54 const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff),
55 bp::args("self", "data", "x", "u"),
56 "Compute the Jacobians of the frame rotation residual.\n\n"
57 "It assumes that calc has been run first.\n"
58 ":param data: action data\n"
59 ":param x: state point (dim. state.nx)\n"
60 ":param u: control input (dim. nu)")
61 .def(
62 "calcDiff",
63 static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&,
64 const Eigen::Ref<const VectorXs>&)>(
65 &ModelBase::calcDiff),
66 bp::args("self", "data", "x"))
67 .def("createData", &Model::createData,
68 bp::with_custodian_and_ward_postcall<0, 2>(),
69 bp::args("self", "data"),
70 "Create the frame rotation residual data.\n\n"
71 "Each residual model has its own data that needs to be allocated. "
72 "This function\n"
73 "returns the allocated data for the frame rotation residual.\n"
74 ":param data: shared data\n"
75 ":return residual data.")
76 .add_property("id", &Model::get_id, &Model::set_id,
77 "reference frame id")
78 .add_property("reference",
79 bp::make_function(
80 &Model::get_reference,
81 bp::return_value_policy<bp::copy_const_reference>()),
82 &Model::set_reference, "reference frame rotation");
83 }
84 };
85
86 template <typename Data>
87 struct ResidualDataFrameRotationVisitor
88 : public bp::def_visitor<ResidualDataFrameRotationVisitor<Data>> {
89 template <class PyClass>
90 void visit(PyClass& cl) const {
91 cl.add_property(
92 "pinocchio",
93 bp::make_getter(&Data::pinocchio, bp::return_internal_reference<>()),
94 "pinocchio data")
95 .add_property(
96 "r", bp::make_getter(&Data::r, bp::return_internal_reference<>()),
97 "residual residual")
98 .add_property(
99 "rRf",
100 bp::make_getter(&Data::rRf, bp::return_internal_reference<>()),
101 "rotation error of the frame")
102 .add_property(
103 "rJf",
104 bp::make_getter(&Data::rJf, bp::return_internal_reference<>()),
105 "error Jacobian of the frame")
106 .add_property(
107 "fJf",
108 bp::make_getter(&Data::fJf, bp::return_internal_reference<>()),
109 "local Jacobian of the frame");
110 }
111 };
112
113 #define CROCODDYL_RESIDUAL_MODEL_FRAME_ROTATION_PYTHON_BINDINGS(Scalar) \
114 typedef ResidualModelFrameRotationTpl<Scalar> Model; \
115 typedef ResidualModelAbstractTpl<Scalar> ModelBase; \
116 typedef typename Model::StateMultibody State; \
117 typedef typename Model::Matrix3s Matrix3s; \
118 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
119 bp::class_<Model, bp::bases<ModelBase>>( \
120 "ResidualModelFrameRotation", \
121 "This residual function is defined as r = R - Rref, with R and Rref as " \
122 "the current and reference frame rotations, respectively.", \
123 bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Matrix3s, \
124 std::size_t>( \
125 bp::args("self", "state", "id", "Rref", "nu"), \
126 "Initialize the frame rotation residual model.\n\n" \
127 ":param state: state of the multibody system\n" \
128 ":param id: reference frame id\n" \
129 ":param Rref: reference frame rotation\n" \
130 ":param nu: dimension of control vector")) \
131 .def(ResidualModelFrameRotationVisitor<Model>()) \
132 .def(CastVisitor<Model>()) \
133 .def(PrintableVisitor<Model>()) \
134 .def(CopyableVisitor<Model>());
135
136 #define CROCODDYL_RESIDUAL_DATA_FRAME_ROTATION_PYTHON_BINDINGS(Scalar) \
137 typedef ResidualDataFrameRotationTpl<Scalar> Data; \
138 typedef ResidualDataAbstractTpl<Scalar> DataBase; \
139 typedef ResidualModelFrameRotationTpl<Scalar> Model; \
140 typedef Model::DataCollectorAbstract DataCollector; \
141 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
142 bp::class_<Data, bp::bases<DataBase>>( \
143 "ResidualDataFrameRotation", "Data for frame rotation residual.\n\n", \
144 bp::init<Model*, DataCollector*>( \
145 bp::args("self", "model", "data"), \
146 "Create frame rotation residual data.\n\n" \
147 ":param model: frame rotation residual model\n" \
148 ":param data: shared data")[bp::with_custodian_and_ward< \
149 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
150 .def(ResidualDataFrameRotationVisitor<Data>()) \
151 .def(CopyableVisitor<Data>());
152
153 void exposeResidualFrameRotation() {
154 CROCODDYL_RESIDUAL_MODEL_FRAME_ROTATION_PYTHON_BINDINGS(double)
155 CROCODDYL_RESIDUAL_DATA_FRAME_ROTATION_PYTHON_BINDINGS(double)
156 }
157
158 } // namespace python
159 } // namespace crocoddyl
160