Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance iDynTree from / to Python mapping and add proper NumPy support #726

Merged
merged 11 commits into from
Sep 1, 2020
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ jobs:
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install git build-essential cmake libace-dev coinor-libipopt-dev libeigen3-dev swig qtbase5-dev qtdeclarative5-dev qtmultimedia5-dev libqt5charts5-dev \
libxml2-dev liboctave-dev python-dev valgrind libassimp-dev
sudo apt-get install \
git build-essential cmake libace-dev coinor-libipopt-dev libeigen3-dev swig \
qtbase5-dev qtdeclarative5-dev qtmultimedia5-dev libqt5charts5-dev \
libxml2-dev liboctave-dev python-dev python3-numpy valgrind libassimp-dev

- name: Cache Source-based Dependencies
id: cache-source-deps
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a new CMake option `IDYNTREE_COMPILES_TOOLS` to disable compilation of iDynTree tools.
- Added a `KinDynComputations::getCentroidalTotalMomentumJacobian()` method (https://github.com/robotology/idyntree/pull/706)
- iDynTree now supports build compiled as a shared library also on Windows.
- When used in Python, new iDynTree objects can be constructed from generic iterable objects and NumPy arrays (`*.FromPython`),
and existing objects can be converted to NumPy arrays (`*.toNumPy`) (https://github.com/robotology/idyntree/pull/726).

### Fixed
- Fixed bug in `yarprobotstatepublisher` that caused segmentation fault each time an unknown joint name was read from the input joint states topic (https://github.com/robotology/idyntree/pull/719)
Expand All @@ -19,12 +21,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- By default iDynTree is compiled as a shared library also on Windows. The `BUILD_SHARED_LIBS` CMake variable can be used to
control if iDynTree is built as a shared or a static library.
- The Python method `*.fromPyList` is replaced by `*.FromPython` (https://github.com/robotology/idyntree/pull/726).

### Removed
- Remove the CMake option IDYNTREE_USES_KDL and all the classes available when enabling it. They were deprecated in iDynTree 1.0 .
- Remove the semantics related classes. They were deprecated in iDynTree 1.0 .
- Remove unnecessary warning messages from [ModelSensorsTransformers.cpp](https://github.com/robotology/idyntree/blob/master/src/sensors/src/ModelSensorsTransformers.cpp) and [URDFDocument.cpp](https://github.com/robotology/idyntree/blob/master/src/model_io/urdf/src/URDFDocument.cpp) (see [PR 718](https://github.com/robotology/idyntree/pull/718))

- Python2 will not be maintained past 2020 and its support has been dropped (https://github.com/robotology/idyntree/pull/726).
- Remove the need to call `iDynTree.init_helpers()` and `iDynTree.init_numpy_helpers()` from Python (https://github.com/robotology/idyntree/pull/726).

## [Unreleased]

Expand Down
2 changes: 1 addition & 1 deletion bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option(IDYNTREE_GENERATE_MATLAB "Enable if you have the experimental version of
find_package(SWIG)
# It is possible to compile matlab/octave bindings without using SWIG
if(SWIG_FOUND OR IDYNTREE_USES_MATLAB OR IDYNTREE_USES_OCTAVE)
include(UseSWIG)
include(${SWIG_USE_FILE})

set_source_files_properties(iDynTree.i PROPERTIES CPLUSPLUS ON)

Expand Down
42 changes: 20 additions & 22 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
set(CMAKE_SWIG_FLAGS "-Wextra;-module;iDynTree;-threads")
set(IDYNTREE_USES_PYTHON_VERSION "" CACHE STRING "Specify python version to use" )

find_package(PythonInterp ${IDYNTREE_USES_PYTHON_VERSION} REQUIRED)
set(IDYNTREE_USES_PYTHON_VERSION_ARGS)
if(NOT IDYNTREE_USES_PYTHON_VERSION)
set (IDYNTREE_USES_PYTHON_VERSION ${PYTHON_VERSION_STRING})
endif()
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
message(STATUS "Using Python: ${Python3_EXECUTABLE}")

find_package(PythonLibs ${IDYNTREE_USES_PYTHON_VERSION} EXACT)
include_directories(${PYTHON_INCLUDE_PATH})
link_libraries(${PYTHON_LIBRARY})
set_source_files_properties(../iDynTree.i PROPERTIES CPLUSPLUS ON)

## in Windows it seems necessary to declare explictly the link_directory
if(WIN32)
get_filename_component(PYTHON_DIR ${PYTHON_LIBRARY} PATH)
link_directories(${PYTHON_DIR})
endif()
swig_add_library(iDynTree_python
TYPE SHARED
LANGUAGE python
SOURCES ../iDynTree.i)

set(target_name iDynTree_python)
set(target_name ${SWIG_MODULE_iDynTree_python_REAL_NAME})

set_source_files_properties(../iDynTree.i PROPERTIES CPLUSPLUS ON)
swig_add_module(${target_name} python ../iDynTree.i)
set_target_properties(_${target_name} PROPERTIES OUTPUT_NAME "_iDynTree")
set_target_properties(_${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/python)
target_link_libraries(${target_name} PUBLIC Python3::Python Python3::NumPy)
set_target_properties(${target_name} PROPERTIES
OUTPUT_NAME "_iDynTree"
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/python)

set_property(
TARGET ${target_name}
PROPERTY SWIG_DEPENDS
python.i numpy.i)

# installation path is determined reliably on most platforms using distutils
execute_process(COMMAND ${PYTHON_EXECUTABLE}
execute_process(COMMAND ${Python3_EXECUTABLE}
-c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
OUTPUT_VARIABLE PYTHON_INSTDIR)
string(STRIP ${PYTHON_INSTDIR} PYTHON_INSTDIR)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iDynTree.py DESTINATION ${PYTHON_INSTDIR} )
install(TARGETS _${target_name} DESTINATION ${PYTHON_INSTDIR} )
install(TARGETS ${target_name} DESTINATION ${PYTHON_INSTDIR} )

if(WIN32)
set_target_properties(_${target_name} PROPERTIES SUFFIX ".pyd")
set_target_properties(${target_name} PROPERTIES SUFFIX ".pyd")
endif(WIN32)

# if compile tests execute also python tests
Expand Down
Loading