GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/residuals/impulse-com.cpp
Date: 2025-01-30 11:01:55
Exec Total Coverage
Lines: 38 41 92.7%
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/impulse-com.hpp"
10
11 #include "python/crocoddyl/multibody/multibody.hpp"
12 #include "python/crocoddyl/utils/copyable.hpp"
13
14 namespace crocoddyl {
15 namespace python {
16
17 10 void exposeResidualImpulseCoM() {
18 10 bp::register_ptr_to_python<std::shared_ptr<ResidualModelImpulseCoM> >();
19
20
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ResidualModelImpulseCoM, bp::bases<ResidualModelAbstract> >(
21 "ResidualModelImpulseCoM",
22 "This residual function defines a residual vector as r = Jcom * "
23 "(vnext-v), with Jcom as the CoM Jacobian, and\n"
24 "vnext the velocity after impact and v the velocity before impact, "
25 "respectively.",
26
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<std::shared_ptr<StateMultibody> >(
27 20 bp::args("self", "state"),
28 "Initialize the CoM position cost model for impulse dynamics.\n\n"
29 "The default nu is obtained from state.nv.\n"
30 ":param state: state of the multibody system"))
31 .def<void (ResidualModelImpulseCoM::*)(
32 const std::shared_ptr<ResidualDataAbstract>&,
33 const Eigen::Ref<const Eigen::VectorXd>&,
34
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
35
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ResidualModelImpulseCoM::calc, bp::args("self", "data", "x"),
36 "Compute the CoM position residual.\n\n"
37 ":param data: residual data\n"
38 ":param x: state point (dim. state.nx)")
39 .def<void (ResidualModelImpulseCoM::*)(
40 const std::shared_ptr<ResidualDataAbstract>&,
41 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
42
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x"))
43 .def<void (ResidualModelImpulseCoM::*)(
44 const std::shared_ptr<ResidualDataAbstract>&,
45 const Eigen::Ref<const Eigen::VectorXd>&,
46
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>&)>(
47 "calcDiff", &ResidualModelImpulseCoM::calcDiff,
48
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"),
49 "Compute the derivatives of the CoM position residual for impulse "
50 "dynamics.\n\n"
51 "It assumes that calc has been run first.\n"
52 ":param data: action data\n"
53 ":param x: state point (dim. state.nx)")
54 .def<void (ResidualModelImpulseCoM::*)(
55 const std::shared_ptr<ResidualDataAbstract>&,
56 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
57 "calcDiff", &ResidualModelAbstract::calcDiff,
58
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
59
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData", &ResidualModelImpulseCoM::createData,
60 bp::with_custodian_and_ward_postcall<0, 2>(),
61
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
62 "Create the CoM position residual data.\n\n"
63 "Each residual model has its own data that needs to be allocated. "
64 "This function\n"
65 "returns the allocated data for the impulse CoM residual.\n"
66 ":param data: shared data\n"
67 ":return residual data.")
68
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ResidualModelImpulseCoM>());
69
70 10 bp::register_ptr_to_python<std::shared_ptr<ResidualDataImpulseCoM> >();
71
72
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ResidualDataImpulseCoM, bp::bases<ResidualDataAbstract> >(
73 "ResidualDataImpulseCoM", "Data for impulse CoM residual.\n\n",
74
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<ResidualModelImpulseCoM*, DataCollectorAbstract*>(
75 10 bp::args("self", "model", "data"),
76 "Create contact force residual data.\n\n"
77 ":param model: impulse CoM residual model\n"
78 ":param data: shared data")[bp::with_custodian_and_ward<
79
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 1, 2, bp::with_custodian_and_ward<1, 3> >()])
80
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("pinocchio",
81
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataImpulseCoM::pinocchio,
82 10 bp::return_internal_reference<>()),
83 "pinocchio data")
84
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
85 "impulses",
86
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataImpulseCoM::impulses,
87 bp::return_value_policy<bp::return_by_value>()),
88
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&ResidualDataImpulseCoM::impulses),
89 "impulses data associated with the current residual")
90
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dvc_dq",
91
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataImpulseCoM::dvc_dq,
92 10 bp::return_internal_reference<>()),
93 "Jacobian of the CoM velocity")
94
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ddv_dv",
95
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataImpulseCoM::ddv_dv,
96 10 bp::return_internal_reference<>()),
97 "Jacobian of the impulse velocity")
98
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("pinocchio_internal",
99
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ResidualDataImpulseCoM::pinocchio_internal,
100 10 bp::return_internal_reference<>()),
101 "internal pinocchio data used for extra computations")
102
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ResidualDataImpulseCoM>());
103 10 }
104
105 } // namespace python
106 } // namespace crocoddyl
107