GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/residuals/centroidal-momentum.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 37 39 94.9%
Branches: 28 56 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/multibody/residuals/centroidal-momentum.hpp"
10
11 #include "python/crocoddyl/multibody/multibody.hpp"
12 #include "python/crocoddyl/utils/copyable.hpp"
13 #include "python/crocoddyl/utils/deprecate.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 10 void exposeResidualCentroidalMomentum() {
19 typedef Eigen::Matrix<double, 6, 1> Vector6d;
20
21 bp::register_ptr_to_python<
22 10 boost::shared_ptr<ResidualModelCentroidalMomentum> >();
23
24
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ResidualModelCentroidalMomentum,
25 bp::bases<ResidualModelAbstract> >(
26 "ResidualModelCentroidalMomentum",
27 "This residual function defines the centroidal momentum tracking as r = "
28 "h - href, with h and href as the\n"
29 "current and reference centroidal momenta, respectively.",
30
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateMultibody>, Vector6d, std::size_t>(
31 20 bp::args("self", "state", "href", "nu"),
32 "Initialize the centroidal momentum residual model.\n\n"
33 ":param state: state of the multibody system\n"
34 ":param href: reference centroidal momentum\n"
35 ":param nu: dimension of control vector"))
36
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<boost::shared_ptr<StateMultibody>, Vector6d>(
37
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state", "href"),
38 "Initialize the centroidal momentum residual model.\n\n"
39 "The default nu is obtained from state.nv.\n"
40 ":param state: state of the multibody system\n"
41 ":param href: reference centroidal momentum"))
42 .def<void (ResidualModelCentroidalMomentum::*)(
43 const boost::shared_ptr<ResidualDataAbstract>&,
44 const Eigen::Ref<const Eigen::VectorXd>&,
45
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
46 "calc", &ResidualModelCentroidalMomentum::calc,
47
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
48 "Compute the centroidal momentum residual.\n\n"
49 ":param data: residual data\n"
50 ":param x: state point (dim. state.nx)\n"
51 ":param u: control input (dim. nu)")
52 .def<void (ResidualModelCentroidalMomentum::*)(
53 const boost::shared_ptr<ResidualDataAbstract>&,
54 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
55
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x"))
56 .def<void (ResidualModelCentroidalMomentum::*)(
57 const boost::shared_ptr<ResidualDataAbstract>&,
58 const Eigen::Ref<const Eigen::VectorXd>&,
59
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 const Eigen::Ref<const Eigen::VectorXd>&)>(
60 "calcDiff", &ResidualModelCentroidalMomentum::calcDiff,
61
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
62 "Compute the Jacobians of the centroidal momentum residual.\n\n"
63 "It assumes that calc has been run first.\n"
64 ":param data: action data\n"
65 ":param x: state point (dim. state.nx)\n"
66 ":param u: control input (dim. nu)")
67 .def<void (ResidualModelCentroidalMomentum::*)(
68 const boost::shared_ptr<ResidualDataAbstract>&,
69 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
70 "calcDiff", &ResidualModelAbstract::calcDiff,
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
72
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData", &ResidualModelCentroidalMomentum::createData,
73 bp::with_custodian_and_ward_postcall<0, 2>(),
74
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
75 "Create the centroidal momentum residual data.\n\n"
76 "Each residual model has its own data that needs to be allocated. "
77 "This function\n"
78 "returns the allocated data for the centroidal momentum residual.\n"
79 ":param data: shared data\n"
80 ":return residual data.")
81
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
82 "reference",
83
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ResidualModelCentroidalMomentum::get_reference,
84 10 bp::return_internal_reference<>()),
85 &ResidualModelCentroidalMomentum::set_reference,
86 "reference centroidal momentum")
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ResidualModelCentroidalMomentum>());
88
89 bp::register_ptr_to_python<
90 10 boost::shared_ptr<ResidualDataCentroidalMomentum> >();
91
92
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ResidualDataCentroidalMomentum, bp::bases<ResidualDataAbstract> >(
93 "ResidualDataCentroidalMomentum",
94 "Data for centroidal momentum residual.\n\n",
95
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<ResidualModelCentroidalMomentum*, DataCollectorAbstract*>(
96 10 bp::args("self", "model", "data"),
97 "Create centroidal momentum residual data.\n\n"
98 ":param model: centroidal momentum residual model\n"
99 ":param data: shared data")[bp::with_custodian_and_ward<
100
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 1, 2, bp::with_custodian_and_ward<1, 3> >()])
101
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("pinocchio",
102
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataCentroidalMomentum::pinocchio,
103 10 bp::return_internal_reference<>()),
104 "pinocchio data")
105
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dhd_dq",
106
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataCentroidalMomentum::dhd_dq,
107 10 bp::return_internal_reference<>()),
108 "Jacobian of the centroidal momentum")
109
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dhd_dv",
110
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataCentroidalMomentum::dhd_dv,
111 10 bp::return_internal_reference<>()),
112 "Jacobian of the centroidal momentum")
113
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ResidualDataCentroidalMomentum>());
114 10 }
115
116 } // namespace python
117 } // namespace crocoddyl
118