Skip to content

Commit

Permalink
Moved collision velocity contraint outside the pyopensot.cpp file in …
Browse files Browse the repository at this point in the history
…order to make the bindings compile when the flag OPENSOT_COMPILE_COLLISION is False.

Collisions bindngs are now in pyopensot_collision python lib.
  • Loading branch information
EnricoMingo committed Aug 2, 2024
1 parent 50ce7e9 commit 4dbd5be
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 40 deletions.
48 changes: 35 additions & 13 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ if(${pybind11_FOUND})

message(STATUS "compiling python bindings")

set(OPENSOT_BINDINGS_SOURCES pyopensot.cpp
variables.hpp
autostack.hpp
sub.hpp
aggregated.hpp
generic.hpp
basic.hpp
solver.hpp
tasks/velocity.hpp
tasks/acceleration.hpp
constraints/velocity.hpp
constraints/acceleration.hpp
constraints/force.hpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
pybind11_add_module(pyopensot pyopensot.cpp
variables.hpp
autostack.hpp
sub.hpp
aggregated.hpp
generic.hpp
basic.hpp
solver.hpp
tasks/velocity.hpp
tasks/acceleration.hpp
constraints/velocity.hpp
constraints/acceleration.hpp
constraints/force.hpp)
pybind11_add_module(pyopensot ${OPENSOT_BINDINGS_SOURCES})

target_link_libraries(pyopensot PUBLIC OpenSoT)


Expand All @@ -39,6 +42,25 @@ if(${pybind11_FOUND})
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin")

if(${OPENSOT_COMPILE_COLLISION})
set(OPENSOT_BINDINGS_COLLISION_SOURCES pyopensot_collision.cpp constraints/velocity_collision.hpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
pybind11_add_module(pyopensot_collision ${OPENSOT_BINDINGS_COLLISION_SOURCES})

target_link_libraries(pyopensot_collision PUBLIC OpenSoT)


find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

install(TARGETS pyopensot_collision
COMPONENT python
LIBRARY DESTINATION "~/.local/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin")
endif()



else()
message(STATUS "pybind not found")
Expand Down
26 changes: 0 additions & 26 deletions bindings/python/constraints/velocity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <OpenSoT/constraints/velocity/JointLimits.h>
#include <OpenSoT/constraints/velocity/VelocityLimits.h>
#include <OpenSoT/constraints/velocity/OmniWheels4X.h>
#include <OpenSoT/constraints/velocity/CollisionAvoidance.h>


namespace py = pybind11;
using namespace OpenSoT::constraints::velocity;
Expand Down Expand Up @@ -35,27 +33,3 @@ void pyVelocityOmniWheels4X(py::module& m) {
.def("update", &OmniWheels4X::update);

}

void pyVelocityCollisionAvoidance(py::module& m) {
py::class_<CollisionAvoidance, std::shared_ptr<CollisionAvoidance>, OpenSoT::Constraint<Eigen::MatrixXd, Eigen::VectorXd>>(m, "CollisionAvoidance")
.def(py::init<const XBot::ModelInterface&, int, urdf::ModelConstSharedPtr, srdf::ModelConstSharedPtr>(),
py::arg(), py::arg("max_pairs") = -1, py::arg("collision_urdf") = nullptr, py::arg("collision_srdf") = nullptr)
.def("getLinkPairThreshold", &CollisionAvoidance::getLinkPairThreshold)
.def("getDetectionThreshold", &CollisionAvoidance::getDetectionThreshold)
.def("setLinkPairThreshold", &CollisionAvoidance::setLinkPairThreshold)
.def("setDetectionThreshold", &CollisionAvoidance::setDetectionThreshold)
.def("update", &CollisionAvoidance::update)
.def("setMaxPairs", &CollisionAvoidance::setMaxPairs)
.def("setCollisionList", &CollisionAvoidance::setCollisionList)
.def("collisionModelUpdated", &CollisionAvoidance::collisionModelUpdated)
.def("addCollisionShape", &CollisionAvoidance::addCollisionShape)
.def("moveCollisionShape", &CollisionAvoidance::moveCollisionShape)
.def("setBoundScaling", &CollisionAvoidance::setBoundScaling)
.def("setLinksVsEnvironment", &CollisionAvoidance::setLinksVsEnvironment)
.def("getCollisionModel", (const XBot::Collision::CollisionModel& (CollisionAvoidance::*)() const) &CollisionAvoidance::getCollisionModel)
.def("getOrderedWitnessPointVector", &CollisionAvoidance::getOrderedWitnessPointVector)
.def("getOrderedLinkPairVector", &CollisionAvoidance::getOrderedLinkPairVector)
.def("getOrderedDistanceVector", &CollisionAvoidance::getOrderedDistanceVector)
.def("getCollisionJacobian", &CollisionAvoidance::getCollisionJacobian);
}

31 changes: 31 additions & 0 deletions bindings/python/constraints/velocity_collision.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include <OpenSoT/constraints/velocity/CollisionAvoidance.h>


namespace py = pybind11;
using namespace OpenSoT::constraints::velocity;

void pyVelocityCollisionAvoidance(py::module& m) {
py::class_<CollisionAvoidance, std::shared_ptr<CollisionAvoidance>, OpenSoT::Constraint<Eigen::MatrixXd, Eigen::VectorXd>>(m, "CollisionAvoidance")
.def(py::init<const XBot::ModelInterface&, int, urdf::ModelConstSharedPtr, srdf::ModelConstSharedPtr>(),
py::arg(), py::arg("max_pairs") = -1, py::arg("collision_urdf") = nullptr, py::arg("collision_srdf") = nullptr)
.def("getLinkPairThreshold", &CollisionAvoidance::getLinkPairThreshold)
.def("getDetectionThreshold", &CollisionAvoidance::getDetectionThreshold)
.def("setLinkPairThreshold", &CollisionAvoidance::setLinkPairThreshold)
.def("setDetectionThreshold", &CollisionAvoidance::setDetectionThreshold)
.def("update", &CollisionAvoidance::update)
.def("setMaxPairs", &CollisionAvoidance::setMaxPairs)
.def("setCollisionList", &CollisionAvoidance::setCollisionList)
.def("collisionModelUpdated", &CollisionAvoidance::collisionModelUpdated)
.def("addCollisionShape", &CollisionAvoidance::addCollisionShape)
.def("moveCollisionShape", &CollisionAvoidance::moveCollisionShape)
.def("setBoundScaling", &CollisionAvoidance::setBoundScaling)
.def("setLinksVsEnvironment", &CollisionAvoidance::setLinksVsEnvironment)
.def("getCollisionModel", (const XBot::Collision::CollisionModel& (CollisionAvoidance::*)() const) &CollisionAvoidance::getCollisionModel)
.def("getOrderedWitnessPointVector", &CollisionAvoidance::getOrderedWitnessPointVector)
.def("getOrderedLinkPairVector", &CollisionAvoidance::getOrderedLinkPairVector)
.def("getOrderedDistanceVector", &CollisionAvoidance::getOrderedDistanceVector)
.def("getCollisionJacobian", &CollisionAvoidance::getCollisionJacobian);
}
1 change: 0 additions & 1 deletion bindings/python/pyopensot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ PYBIND11_MODULE(pyopensot, m) {
pyVelocityJointLimits(m_cv);
pyVelocityLimits(m_cv);
pyVelocityOmniWheels4X(m_cv);
pyVelocityCollisionAvoidance(m_cv);

auto m_ca = m_c.def_submodule("acceleration");
pyAccelerationJointLimits(m_ca);
Expand Down
7 changes: 7 additions & 0 deletions bindings/python/pyopensot_collision.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "constraints/velocity_collision.hpp"

PYBIND11_MODULE(pyopensot_collision, m) {
auto m_c = m.def_submodule("constraints");
auto m_cv = m_c.def_submodule("velocity");
pyVelocityCollisionAvoidance(m_cv);
}

0 comments on commit 4dbd5be

Please sign in to comment.