GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/multibody/actions/impulse-fwddyn.cpp Lines: 62 63 98.4 %
Date: 2024-02-13 11:12:33 Branches: 48 96 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
5
//                          University of Oxford, Heriot-Watt University
6
// Copyright note valid unless otherwise stated in individual files.
7
// All rights reserved.
8
///////////////////////////////////////////////////////////////////////////////
9
10
#include "crocoddyl/multibody/actions/impulse-fwddyn.hpp"
11
12
#include "python/crocoddyl/core/action-base.hpp"
13
#include "python/crocoddyl/multibody/multibody.hpp"
14
#include "python/crocoddyl/utils/copyable.hpp"
15
16
namespace crocoddyl {
17
namespace python {
18
19
10
void exposeActionImpulseFwdDynamics() {
20
  bp::register_ptr_to_python<
21
10
      boost::shared_ptr<ActionModelImpulseFwdDynamics> >();
22
23
10
  bp::class_<ActionModelImpulseFwdDynamics, bp::bases<ActionModelAbstract> >(
24
      "ActionModelImpulseFwdDynamics",
25
      "Action model for impulse forward dynamics in multibody systems.\n\n"
26
      "The impulse is modelled as holonomic constraits in the contact frame. "
27
      "There\n"
28
      "is also a custom implementation in case of system with armatures. If "
29
      "you want to\n"
30
      "include the armature, you need to use set_armature(). On the other "
31
      "hand, the\n"
32
      "stack of cost functions are implemented in CostModelSum().",
33
10
      bp::init<boost::shared_ptr<StateMultibody>,
34
               boost::shared_ptr<ImpulseModelMultiple>,
35
               boost::shared_ptr<CostModelSum>,
36
               bp::optional<double, double, bool> >(
37
20
          bp::args("self", "state", " impulses", "costs", "r_coeff",
38
                   "inv_damping", "enable_force"),
39
          "Initialize the impulse forward-dynamics action model.\n\n"
40
          "The damping factor is needed when the contact Jacobian is not "
41
          "full-rank. Otherwise,\n"
42
          "a good damping factor could be 1e-12. In addition, if you have cost "
43
          "based on forces,\n"
44
          "you need to enable the computation of the force Jacobians (i.e. "
45
          "enable_force=True)."
46
          ":param state: multibody state\n"
47
          ":param impulses: multiple impulse model\n"
48
          ":param costs: stack of cost functions\n"
49
          ":param r_coeff: restitution coefficient (default 0.)\n"
50
          ":param inv_damping: Damping factor for cholesky decomposition of "
51
          "JMinvJt (default 0.)\n"
52
          ":param enable_force: Enable the computation of force Jacobians "
53
          "(default False)"))
54
10
      .def(bp::init<boost::shared_ptr<StateMultibody>,
55
                    boost::shared_ptr<ImpulseModelMultiple>,
56
                    boost::shared_ptr<CostModelSum>,
57
                    boost::shared_ptr<ConstraintModelManager>,
58
                    bp::optional<double, double, bool> >(
59
20
          bp::args("self", "state", "impulses", "costs", "constraints",
60
                   "r_coeff", "inv_damping", "enable_force"),
61
          "Initialize the constrained forward-dynamics action model.\n\n"
62
          "The damping factor is needed when the contact Jacobian is not "
63
          "full-rank. Otherwise,\n"
64
          "a good damping factor could be 1e-12. In addition, if you have cost "
65
          "based on forces,\n"
66
          "you need to enable the computation of the force Jacobians (i.e. "
67
          "enable_force=True)."
68
          ":param state: multibody state\n"
69
          ":param impulses: multiple impulse model\n"
70
          ":param costs: stack of cost functions\n"
71
          ":param constraints: stack of constraint functions\n"
72
          ":param r_coeff: restitution coefficient (default 0.)\n"
73
          ":param inv_damping: Damping factor for cholesky decomposition of "
74
          "JMinvJt (default 0.)\n"
75
          ":param enable_force: Enable the computation of force Jacobians "
76
10
          "(default False)"))
77
      .def<void (ActionModelImpulseFwdDynamics::*)(
78
          const boost::shared_ptr<ActionDataAbstract>&,
79
          const Eigen::Ref<const Eigen::VectorXd>&,
80
          const Eigen::Ref<const Eigen::VectorXd>&)>(
81
          "calc", &ActionModelImpulseFwdDynamics::calc,
82
20
          bp::args("self", "data", "x", "u"),
83
          "Compute the next state and cost value.\n\n"
84
          "It describes the time-continuous evolution of the multibody system "
85
          "with impulse. The\n"
86
          "impulses are modelled as holonomic constraints.\n"
87
          "Additionally it computes the cost value associated to this state "
88
          "and control pair.\n"
89
          ":param data: impulse forward-dynamics action data\n"
90
          ":param x: time-continuous state vector\n"
91
20
          ":param u: time-continuous control input")
92
      .def<void (ActionModelImpulseFwdDynamics::*)(
93
          const boost::shared_ptr<ActionDataAbstract>&,
94
          const Eigen::Ref<const Eigen::VectorXd>&)>(
95

20
          "calc", &ActionModelAbstract::calc, bp::args("self", "data", "x"))
96
      .def<void (ActionModelImpulseFwdDynamics::*)(
97
          const boost::shared_ptr<ActionDataAbstract>&,
98
          const Eigen::Ref<const Eigen::VectorXd>&,
99
          const Eigen::Ref<const Eigen::VectorXd>&)>(
100
          "calcDiff", &ActionModelImpulseFwdDynamics::calcDiff,
101
20
          bp::args("self", "data", "x", "u"),
102
          "Compute the derivatives of the differential multibody system and "
103
          "its cost\n"
104
          "functions.\n\n"
105
          "It computes the partial derivatives of the differential multibody "
106
          "system and the\n"
107
          "cost function. It assumes that calc has been run first.\n"
108
          "This function builds a quadratic approximation of the\n"
109
          "action model (i.e. dynamical system and cost function).\n"
110
          ":param data: impulse forward-dynamics action data\n"
111
          ":param x: time-continuous state vector\n"
112
          ":param u: time-continuous control input\n"
113
10
          "")
114
      .def<void (ActionModelImpulseFwdDynamics::*)(
115
          const boost::shared_ptr<ActionDataAbstract>&,
116
          const Eigen::Ref<const Eigen::VectorXd>&)>(
117
          "calcDiff", &ActionModelAbstract::calcDiff,
118

20
          bp::args("self", "data", "x"))
119
      .def("createData", &ActionModelImpulseFwdDynamics::createData,
120
20
           bp::args("self"),
121

20
           "Create the impulse forward dynamics differential action data.")
122
      .add_property(
123
          "pinocchio",
124
10
          bp::make_function(&ActionModelImpulseFwdDynamics::get_pinocchio,
125
10
                            bp::return_internal_reference<>()),
126
10
          "multibody model (i.e. pinocchio model)")
127
      .add_property(
128
          "impulses",
129
10
          bp::make_function(&ActionModelImpulseFwdDynamics::get_impulses,
130
10
                            bp::return_value_policy<bp::return_by_value>()),
131
10
          "multiple contact model")
132
      .add_property(
133
          "costs",
134
10
          bp::make_function(&ActionModelImpulseFwdDynamics::get_costs,
135
10
                            bp::return_value_policy<bp::return_by_value>()),
136
10
          "total cost model")
137
      .add_property(
138
          "constraints",
139
10
          bp::make_function(&ActionModelImpulseFwdDynamics::get_constraints,
140
10
                            bp::return_value_policy<bp::return_by_value>()),
141
10
          "constraint model manager")
142
      .add_property(
143
          "armature",
144
10
          bp::make_function(&ActionModelImpulseFwdDynamics::get_armature,
145
                            bp::return_internal_reference<>()),
146
20
          bp::make_function(&ActionModelImpulseFwdDynamics::set_armature),
147
10
          "set an armature mechanism in the joints")
148
      .add_property(
149
          "r_coeff",
150
10
          bp::make_function(
151
              &ActionModelImpulseFwdDynamics::get_restitution_coefficient),
152
20
          bp::make_function(
153
              &ActionModelImpulseFwdDynamics::set_restitution_coefficient),
154
10
          "Restitution coefficient that describes elastic impacts")
155
      .add_property(
156
          "JMinvJt_damping",
157
10
          bp::make_function(&ActionModelImpulseFwdDynamics::get_damping_factor),
158
20
          bp::make_function(&ActionModelImpulseFwdDynamics::set_damping_factor),
159
10
          "Damping factor for cholesky decomposition of JMinvJt")
160
10
      .def(CopyableVisitor<ActionModelImpulseFwdDynamics>());
161
162
  bp::register_ptr_to_python<
163
10
      boost::shared_ptr<ActionDataImpulseFwdDynamics> >();
164
165
10
  bp::class_<ActionDataImpulseFwdDynamics, bp::bases<ActionDataAbstract> >(
166
      "ActionDataImpulseFwdDynamics",
167
      "Action data for the impulse forward dynamics system.",
168
10
      bp::init<ActionModelImpulseFwdDynamics*>(
169
20
          bp::args("self", "model"),
170
          "Create impulse forward-dynamics action data.\n\n"
171
          ":param model: impulse forward-dynamics action model"))
172
      .add_property("pinocchio",
173
10
                    bp::make_getter(&ActionDataImpulseFwdDynamics::pinocchio,
174
10
                                    bp::return_internal_reference<>()),
175
10
                    "pinocchio data")
176
      .add_property("multibody",
177
10
                    bp::make_getter(&ActionDataImpulseFwdDynamics::multibody,
178
10
                                    bp::return_internal_reference<>()),
179
10
                    "multibody data")
180
      .add_property(
181
          "costs",
182
10
          bp::make_getter(&ActionDataImpulseFwdDynamics::costs,
183
10
                          bp::return_value_policy<bp::return_by_value>()),
184
10
          "total cost data")
185
      .add_property(
186
          "constraints",
187
10
          bp::make_getter(&ActionDataImpulseFwdDynamics::constraints,
188
10
                          bp::return_value_policy<bp::return_by_value>()),
189
10
          "constraint data")
190
      .add_property("Kinv",
191
10
                    bp::make_getter(&ActionDataImpulseFwdDynamics::Kinv,
192
10
                                    bp::return_internal_reference<>()),
193
10
                    "inverse of the KKT matrix")
194
      .add_property("df_dx",
195
10
                    bp::make_getter(&ActionDataImpulseFwdDynamics::df_dx,
196
10
                                    bp::return_internal_reference<>()),
197
10
                    "Jacobian of the contact impulse")
198
10
      .def(CopyableVisitor<ActionDataImpulseFwdDynamics>());
199
10
}
200
201
}  // namespace python
202
}  // namespace crocoddyl