GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/multibody/impulse-base.cpp Lines: 52 56 92.9 %
Date: 2024-02-13 11:12:33 Branches: 50 100 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
5
//                          Heriot-Watt University
6
// Copyright note valid unless otherwise stated in individual files.
7
// All rights reserved.
8
///////////////////////////////////////////////////////////////////////////////
9
10
#include "python/crocoddyl/multibody/impulse-base.hpp"
11
12
#include "python/crocoddyl/multibody/multibody.hpp"
13
#include "python/crocoddyl/utils/copyable.hpp"
14
#include "python/crocoddyl/utils/deprecate.hpp"
15
#include "python/crocoddyl/utils/printable.hpp"
16
17
namespace crocoddyl {
18
namespace python {
19
20
10
void exposeImpulseAbstract() {
21
10
  bp::register_ptr_to_python<boost::shared_ptr<ImpulseModelAbstract> >();
22
23
10
  bp::class_<ImpulseModelAbstract_wrap, boost::noncopyable>(
24
      "ImpulseModelAbstract",
25
      "Abstract impulse model.\n\n"
26
      "It defines a template for impulse models.\n"
27
      "The calc and calcDiff functions compute the impulse Jacobian\n"
28
      "the derivatives respectively.",
29
10
      bp::init<boost::shared_ptr<StateMultibody>, pinocchio::ReferenceFrame,
30
20
               std::size_t>(bp::args("self", "state", "type", "nc"),
31
                            "Initialize the impulse model.\n\n"
32
                            ":param state: state of the multibody system\n"
33
                            ":param type: type of impulse\n"
34
                            ":param nc: dimension of impulse model"))
35
10
      .def(bp::init<boost::shared_ptr<StateMultibody>, std::size_t>(
36
20
          bp::args("self", "state", "nc"),
37
          "Initialize the impulse model.\n\n"
38
          ":param state: state of the multibody system\n"
39
10
          ":param nc: dimension of impulse model"))
40
      .def("calc", pure_virtual(&ImpulseModelAbstract_wrap::calc),
41
20
           bp::args("self", "data", "x"),
42
           "Compute the impulse Jacobian\n"
43
           ":param data: impulse data\n"
44

10
           ":param x: state point (dim. state.nx)")
45
      .def("calcDiff", pure_virtual(&ImpulseModelAbstract_wrap::calcDiff),
46
20
           bp::args("self", "data", "x"),
47
           "Compute the derivatives of impulse Jacobian\n"
48
           "It assumes that calc has been run first.\n"
49
           ":param data: impulse data\n"
50

10
           ":param x: state point (dim. state.nx)")
51
      .def("updateForce", pure_virtual(&ImpulseModelAbstract_wrap::updateForce),
52
20
           bp::args("self", "data", "force"),
53
           "Convert the force into a stack of spatial forces.\n\n"
54
           ":param data: impulse data\n"
55

10
           ":param force: force vector (dimension nc)")
56
      .def("updateForceDiff", &ImpulseModelAbstract_wrap::updateForceDiff,
57
20
           bp::args("self", "data", "df_dx"),
58
           "Update the Jacobian of the impulse force.\n\n"
59
           ":param data: impulse data\n"
60
10
           ":param df_dx: Jacobian of the impulse force (dimension nc*ndx)")
61
      .def("setZeroForce", &ImpulseModelAbstract_wrap::setZeroForce,
62
20
           bp::args("self", "data"),
63
           "Set zero the spatial force.\n\n"
64
10
           ":param data: contact data")
65
      .def("setZeroForceDiff", &ImpulseModelAbstract_wrap::setZeroForceDiff,
66
20
           bp::args("self", "data"),
67
           "Set zero the derivatives of the spatial force.\n\n"
68
10
           ":param data: contact data")
69
      .def("createData", &ImpulseModelAbstract_wrap::createData,
70
           bp::with_custodian_and_ward_postcall<0, 2>(),
71
20
           bp::args("self", "data"),
72
           "Create the impulse data.\n\n"
73
           "Each impulse model has its own data that needs to be allocated. "
74
           "This function\n"
75
           "returns the allocated data for a predefined impulse.\n"
76
           ":param data: Pinocchio data\n"
77
10
           ":return impulse data.")
78
      .def("createData", &ImpulseModelAbstract_wrap::default_createData,
79
10
           bp::with_custodian_and_ward_postcall<0, 2>())
80
      .add_property(
81
          "state",
82
10
          bp::make_function(&ImpulseModelAbstract_wrap::get_state,
83
10
                            bp::return_value_policy<bp::return_by_value>()),
84
10
          "state of the multibody system")
85
      .add_property("ni",
86
10
                    bp::make_function(&ImpulseModelAbstract_wrap::get_nc,
87

20
                                      deprecated<>("Deprecated. Use nc")),
88
10
                    "dimension of impulse")
89
20
      .add_property("nc", bp::make_function(&ImpulseModelAbstract_wrap::get_nc),
90
10
                    "dimension of impulse")
91
      .add_property("id", &ImpulseModelAbstract_wrap::get_id,
92
10
                    &ImpulseModelAbstract_wrap::set_id, "reference frame id")
93
      .add_property("type",
94
10
                    bp::make_function(&ImpulseModelAbstract_wrap::get_type),
95

10
                    &ImpulseModelAbstract_wrap::set_type, "type of impulse")
96
10
      .def(CopyableVisitor<ImpulseModelAbstract_wrap>())
97
10
      .def(PrintableVisitor<ImpulseModelAbstract>());
98
99
10
  bp::register_ptr_to_python<boost::shared_ptr<ImpulseDataAbstract> >();
100
101
10
  bp::class_<ImpulseDataAbstract, bp::bases<ForceDataAbstract> >(
102
      "ImpulseDataAbstract", "Abstract class for impulse data.\n\n",
103
10
      bp::init<ImpulseModelAbstract*, pinocchio::Data*>(
104
10
          bp::args("self", "model", "data"),
105
          "Create common data shared between impulse models.\n\n"
106
          ":param model: impulse model\n"
107
20
          ":param data: Pinocchio data")[bp::with_custodian_and_ward<1, 3>()])
108
      .add_property("fXj",
109
10
                    bp::make_getter(&ImpulseDataAbstract::fXj,
110
                                    bp::return_internal_reference<>()),
111
20
                    bp::make_setter(&ImpulseDataAbstract::fXj),
112
10
                    "action matrix from contact to local frames")
113
      .add_property("dv0_dq",
114
10
                    bp::make_getter(&ImpulseDataAbstract::dv0_dq,
115
                                    bp::return_internal_reference<>()),
116
20
                    bp::make_setter(&ImpulseDataAbstract::dv0_dq),
117
10
                    "Jacobian of the previous impulse velocity")
118
      .add_property("dtau_dq",
119
10
                    bp::make_getter(&ImpulseDataAbstract::dtau_dq,
120
                                    bp::return_internal_reference<>()),
121
20
                    bp::make_setter(&ImpulseDataAbstract::dtau_dq),
122
10
                    "force contribution to dtau_dq")
123
10
      .def(CopyableVisitor<ImpulseDataAbstract>());
124
10
}
125
126
}  // namespace python
127
}  // namespace crocoddyl