GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/residuals/joint-acceleration.cpp Lines: 26 28 92.9 %
Date: 2024-02-13 11:12:33 Branches: 24 48 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2022-2023, Heriot-Watt University
5
// Copyright note valid unless otherwise stated in individual files.
6
// All rights reserved.
7
///////////////////////////////////////////////////////////////////////////////
8
9
#include "crocoddyl/core/residuals/joint-acceleration.hpp"
10
11
#include "python/crocoddyl/core/core.hpp"
12
#include "python/crocoddyl/utils/copyable.hpp"
13
14
namespace crocoddyl {
15
namespace python {
16
17
10
void exposeResidualJointAcceleration() {
18
  bp::register_ptr_to_python<
19
10
      boost::shared_ptr<ResidualModelJointAcceleration>>();
20
21
10
  bp::class_<ResidualModelJointAcceleration, bp::bases<ResidualModelAbstract>>(
22
      "ResidualModelJointAcceleration",
23
      "This residual function defines a residual vector as r = a - aref, with "
24
      "a and aref as the current and\n"
25
      "reference joint acceleration (i.e., generalized acceleration), "
26
      "respectively.",
27
10
      bp::init<boost::shared_ptr<StateAbstract>, Eigen::VectorXd, std::size_t>(
28
20
          bp::args("self", "state", "aref", "nu"),
29
          "Initialize the joint-acceleration residual model.\n\n"
30
          ":param state: state description\n"
31
          ":param aref: reference joint acceleration\n"
32
          ":param nu: dimension of the control vector"))
33
10
      .def(bp::init<boost::shared_ptr<StateAbstract>, Eigen::VectorXd>(
34
20
          bp::args("self", "state", "aref"),
35
          "Initialize the joint-acceleration residual model.\n\n"
36
          "The default nu value is obtained from state.nv.\n"
37
          ":param state: state description\n"
38
10
          ":param aref: reference joint acceleration"))
39
10
      .def(bp::init<boost::shared_ptr<StateAbstract>, std::size_t>(
40
20
          bp::args("self", "state", "nu"),
41
          "Initialize the joint-acceleration residual model.\n\n"
42
          "The default reference joint-acceleration is obtained from "
43
          "np.zero(actuation.nu).\n"
44
          ":param state: state description\n"
45
10
          ":param nu: dimension of the control vector"))
46
10
      .def(bp::init<boost::shared_ptr<StateAbstract>>(
47
20
          bp::args("self", "state"),
48
          "Initialize the joint-acceleration residual model.\n\n"
49
          "The default reference joint-acceleration is obtained from "
50
          "np.zero(actuation.nu).\n"
51
          "The default nu value is obtained from state.nv.\n"
52
10
          ":param state: state description"))
53
      .def<void (ResidualModelJointAcceleration::*)(
54
          const boost::shared_ptr<ResidualDataAbstract>&,
55
          const Eigen::Ref<const Eigen::VectorXd>&,
56
          const Eigen::Ref<const Eigen::VectorXd>&)>(
57
          "calc", &ResidualModelJointAcceleration::calc,
58
20
          bp::args("self", "data", "x", "u"),
59
          "Compute the joint-acceleration residual.\n\n"
60
          ":param data: residual data\n"
61
          ":param x: state point (dim. state.nx)\n"
62
20
          ":param u: control input (dim. nu)")
63
      .def<void (ResidualModelJointAcceleration::*)(
64
          const boost::shared_ptr<ResidualDataAbstract>&,
65
          const Eigen::Ref<const Eigen::VectorXd>&)>(
66

20
          "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x"))
67
      .def<void (ResidualModelJointAcceleration::*)(
68
          const boost::shared_ptr<ResidualDataAbstract>&,
69
          const Eigen::Ref<const Eigen::VectorXd>&,
70
          const Eigen::Ref<const Eigen::VectorXd>&)>(
71
          "calcDiff", &ResidualModelJointAcceleration::calcDiff,
72
20
          bp::args("self", "data", "x", "u"),
73
          "Compute the Jacobians of the joint-acceleration residual.\n\n"
74
          "It assumes that calc has been run first.\n"
75
          ":param data: residual data\n"
76
          ":param x: state point (dim. state.nx)\n"
77

20
          ":param u: control input (dim. nu)")
78
      .def<void (ResidualModelJointAcceleration::*)(
79
          const boost::shared_ptr<ResidualDataAbstract>&,
80
          const Eigen::Ref<const Eigen::VectorXd>&)>(
81
          "calcDiff", &ResidualModelAbstract::calcDiff,
82
20
          bp::args("self", "data", "x"))
83
      .def("createData", &ResidualModelJointAcceleration::createData,
84
           bp::with_custodian_and_ward_postcall<0, 2>(),
85
20
           bp::args("self", "data"),
86
           "Create the joint-acceleration residual data.\n\n"
87
           "Each residual model has its own data that needs to be allocated. "
88
           "This function\n"
89
           "returns the allocated data for the joint-acceleration residual.\n"
90
           ":param data: shared data\n"
91

20
           ":return residual data.")
92
      .add_property(
93
          "reference",
94
          bp::make_function(&ResidualModelJointAcceleration::get_reference,
95
10
                            bp::return_internal_reference<>()),
96
          &ResidualModelJointAcceleration::set_reference,
97

10
          "reference joint acceleration")
98
10
      .def(CopyableVisitor<ResidualModelJointAcceleration>());
99
10
}
100
101
}  // namespace python
102
}  // namespace crocoddyl