Skip to content

Commit

Permalink
fixed bindings operators
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMingo committed May 9, 2024
1 parent be91104 commit f497579
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
13 changes: 10 additions & 3 deletions bindings/python/autostack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace OpenSoT;

void pyAutostack(py::module& m) {
// Expose AutoStack class
py::class_<AutoStack, AutoStack::Ptr>(m, "AutoStack")
py::class_<AutoStack, std::shared_ptr<AutoStack>>(m, "AutoStack")
.def(py::init<const int>())
.def(py::init<OpenSoT::tasks::Aggregated::TaskPtr>())
.def(py::init<OpenSoT::tasks::Aggregated::TaskPtr, std::list<OpenSoT::constraints::Aggregated::ConstraintPtr>>())
Expand All @@ -23,8 +23,15 @@ void pyAutostack(py::module& m) {
.def("getRegularisationTask", &AutoStack::getRegularisationTask)
.def("setBoundsAggregationPolicy", &AutoStack::setBoundsAggregationPolicy)
.def("getBounds", &AutoStack::getBounds)
.def("getTask", &AutoStack::getTask);

.def("getTask", &AutoStack::getTask)
.def("__lshift__", [](OpenSoT::AutoStack::Ptr stack, OpenSoT::constraints::Aggregated::ConstraintPtr bound) {
return stack << bound;})
.def("__lshift__", [](OpenSoT::AutoStack::Ptr stack, OpenSoT::tasks::Aggregated::TaskPtr constraint) {
return stack << constraint;})
.def("__truediv__", [](const OpenSoT::AutoStack::Ptr stack, const OpenSoT::tasks::Aggregated::TaskPtr task ) {
return stack / task;})
.def("__truediv__", [](OpenSoT::AutoStack::Ptr stack1, OpenSoT::AutoStack::Ptr stack2) {
return stack1 / stack2;});

m.def("mul", [](const Eigen::MatrixXd& W, OpenSoT::tasks::Aggregated::TaskPtr task) {
return W * task;
Expand Down
27 changes: 25 additions & 2 deletions bindings/python/basic.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <OpenSoT/Task.h>
#include <OpenSoT/Constraint.h>
#include <OpenSoT/utils/AutoStack.h>

using namespace OpenSoT;
namespace py = pybind11;
Expand Down Expand Up @@ -47,7 +49,26 @@ void pyTask(py::module& m, const std::string& className) {
.def("setActiveJointsMask", &Task<MatrixType, VectorType>::setActiveJointsMask)
.def("log", &Task<MatrixType, VectorType>::log)
.def("computeCost", &Task<MatrixType, VectorType>::computeCost)
.def("checkConsistency", &Task<MatrixType, VectorType>::checkConsistency);
.def("checkConsistency", &Task<MatrixType, VectorType>::checkConsistency)
.def("__add__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task1, const std::shared_ptr<Task<MatrixType, VectorType>> task2) {
return task1 + task2;})
.def("__mod__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task, const std::list<unsigned int>& rowIndices) {
return task % rowIndices;})
.def("__rmul__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task, const float& w) {
return w * task;})
.def("__truediv__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task1,
const std::shared_ptr<Task<MatrixType, VectorType>> task2) {
return task1 / task2;})
.def("__truediv__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task, const OpenSoT::AutoStack::Ptr stack) {
return task / stack;})
.def("__lshift__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task, const std::shared_ptr<Constraint<MatrixType, VectorType>> constraint) {
return task << constraint;})
.def("__lshift__", [](const std::shared_ptr<Task<MatrixType, VectorType>> task1,
const std::shared_ptr<Task<MatrixType, VectorType>> task2) {
return task1 << task2;
});


}

template<typename MatrixType, typename VectorType>
Expand All @@ -72,7 +93,9 @@ void pyConstraint(py::module& m, const std::string& className) {
.def("getConstraintID", &Constraint<MatrixType, VectorType>::getConstraintID)
.def("update", &Constraint<MatrixType, VectorType>::update)
.def("log", &Constraint<MatrixType, VectorType>::log)
.def("checkConsistency", &Constraint<MatrixType, VectorType>::checkConsistency);
.def("checkConsistency", &Constraint<MatrixType, VectorType>::checkConsistency)
.def("__mod__", [](const std::shared_ptr<Constraint<MatrixType, VectorType>> constraint, const std::list<unsigned int>& rowIndices) {
return constraint % rowIndices;});
}


Expand Down
1 change: 0 additions & 1 deletion bindings/python/constraints/force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void pyForceCoP(py::module& m) {

py::class_<CoPs, std::shared_ptr<CoPs>, OpenSoT::Constraint<Eigen::MatrixXd, Eigen::VectorXd>>(m, "CoPs")
.def(py::init<const std::vector<AffineHelper>&, const std::vector<std::string>&, XBot::ModelInterface&, const std::vector<Eigen::Vector2d>&, const std::vector<Eigen::Vector2d>&>())
.def("getCoP", &CoPs::getCoP)
.def("update", &CoPs::update);
}

Expand Down
2 changes: 0 additions & 2 deletions include/OpenSoT/constraints/force/CoP.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ namespace OpenSoT {
const std::vector<Eigen::Vector2d>& X_Lims,
const std::vector<Eigen::Vector2d>& Y_Lims);

CoP::Ptr getCoP(const std::string& contact_name);

void update();


Expand Down

0 comments on commit f497579

Please sign in to comment.