Skip to content

Commit 37cd6bd

Browse files
committed
Added trampoline class for GenricTask and GenericConstraint
1 parent 666ecf5 commit 37cd6bd

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

bindings/python/generic.hpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,47 @@ namespace py = pybind11;
88
using namespace OpenSoT::constraints;
99
using namespace OpenSoT::tasks;
1010

11+
struct PyGenericTaskTrampoline : public GenericTask {
12+
using GenericTask::GenericTask; // Inherit constructors
13+
14+
void _update() override {
15+
PYBIND11_OVERRIDE(
16+
void, // Return type
17+
GenericTask, // C++ parent class
18+
_update // Name of the function
19+
);
20+
}
21+
};
22+
23+
struct PyGenericConstraintTrampoline : public GenericConstraint {
24+
using GenericConstraint::GenericConstraint; // Inherit constructors
25+
26+
void _update() override {
27+
PYBIND11_OVERRIDE(
28+
void, // Return type
29+
GenericConstraint, // C++ parent class
30+
_update // Name of the function
31+
);
32+
}
33+
};
34+
1135
// Define bindings
1236
void pyGenericConstraint(py::module& m) {
1337
py::enum_<GenericConstraint::Type>(m, "ConstraintType")
1438
.value("BOUND", GenericConstraint::Type::BOUND)
1539
.value("CONSTRAINT", GenericConstraint::Type::CONSTRAINT)
1640
.export_values();
1741

18-
py::class_<GenericConstraint, std::shared_ptr<GenericConstraint>, Constraint<Eigen::MatrixXd, Eigen::VectorXd>>(m, "GenericConstraint")
42+
py::class_<GenericConstraint, std::shared_ptr<GenericConstraint>, Constraint<Eigen::MatrixXd, Eigen::VectorXd>, PyGenericConstraintTrampoline>(m, "GenericConstraint")
1943
.def(py::init<std::string, const Eigen::VectorXd&, const Eigen::VectorXd&, int>())
2044
.def(py::init<std::string, const AffineHelper&, const Eigen::VectorXd&, const Eigen::VectorXd&, GenericConstraint::Type>())
2145
.def("setConstraint", &GenericConstraint::setConstraint)
2246
.def("setBounds", &GenericConstraint::setBounds)
23-
.def("update", &GenericConstraint::update)
2447
.def("getType", &GenericConstraint::getType);
2548
}
2649

2750
void pyGenericTask(py::module& m) {
28-
py::class_<GenericTask, std::shared_ptr<GenericTask>, Task<Eigen::MatrixXd, Eigen::VectorXd>>(m, "GenericTask")
51+
py::class_<GenericTask, std::shared_ptr<GenericTask>, Task<Eigen::MatrixXd, Eigen::VectorXd>, PyGenericTaskTrampoline>(m, "GenericTask")
2952
.def(py::init<const std::string&, const Eigen::MatrixXd&, const Eigen::VectorXd&>())
3053
.def(py::init<const std::string&, const Eigen::MatrixXd&, const Eigen::VectorXd&, const AffineHelper&>())
3154
.def("setA", &GenericTask::setA)

0 commit comments

Comments
 (0)