GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/multibody/residuals/impulse-com.cpp Lines: 37 39 94.9 %
Date: 2024-02-13 11:12:33 Branches: 29 58 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<boost::shared_ptr<ResidualModelImpulseCoM> >();
19
20
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
10
      bp::init<boost::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 boost::shared_ptr<ResidualDataAbstract>&,
33
          const Eigen::Ref<const Eigen::VectorXd>&,
34
          const Eigen::Ref<const Eigen::VectorXd>&)>(
35
20
          "calc", &ResidualModelImpulseCoM::calc, bp::args("self", "data", "x"),
36
          "Compute the CoM position residual.\n\n"
37
          ":param data: residual data\n"
38
10
          ":param x: state point (dim. state.nx)")
39
      .def<void (ResidualModelImpulseCoM::*)(
40
          const boost::shared_ptr<ResidualDataAbstract>&,
41
          const Eigen::Ref<const Eigen::VectorXd>&)>(
42
20
          "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x"))
43
      .def<void (ResidualModelImpulseCoM::*)(
44
          const boost::shared_ptr<ResidualDataAbstract>&,
45
          const Eigen::Ref<const Eigen::VectorXd>&,
46
          const Eigen::Ref<const Eigen::VectorXd>&)>(
47
          "calcDiff", &ResidualModelImpulseCoM::calcDiff,
48
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

20
          ":param x: state point (dim. state.nx)")
54
      .def<void (ResidualModelImpulseCoM::*)(
55
          const boost::shared_ptr<ResidualDataAbstract>&,
56
          const Eigen::Ref<const Eigen::VectorXd>&)>(
57
          "calcDiff", &ResidualModelAbstract::calcDiff,
58
20
          bp::args("self", "data", "x"))
59
      .def("createData", &ResidualModelImpulseCoM::createData,
60
           bp::with_custodian_and_ward_postcall<0, 2>(),
61
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

20
           ":return residual data.")
68
10
      .def(CopyableVisitor<ResidualModelImpulseCoM>());
69
70
10
  bp::register_ptr_to_python<boost::shared_ptr<ResidualDataImpulseCoM> >();
71
72
10
  bp::class_<ResidualDataImpulseCoM, bp::bases<ResidualDataAbstract> >(
73
      "ResidualDataImpulseCoM", "Data for impulse CoM residual.\n\n",
74
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
10
          ":param data: shared data")[bp::with_custodian_and_ward<
79
20
          1, 2, bp::with_custodian_and_ward<1, 3> >()])
80
      .add_property("pinocchio",
81
10
                    bp::make_getter(&ResidualDataImpulseCoM::pinocchio,
82
10
                                    bp::return_internal_reference<>()),
83
10
                    "pinocchio data")
84
      .add_property(
85
          "impulses",
86
10
          bp::make_getter(&ResidualDataImpulseCoM::impulses,
87
                          bp::return_value_policy<bp::return_by_value>()),
88
20
          bp::make_setter(&ResidualDataImpulseCoM::impulses),
89
10
          "impulses data associated with the current residual")
90
      .add_property("dvc_dq",
91
10
                    bp::make_getter(&ResidualDataImpulseCoM::dvc_dq,
92
10
                                    bp::return_internal_reference<>()),
93
10
                    "Jacobian of the CoM velocity")
94
      .add_property("ddv_dv",
95
10
                    bp::make_getter(&ResidualDataImpulseCoM::ddv_dv,
96
10
                                    bp::return_internal_reference<>()),
97
10
                    "Jacobian of the impulse velocity")
98
      .add_property("pinocchio_internal",
99
10
                    bp::make_getter(&ResidualDataImpulseCoM::pinocchio_internal,
100
10
                                    bp::return_internal_reference<>()),
101
10
                    "internal pinocchio data used for extra computations")
102
10
      .def(CopyableVisitor<ResidualDataImpulseCoM>());
103
10
}
104
105
}  // namespace python
106
}  // namespace crocoddyl