Skip to content

Commit

Permalink
Add python bindings for Joint::getWrenchTo{Child|Parent}BodyNode (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Nov 4, 2021
1 parent 787b351 commit 5013021
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 47 deletions.
5 changes: 2 additions & 3 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,14 @@ if [ "$BUILD_TUTORIALS" = "ON" ]; then
make -j$num_threads all tutorials
fi

make -j$num_threads install

# dartpy: build, test, and install
if [ "$BUILD_DARTPY" = "ON" ]; then
make -j$num_threads dartpy
make pytest
make -j$num_threads install-dartpy
fi

make -j$num_threads install

# Codecov
if [ "$CODECOV" = "ON" ]; then
lcov --directory . --capture --output-file coverage.info
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Fixed bullet header include: [#1620](https://github.com/dartsim/dart/pull/1620)

* dartpy

* Added Python bindings for Joint::getWrenchTo{Child|Parent}BodyNode: [#1621](https://github.com/dartsim/dart/pull/1621)

### [DART 6.12.0 (2021-11-1)](https://github.com/dartsim/dart/milestone/66?closed=1)

* API Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ message(STATUS "Run 'make view_docs' to see the API documentation")
message(STATUS "Run 'make install' to install all the C++ components")
if(TARGET dartpy)
message(STATUS "Run 'make dartpy' to build dartpy")
message(STATUS "Run 'make install-dartpy' to install dartpy")
message(STATUS "Run 'make install' to install dartpy")
endif()

#===============================================================================
Expand Down
40 changes: 19 additions & 21 deletions python/dartpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@ if(NOT DARTPY_PYTHON_VERSION)
set(DARTPY_PYTHON_VERSION 3.4 CACHE STRING "Choose the target Python version (e.g., 3.4, 2.7)" FORCE)
endif()

find_package(PythonInterp ${DARTPY_PYTHON_VERSION} QUIET)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"from distutils.sysconfig import get_python_lib;\
print(get_python_lib(plat_specific=True, prefix=''))"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT IS_ABSOLUTE PYTHON_SITE_PACKAGES)
set(PYTHON_SITE_PACKAGES "${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGES}")
# Find pybind11, including PythonInterp and PythonLibs
# Needs to set PYBIND11_PYTHON_VERSION before finding pybind11
set(PYBIND11_PYTHON_VERSION ${DARTPY_PYTHON_VERSION})
find_package(pybind11 2.2.0 QUIET)
if(NOT pybind11_FOUND)
message(WARNING "Disabling [dartpy] due to missing pybind11 >= 2.2.0.")
return()
endif()

if(NOT PythonInterp_FOUND AND NOT PYTHONINTERP_FOUND)
message(WARNING "Disabling [dartpy] due to missing [PythonInterp].")
return()
endif()

find_package(PythonLibs ${DARTPY_PYTHON_VERSION} QUIET)
if(NOT PythonLibs_FOUND AND NOT PYTHONLIBS_FOUND)
message(WARNING "Disabling [dartpy] due to missing [PythonLibs].")
return()
endif()

# Find pybind11
# Needs to set PYBIND11_PYTHON_VERSION before finding pybind11
set(PYBIND11_PYTHON_VERSION ${DARTPY_PYTHON_VERSION})
find_package(pybind11 2.2.0 QUIET)
if(NOT pybind11_FOUND)
message(WARNING "Disabling [dartpy] due to missing pybind11 >= 2.2.0.")
return()
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"from distutils.sysconfig import get_python_lib;\
print(get_python_lib(plat_specific=True, prefix=''))"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT IS_ABSOLUTE PYTHON_SITE_PACKAGES)
set(PYTHON_SITE_PACKAGES "${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGES}")
endif()

file(GLOB_RECURSE dartpy_headers "*.h" "*.hpp")
Expand Down Expand Up @@ -99,10 +98,9 @@ if(BUILD_SHARED_LIBS)
"Install the shared libraries to be able to import ${pybind_module}."
)
endif()
add_custom_target(install-${pybind_module}
COMMENT "${install_comment}"
COMMAND ${CMAKE_COMMAND} -E copy ${PYBIND_MODULE} ${PYTHON_SITE_PACKAGES}
DEPENDS ${install_dartpy_deps}
# Install the pybind module to site-packages directory
install(TARGETS ${pybind_module}
LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}"
)

list(REMOVE_ITEM dartpy_headers
Expand Down
8 changes: 8 additions & 0 deletions python/dartpy/dynamics/Joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,14 @@ void Joint(py::module& m)
+[](const dart::dynamics::Joint* self) -> Eigen::Vector6d {
return self->getBodyConstraintWrench();
})
.def(
"getWrenchToChildBodyNode",
&dart::dynamics::Joint::getWrenchToChildBodyNode,
::py::arg("withRespectTo") = nullptr)
.def(
"getWrenchToParentBodyNode",
&dart::dynamics::Joint::getWrenchToParentBodyNode,
::py::arg("withRespectTo") = nullptr)
.def(
"notifyPositionUpdated",
+[](dart::dynamics::Joint* self)
Expand Down
2 changes: 1 addition & 1 deletion python/dartpy/dynamics/SimpleFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void SimpleFrame(py::module& m)
dart::dynamics::SimpleFrame,
dart::dynamics::ShapeFrame,
dart::dynamics::Detachable,
std::shared_ptr<dart::dynamics::SimpleFrame> >(m, "SimpleFrame")
std::shared_ptr<dart::dynamics::SimpleFrame>>(m, "SimpleFrame")
.def(::py::init<>())
.def(::py::init<dart::dynamics::Frame*>(), ::py::arg("refFrame"))
.def(
Expand Down
3 changes: 3 additions & 0 deletions python/dartpy/eigen_geometry_pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ void eigen_geometry(pybind11::module& parent_m)
.def("matrix", [](const Class* self) -> Eigen::Matrix<T, 4, 4> {
return self->matrix();
})
.def("set_identity", [](Class* self) {
self->setIdentity();
})
.def("set_matrix", [](Class* self, const Eigen::Matrix<T, 4, 4>& matrix) {
Class update(matrix);
CheckIsometry(update);
Expand Down
4 changes: 2 additions & 2 deletions python/dartpy/utils/SdfParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void SdfParser(py::module& m)
{
auto sm = m.def_submodule("SdfParser");

::py::enum_<utils::SdfParser::RootJointType>(m, "RootJointType")
::py::enum_<utils::SdfParser::RootJointType>(sm, "RootJointType")
.value("FLOATING", utils::SdfParser::RootJointType::FLOATING)
.value("FIXED", utils::SdfParser::RootJointType::FIXED);

::py::class_<utils::SdfParser::Options>(m, "Options")
::py::class_<utils::SdfParser::Options>(sm, "Options")
.def(
::py::init<
common::ResourceRetrieverPtr,
Expand Down
1 change: 1 addition & 0 deletions python/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function(dartpy_add_test test_name) # ARGN for source file
COMMAND PYTHONPATH=${DART_DARTPY_BUILD_DIR} ${PYTHON_EXECUTABLE} ${source}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
SOURCES ${source}
DEPENDS dartpy
)
endfunction()

Expand Down
Empty file.
Loading

0 comments on commit 5013021

Please sign in to comment.