GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/constraints/residual.cpp Lines: 27 28 96.4 %
Date: 2024-02-13 11:12:33 Branches: 21 42 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/core/constraints/residual.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 exposeConstraintResidual() {
18
10
  bp::register_ptr_to_python<boost::shared_ptr<ConstraintModelResidual> >();
19
20
10
  bp::class_<ConstraintModelResidual, bp::bases<ConstraintModelAbstract> >(
21
      "ConstraintModelResidual",
22
      "This defines equality / inequality constraints based on a residual "
23
      "vector and its bounds.",
24
10
      bp::init<boost::shared_ptr<StateAbstract>,
25
               boost::shared_ptr<ResidualModelAbstract>, Eigen::VectorXd,
26
               Eigen::VectorXd>(
27
20
          bp::args("self", "state", "residual", "lower", "upper"),
28
          "Initialize the residual constraint model as an inequality "
29
          "constraint.\n\n"
30
          ":param state: state description\n"
31
          ":param residual: residual model\n"
32
          ":param lower: lower bound\n"
33
          ":param upper: upper bound"))
34
10
      .def(bp::init<boost::shared_ptr<StateAbstract>,
35
                    boost::shared_ptr<ResidualModelAbstract> >(
36
20
          bp::args("self", "state", "residual"),
37
          "Initialize the residual constraint model as an equality "
38
          "constraint.\n\n"
39
          ":param state: state description\n"
40
10
          ":param residual: residual model"))
41
      .def<void (ConstraintModelResidual::*)(
42
          const boost::shared_ptr<ConstraintDataAbstract>&,
43
          const Eigen::Ref<const Eigen::VectorXd>&,
44
          const Eigen::Ref<const Eigen::VectorXd>&)>(
45
          "calc", &ConstraintModelResidual::calc,
46
20
          bp::args("self", "data", "x", "u"),
47
          "Compute the residual constraint.\n\n"
48
          ":param data: constraint data\n"
49
          ":param x: state point (dim. state.nx)\n"
50
20
          ":param u: control input (dim. nu)")
51
      .def<void (ConstraintModelResidual::*)(
52
          const boost::shared_ptr<ConstraintDataAbstract>&,
53
          const Eigen::Ref<const Eigen::VectorXd>&)>(
54
20
          "calc", &ConstraintModelAbstract::calc, bp::args("self", "data", "x"),
55
          "Compute the residual constraint based on state only.\n\n"
56
          "It updates the constraint based on the state only.\n"
57
          "This function is commonly used in the terminal nodes of an optimal "
58
          "control problem.\n"
59
          ":param data: constraint data\n"
60
10
          ":param x: state point (dim. state.nx)")
61
      .def<void (ConstraintModelResidual::*)(
62
          const boost::shared_ptr<ConstraintDataAbstract>&,
63
          const Eigen::Ref<const Eigen::VectorXd>&,
64
          const Eigen::Ref<const Eigen::VectorXd>&)>(
65
          "calcDiff", &ConstraintModelResidual::calcDiff,
66
20
          bp::args("self", "data", "x", "u"),
67
          "Compute the derivatives of the residual constraint.\n\n"
68
          "It assumes that calc has been run first.\n"
69
          ":param data: constraint data\n"
70
          ":param x: state point (dim. state.nx)\n"
71
10
          ":param u: control input (dim. nu)\n")
72
      .def<void (ConstraintModelResidual::*)(
73
          const boost::shared_ptr<ConstraintDataAbstract>&,
74
          const Eigen::Ref<const Eigen::VectorXd>&)>(
75
          "calcDiff", &ConstraintModelAbstract::calcDiff,
76
20
          bp::args("self", "data", "x"),
77
          "Compute the derivatives of the residual constraint with respect to "
78
          "the state only.\n\n"
79
          "It updates the Jacobian of the constraint function based on the "
80
          "state only.\n"
81
          "This function is commonly used in the terminal nodes of an optimal "
82
          "control problem.\n"
83
          ":param data: constraint data\n"
84
10
          ":param x: state point (dim. state.nx)")
85
      .def("createData", &ConstraintModelResidual::createData,
86
           bp::with_custodian_and_ward_postcall<0, 2>(),
87
20
           bp::args("self", "data"),
88
           "Create the residual constraint data.\n\n"
89
           "Each constraint model has its own data that needs to be allocated. "
90
           "This function\n"
91
           "returns the allocated data for a predefined constraint.\n"
92
           ":param data: shared data\n"
93

20
           ":return constraint data.")
94
10
      .def(CopyableVisitor<ConstraintModelResidual>());
95
96
10
  bp::register_ptr_to_python<boost::shared_ptr<ConstraintDataResidual> >();
97
98
10
  bp::class_<ConstraintDataResidual, bp::bases<ConstraintDataAbstract> >(
99
      "ConstraintDataResidual", "Data for residual constraint.\n\n",
100
10
      bp::init<ConstraintModelResidual*, DataCollectorAbstract*>(
101
10
          bp::args("self", "model", "data"),
102
          "Create residual constraint data.\n\n"
103
          ":param model: residual constraint model\n"
104
10
          ":param data: shared data")[bp::with_custodian_and_ward<
105
20
          1, 2, bp::with_custodian_and_ward<1, 3> >()])
106
10
      .def(CopyableVisitor<ConstraintDataResidual>());
107
10
}
108
109
}  // namespace python
110
}  // namespace crocoddyl