Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/constraints/residual.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 25 | 27 | 92.6% |
Branches: | 20 | 40 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2024, 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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<StateAbstract>, |
25 | boost::shared_ptr<ResidualModelAbstract>, Eigen::VectorXd, | ||
26 | Eigen::VectorXd, bp::optional<bool> >( | ||
27 | 20 | bp::args("self", "state", "residual", "lower", "upper", "T_act"), | |
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\n" | ||
34 | ":param T_act: false if we want to deactivate the residual at the " | ||
35 | "terminal node (default true)")) | ||
36 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<boost::shared_ptr<StateAbstract>, |
37 | boost::shared_ptr<ResidualModelAbstract>, | ||
38 | bp::optional<bool> >( | ||
39 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "state", "residual", "T_act"), |
40 | "Initialize the residual constraint model as an equality " | ||
41 | "constraint.\n\n" | ||
42 | ":param state: state description\n" | ||
43 | ":param residual: residual model\n" | ||
44 | ":param T_act: false if we want to deactivate the residual at the " | ||
45 | "terminal node (default true)")) | ||
46 | .def<void (ConstraintModelResidual::*)( | ||
47 | const boost::shared_ptr<ConstraintDataAbstract>&, | ||
48 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
49 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
50 | "calc", &ConstraintModelResidual::calc, | ||
51 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
52 | "Compute the residual constraint.\n\n" | ||
53 | ":param data: constraint data\n" | ||
54 | ":param x: state point (dim. state.nx)\n" | ||
55 | ":param u: control input (dim. nu)") | ||
56 | .def<void (ConstraintModelResidual::*)( | ||
57 | const boost::shared_ptr<ConstraintDataAbstract>&, | ||
58 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
59 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ConstraintModelAbstract::calc, bp::args("self", "data", "x"), |
60 | "Compute the residual constraint based on state only.\n\n" | ||
61 | "It updates the constraint based on the state only.\n" | ||
62 | "This function is commonly used in the terminal nodes of an optimal " | ||
63 | "control problem.\n" | ||
64 | ":param data: constraint data\n" | ||
65 | ":param x: state point (dim. state.nx)") | ||
66 | .def<void (ConstraintModelResidual::*)( | ||
67 | const boost::shared_ptr<ConstraintDataAbstract>&, | ||
68 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
69 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
70 | "calcDiff", &ConstraintModelResidual::calcDiff, | ||
71 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
72 | "Compute the derivatives of the residual constraint.\n\n" | ||
73 | "It assumes that calc has been run first.\n" | ||
74 | ":param data: constraint data\n" | ||
75 | ":param x: state point (dim. state.nx)\n" | ||
76 | ":param u: control input (dim. nu)\n") | ||
77 | .def<void (ConstraintModelResidual::*)( | ||
78 | const boost::shared_ptr<ConstraintDataAbstract>&, | ||
79 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
80 | "calcDiff", &ConstraintModelAbstract::calcDiff, | ||
81 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x"), |
82 | "Compute the derivatives of the residual constraint with respect to " | ||
83 | "the state only.\n\n" | ||
84 | "It updates the Jacobian of the constraint function based on the " | ||
85 | "state only.\n" | ||
86 | "This function is commonly used in the terminal nodes of an optimal " | ||
87 | "control problem.\n" | ||
88 | ":param data: constraint data\n" | ||
89 | ":param x: state point (dim. state.nx)") | ||
90 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("createData", &ConstraintModelResidual::createData, |
91 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
92 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
93 | "Create the residual constraint data.\n\n" | ||
94 | "Each constraint model has its own data that needs to be allocated. " | ||
95 | "This function\n" | ||
96 | "returns the allocated data for a predefined constraint.\n" | ||
97 | ":param data: shared data\n" | ||
98 | ":return constraint data.") | ||
99 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ConstraintModelResidual>()); |
100 | |||
101 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ConstraintDataResidual> >(); | |
102 | |||
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ConstraintDataResidual, bp::bases<ConstraintDataAbstract> >( |
104 | "ConstraintDataResidual", "Data for residual constraint.\n\n", | ||
105 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ConstraintModelResidual*, DataCollectorAbstract*>( |
106 | 10 | bp::args("self", "model", "data"), | |
107 | "Create residual constraint data.\n\n" | ||
108 | ":param model: residual constraint model\n" | ||
109 | ✗ | ":param data: shared data")[bp::with_custodian_and_ward< | |
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
111 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ConstraintDataResidual>()); |
112 | 10 | } | |
113 | |||
114 | } // namespace python | ||
115 | } // namespace crocoddyl | ||
116 |