diff --git a/CMakeLists.txt b/CMakeLists.txt index d24aefb9c..6ad1a9706 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.4.3) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) - +cmake_policy(SET CMP0017 NEW) #this line has to appear before 'PROJECT' in order to be able to disable incremental linking SET(MSVC_INCREMENTAL_DEFAULT ON) @@ -27,7 +27,7 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF) OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON) OPTION(BUILD_SHARED_LIBS "Use shared libraries" OFF) -OPTION(USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD "Use btSoftMultiBodyDynamicsWorld" OFF) +OPTION(USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD "Use btSoftMultiBodyDynamicsWorld" OFF) OPTION(BULLET2_USE_THREAD_LOCKS "Build Bullet 2 libraries with mutex locking around certain operations" OFF) OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF) @@ -123,22 +123,22 @@ IF(MSVC) OPTION(USE_MSVC_EXEPTIONS "Use MSVC C++ exceptions option" OFF) - + OPTION(USE_MSVC_COMDAT_FOLDING "Use MSVC /OPT:ICF COMDAT folding option" ON) - + IF(USE_MSVC_COMDAT_FOLDING) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:ICF") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:ICF") ENDIF() - + OPTION(USE_MSVC_DISABLE_RTTI "Use MSVC /GR- disabled RTTI flags option" ON) IF(USE_MSVC_DISABLE_RTTI) STRING(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Disable RTTI SET(CMAKE_C_FLAGS "/GR- ${CMAKE_C_FLAGS}") SET(CMAKE_CXX_FLAGS "/GR- ${CMAKE_CXX_FLAGS}") ENDIF(USE_MSVC_DISABLE_RTTI) - + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267") ENDIF(MSVC) @@ -254,24 +254,39 @@ ENDIF() OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON) -OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" OFF) - +# Optional Python configuration +# builds pybullet automatically if all the requirements are met +SET(PYTHON_VERSION_PYBULLET "2.7" CACHE STRING "Python version pybullet will use.") +SET(Python_ADDITIONAL_VERSIONS 2.7 2.7.3 3 3.0 3.1 3.2 3.3 3.4 3.5 3.6) +SET_PROPERTY(CACHE PYTHON_VERSION_PYBULLET PROPERTY STRINGS ${Python_ADDITIONAL_VERSIONS}) +SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build3/cmake ${CMAKE_MODULE_PATH}) +OPTION(EXACT_PYTHON_VERSION "Require Python and match PYTHON_VERSION_PYBULLET exactly, e.g. 2.7.3" OFF) +IF(EXACT_PYTHON_VERSION) + set(EXACT_PYTHON_VERSION_FLAG EXACT REQUIRED) +ENDIF(EXACT_PYTHON_VERSION) +# first find the python interpreter +FIND_PACKAGE(PythonInterp ${PYTHON_VERSION_PYBULLET} ${EXACT_PYTHON_VERSION_FLAG}) +# python library should exactly match that of the interpreter +FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_STRING} EXACT) +SET(DEFAULT_BUILD_PYBULLET OFF) +IF(PYTHONLIBS_FOUND) + SET(DEFAULT_BUILD_PYBULLET ON) +ENDIF(PYTHONLIBS_FOUND) +OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" ${DEFAULT_BUILD_PYBULLET}) + OPTION(BUILD_ENET "Set when you want to build apps with enet UDP networking support" ON) OPTION(BUILD_CLSOCKET "Set when you want to build apps with enet TCP networking support" ON) - + IF(BUILD_PYBULLET) - FIND_PACKAGE(PythonLibs) - - OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" OFF) + OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" ON) OPTION(BUILD_PYBULLET_ENET "Set when you want to build pybullet with enet UDP networking support" ON) OPTION(BUILD_PYBULLET_CLSOCKET "Set when you want to build pybullet with enet TCP networking support" ON) - OPTION(BUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK "Set when you want to use the Python Framework on Mac" ON) + OPTION(BUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK "Set when you want to use the Python Framework on Mac" OFF) - IF(BUILD_PYBULLET_NUMPY) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/build3/cmake) + IF(BUILD_PYBULLET_NUMPY) #include(FindNumPy) FIND_PACKAGE(NumPy) if (PYTHON_NUMPY_FOUND) @@ -281,7 +296,6 @@ IF(BUILD_PYBULLET) message("NumPy not found") endif() ENDIF() - OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF) IF(WIN32) SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared Libs" FORCE) diff --git a/build3/cmake/FindLibPython.py b/build3/cmake/FindLibPython.py new file mode 100644 index 000000000..d4384da4e --- /dev/null +++ b/build3/cmake/FindLibPython.py @@ -0,0 +1,25 @@ +# Note by Nikolaus Demmel 28.03.2014: My contributions are licensend under the +# same as CMake (BSD). My adaptations are in part based +# https://github.com/qgis/QGIS/tree/master/cmake which has the following +# copyright note: + +# FindLibPython.py +# Copyright (c) 2007, Simon Edwards +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +import sys +import distutils.sysconfig + +print("exec_prefix:%s" % sys.exec_prefix) +print("major_version:%s" % str(sys.version_info[0])) +print("minor_version:%s" % str(sys.version_info[1])) +print("patch_version:%s" % str(sys.version_info[2])) +print("short_version:%s" % '.'.join(map(lambda x:str(x), sys.version_info[0:2]))) +print("long_version:%s" % '.'.join(map(lambda x:str(x), sys.version_info[0:3]))) +print("py_inc_dir:%s" % distutils.sysconfig.get_python_inc()) +print("site_packages_dir:%s" % distutils.sysconfig.get_python_lib(plat_specific=1)) +for e in distutils.sysconfig.get_config_vars ('LIBDIR'): + if e != None: + print("py_lib_dir:%s" % e) + break diff --git a/build3/cmake/FindNumPy.cmake b/build3/cmake/FindNumPy.cmake index 4d729b2a3..5ce9e178c 100644 --- a/build3/cmake/FindNumPy.cmake +++ b/build3/cmake/FindNumPy.cmake @@ -1,41 +1,59 @@ -# Find the Python NumPy package -# PYTHON_NUMPY_INCLUDE_DIR -# PYTHON_NUMPY_FOUND -# will be set by this script +# - Find the NumPy libraries +# This module finds if NumPy is installed, and sets the following variables +# indicating where it is. +# +# TODO: Update to provide the libraries and paths for linking npymath lib. +# +# PYTHON_NUMPY_FOUND - was NumPy found +# PYTHON_NUMPY_VERSION - the version of NumPy found as a string +# PYTHON_NUMPY_VERSION_MAJOR - the major version number of NumPy +# PYTHON_NUMPY_VERSION_MINOR - the minor version number of NumPy +# PYTHON_NUMPY_VERSION_PATCH - the patch version number of NumPy +# PYTHON_NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is 10601 +# PYTHON_NUMPY_INCLUDE_DIR - path to the NumPy include files -cmake_minimum_required(VERSION 2.6) +unset(PYTHON_NUMPY_VERSION) +unset(PYTHON_NUMPY_INCLUDE_DIR) -if(NOT PYTHON_EXECUTABLE) - if(NumPy_FIND_QUIETLY) - find_package(PythonInterp QUIET) - else() - find_package(PythonInterp) - set(__numpy_out 1) +if(PYTHONINTERP_FOUND) + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" + "import numpy as n; print(n.__version__); print(n.get_include());" + RESULT_VARIABLE __result + OUTPUT_VARIABLE __output + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(__result MATCHES 0) + string(REGEX REPLACE ";" "\\\\;" __values ${__output}) + string(REGEX REPLACE "\r?\n" ";" __values ${__values}) + list(GET __values 0 PYTHON_NUMPY_VERSION) + list(GET __values 1 PYTHON_NUMPY_INCLUDE_DIR) + + string(REGEX MATCH "^([0-9])+\\.([0-9])+\\.([0-9])+" __ver_check "${PYTHON_NUMPY_VERSION}") + if(NOT "${__ver_check}" STREQUAL "") + set(PYTHON_NUMPY_VERSION_MAJOR ${CMAKE_MATCH_1}) + set(PYTHON_NUMPY_VERSION_MINOR ${CMAKE_MATCH_2}) + set(PYTHON_NUMPY_VERSION_PATCH ${CMAKE_MATCH_3}) + math(EXPR PYTHON_NUMPY_VERSION_DECIMAL + "(${PYTHON_NUMPY_VERSION_MAJOR} * 10000) + (${PYTHON_NUMPY_VERSION_MINOR} * 100) + ${PYTHON_NUMPY_VERSION_PATCH}") + string(REGEX REPLACE "\\\\" "/" PYTHON_NUMPY_INCLUDE_DIR ${PYTHON_NUMPY_INCLUDE_DIR}) + else() + unset(PYTHON_NUMPY_VERSION) + unset(PYTHON_NUMPY_INCLUDE_DIR) + message(STATUS "Requested NumPy version and include path, but got instead:\n${__output}\n") + endif() endif() +else() + message(STATUS "To find NumPy Python interpretor is required to be found.") endif() -if (PYTHON_EXECUTABLE) - # Find out the include path - execute_process( - COMMAND "${PYTHON_EXECUTABLE}" -c - "from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n" - OUTPUT_VARIABLE __numpy_path) - # And the version - execute_process( - COMMAND "${PYTHON_EXECUTABLE}" -c - "from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n" - OUTPUT_VARIABLE __numpy_version) -elseif(__numpy_out) - message(STATUS "Python executable not found.") -endif(PYTHON_EXECUTABLE) - -find_path(PYTHON_NUMPY_INCLUDE_DIR numpy/arrayobject.h - HINTS "${__numpy_path}" "${PYTHON_INCLUDE_PATH}" NO_DEFAULT_PATH) - -if(PYTHON_NUMPY_INCLUDE_DIR) - set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy found") -endif(PYTHON_NUMPY_INCLUDE_DIR) - include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR - VERSION_VAR __numpy_version) +find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR PYTHON_NUMPY_VERSION + VERSION_VAR PYTHON_NUMPY_VERSION) + +if(NUMPY_FOUND) + set(PYTHON_NUMPY_FOUND TRUE) + message(STATUS "NumPy ver. ${PYTHON_NUMPY_VERSION} found (include: ${PYTHON_NUMPY_INCLUDE_DIR})") +endif() + +# caffe_clear_vars(__result __output __error_value __values __ver_check __error_value) + diff --git a/build3/cmake/FindPythonLibs.cmake b/build3/cmake/FindPythonLibs.cmake new file mode 100644 index 000000000..a0e9bffbe --- /dev/null +++ b/build3/cmake/FindPythonLibs.cmake @@ -0,0 +1,353 @@ +# - Find python libraries +# This module finds if Python is installed and determines where the +# include files and libraries are. It also determines what the name of +# the library is. This code sets the following variables: +# +# PYTHONLIBS_FOUND - have the Python libs been found +# PYTHON_LIBRARIES - path to the python library +# PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated) +# PYTHON_INCLUDE_DIRS - path to where Python.h is found +# PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated) +# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8) +# +# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list of +# version numbers that should be taken into account when searching for Python. +# You need to set this variable before calling find_package(PythonLibs). +# +# If you'd like to specify the installation of Python to use, you should modify +# the following cache variables: +# PYTHON_LIBRARY - path to the python library +# PYTHON_INCLUDE_DIR - path to where Python.h is found + +#============================================================================= +# Copyright 2001-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Note by Nikolaus Demmel 28.03.2014: My contributions are licensend under the +# same as CMake (BSD). My adaptations are in part based +# https://github.com/qgis/QGIS/tree/master/cmake which has the following +# copyright note: + +# Copyright (c) 2007, Simon Edwards +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if(NOT DEFINED PYTHON_INCLUDE_DIR) + if(DEFINED PYTHON_INCLUDE_PATH) + # For backward compatibility, repect PYTHON_INCLUDE_PATH. + set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}" CACHE PATH + "Path to where Python.h is found" FORCE) + else() + set(PYTHON_INCLUDE_DIR "" CACHE PATH + "Path to where Python.h is found" FORCE) + endif() +endif() + +if(EXISTS "${PYTHON_INCLUDE_DIR}" AND EXISTS "${PYTHON_LIBRARY}") + if(EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h") + file(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" _PYTHON_VERSION_STR + REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"") + string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1" + PYTHONLIBS_VERSION_STRING "${_PYTHON_VERSION_STR}") + unset(_PYTHON_VERSION_STR) + endif() +else() + set(_PYTHON1_VERSIONS 1.6 1.5) + set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) + set(_PYTHON3_VERSIONS 3.4 3.3 3.2 3.1 3.0) + + unset(_PYTHON_FIND_OTHER_VERSIONS) + if(PythonLibs_FIND_VERSION) + if(PythonLibs_FIND_VERSION_COUNT GREATER 1) + set(_PYTHON_FIND_MAJ_MIN "${PythonLibs_FIND_VERSION_MAJOR}.${PythonLibs_FIND_VERSION_MINOR}") + if(NOT PythonLibs_FIND_VERSION_EXACT) + foreach(_PYTHON_V ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS}) + if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN) + if(NOT _PYTHON_V STREQUAL PythonLibs_FIND_VERSION) + list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V}) + endif() + endif() + endforeach() + endif() + unset(_PYTHON_FIND_MAJ_MIN) + else() + set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS}) + endif() + else() + # add an empty version to check the `python` executable first in case no version is requested + set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS}) + endif() + + unset(_PYTHON1_VERSIONS) + unset(_PYTHON2_VERSIONS) + unset(_PYTHON3_VERSIONS) + + # Set up the versions we know about, in the order we will search. Always add + # the user supplied additional versions to the front. + # If FindPythonInterp has already found the major and minor version, + # insert that version between the user supplied versions and the stock + # version list. + # If no specific version is requested or suggested by PythonInterp, always look + # for "python" executable first + set(_PYTHON_VERSIONS ${PythonLibs_FIND_VERSION} ${PythonLibs_ADDITIONAL_VERSIONS} ) + if(DEFINED PYTHON_VERSION_MAJOR AND DEFINED PYTHON_VERSION_MINOR) + list(APPEND _PYTHON_VERSIONS ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}) + endif() + if (NOT _PYTHON_VERSIONS) + set(_PYTHON_VERSIONS ";") # empty entry at the front makeing sure we search for "python" first + endif() + list(APPEND _PYTHON_VERSIONS ${_PYTHON_FIND_OTHER_VERSIONS}) + + unset(_PYTHON_FIND_OTHER_VERSIONS) + + message(STATUS "Looking for versions: ${_PYTHON_VERSIONS}") + + FIND_FILE(_FIND_LIB_PYTHON_PY FindLibPython.py PATHS ${CMAKE_MODULE_PATH} ${CMAKE_ROOT}/Modules) + + if(NOT _FIND_LIB_PYTHON_PY) + message(FATAL_ERROR "Could not find required file 'FindLibPython.py'") + endif() + + unset(PYTHONLIBS_VERSION_STRING) + foreach(_CURRENT_VERSION IN LISTS _PYTHON_VERSIONS) + + STRING(REGEX REPLACE "^([0-9]+).*$" "\\1" _VERSION_MAJOR "${_CURRENT_VERSION}") + STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+).*$" "\\1" _VERSION_MINOR "${_CURRENT_VERSION}") + + set(_PYTHON_NAMES python) + + if (_CURRENT_VERSION MATCHES "^[0-9]+.*$") + list(APPEND _PYTHON_NAMES "python${_VERSION_MAJOR}") + if (_CURRENT_VERSION MATCHES "^[0-9]+\\.[0-9].*$") + list(APPEND _PYTHON_NAMES "python${_VERSION_MAJOR}.${_VERSION_MINOR}") + endif() + endif() + + message(STATUS "Looking for python version '${_CURRENT_VERSION}' by checking executables: ${_PYTHON_NAMES}.") + + foreach(_CURRENT_PYTHON_NAME IN LISTS _PYTHON_NAMES) + + unset(_PYTHON_EXECUTABLE CACHE) + find_program(_PYTHON_EXECUTABLE ${_CURRENT_PYTHON_NAME} + PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]) + + if(_PYTHON_EXECUTABLE) + + EXECUTE_PROCESS( + COMMAND ${_PYTHON_EXECUTABLE} "${_FIND_LIB_PYTHON_PY}" + OUTPUT_VARIABLE _PYTHON_CONFIG + RESULT_VARIABLE _PYTHON_CONFIG_RESULT + ERROR_QUIET) + + if(NOT ${_PYTHON_CONFIG_RESULT} AND (NOT ${_PYTHON_CONFIG} STREQUAL "")) + STRING(REGEX REPLACE ".*\nmajor_version:([0-9]+).*$" "\\1" _PYTHON_MAJOR_VERSION ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\nminor_version:([0-9]+).*$" "\\1" _PYTHON_MINOR_VERSION ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\npatch_version:([0-9]+).*$" "\\1" _PYTHON_PATCH_VERSION ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\nshort_version:([^\n]+).*$" "\\1" _PYTHON_SHORT_VERSION ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\nlong_version:([^\n]+).*$" "\\1" _PYTHON_LONG_VERSION ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" _PYTHON_INCLUDE_DIR ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\npy_lib_dir:([^\n]+).*$" "\\1" _PYTHON_LIBRARY_DIR ${_PYTHON_CONFIG}) + STRING(REGEX REPLACE ".*\nexec_prefix:(^\n+).*$" "\\1" _PYTHON_PREFIX ${_PYTHON_CONFIG}) + + if ("${_CURRENT_VERSION}" STREQUAL "" OR + "${_CURRENT_VERSION}" STREQUAL "${_PYTHON_MAJOR_VERSION}" OR + "${_CURRENT_VERSION}" STREQUAL "${_PYTHON_SHORT_VERSION}" OR + "${_CURRENT_VERSION}" STREQUAL "${_PYTHON_LONG_VERSION}") + + message(STATUS "Found executable ${_PYTHON_EXECUTABLE} with suitable version ${_PYTHON_LONG_VERSION}") + + if(NOT EXISTS "${PYTHON_INCLUDE_DIR}") + set(PYTHON_INCLUDE_DIR "${_PYTHON_INCLUDE_DIR}") + endif() + + if(NOT EXISTS "${PYTHON_LIBRARY}") + set(_PYTHON_SHORT_VERSION_NO_DOT "${_PYTHON_MAJOR_VERSION}${_PYTHON_MINOR_VERSION}") + set(_PYTHON_LIBRARY_NAMES python${_PYTHON_SHORT_VERSION} python${_PYTHON_SHORT_VERSION_NO_DOT}) + FIND_LIBRARY(PYTHON_LIBRARY + NAMES ${_PYTHON_LIBRARY_NAMES} + PATH_SUFFIXES + python${_PYTHON_SHORT_VERSION}/config + python${_PYTHON_SHORT_VERSION_NO_DOT}/config + PATHS + ${_PYTHON_LIBRARY_DIR} + ${_PYTHON_PREFIX}/lib $ + {_PYTHON_PREFIX}/libs + NO_DEFAULT_PATH) + + if(WIN32) + find_library(PYTHON_DEBUG_LIBRARY + NAMES python${_PYTHON_SHORT_VERSION_NO_DOT}_d python + PATHS + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs + ) + endif() + endif() + + set(PYTHONLIBS_VERSION_STRING ${_PYTHON_LONG_VERSION}) + if(_PYTHON_PATCH_VERSION STREQUAL "0") + # it's called "Python 2.7", not "2.7.0" + string(REGEX REPLACE "\\.0$" "" PYTHONLIBS_VERSION_STRING "${PYTHONLIBS_VERSION_STRING}") + endif() + + break() + else() + message(STATUS "Found executable ${_PYTHON_EXECUTABLE} with UNsuitable version ${_PYTHON_LONG_VERSION}") + endif() # version ok + else() + message(WARNING "Found executable ${_PYTHON_EXECUTABLE}, but could not extract version info.") + endif() # could extract config + endif() # found executable + endforeach() # python names + if (PYTHONLIBS_VERSION_STRING) + break() + endif() + endforeach() # python versions +endif() + +unset(_PYTHON_NAMES) +unset(_PYTHON_VERSIONS) +unset(_PYTHON_EXECUTABLE CACHE) +unset(_PYTHON_MAJOR_VERSION) +unset(_PYTHON_MINOR_VERSION) +unset(_PYTHON_PATCH_VERSION) +unset(_PYTHON_SHORT_VERSION) +unset(_PYTHON_LONG_VERSION) +unset(_PYTHON_LIBRARY_DIR) +unset(_PYTHON_INCLUDE_DIR) +unset(_PYTHON_PREFIX) +unset(_PYTHON_SHORT_VERSION_NO_DOT) +unset(_PYTHON_LIBRARY_NAMES) + + +# For backward compatibility, set PYTHON_INCLUDE_PATH. +set(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}") + +mark_as_advanced( + PYTHON_DEBUG_LIBRARY + PYTHON_LIBRARY + PYTHON_INCLUDE_DIR +) + +# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the +# cache entries because they are meant to specify the location of a single +# library. We now set the variables listed by the documentation for this +# module. +set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") +set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") + +# These variables have been historically named in this module different from +# what SELECT_LIBRARY_CONFIGURATIONS() expects. +set(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}") +set(PYTHON_LIBRARY_RELEASE "${PYTHON_LIBRARY}") +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +SELECT_LIBRARY_CONFIGURATIONS(PYTHON) +# SELECT_LIBRARY_CONFIGURATIONS() sets ${PREFIX}_FOUND if it has a library. +# Unset this, this prefix doesn't match the module prefix, they are different +# for historical reasons. +unset(PYTHON_FOUND) + +# include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs + REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS + VERSION_VAR PYTHONLIBS_VERSION_STRING) + +# PYTHON_ADD_MODULE( src1 src2 ... srcN) is used to build modules for python. +# PYTHON_WRITE_MODULES_HEADER() writes a header file you can include +# in your sources to initialize the static python modules +function(PYTHON_ADD_MODULE _NAME ) + get_property(_TARGET_SUPPORTS_SHARED_LIBS + GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) + option(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE) + option(PYTHON_MODULE_${_NAME}_BUILD_SHARED + "Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS}) + + # Mark these options as advanced + mark_as_advanced(PYTHON_ENABLE_MODULE_${_NAME} + PYTHON_MODULE_${_NAME}_BUILD_SHARED) + + if(PYTHON_ENABLE_MODULE_${_NAME}) + if(PYTHON_MODULE_${_NAME}_BUILD_SHARED) + set(PY_MODULE_TYPE MODULE) + else() + set(PY_MODULE_TYPE STATIC) + set_property(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME}) + endif() + + set_property(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME}) + add_library(${_NAME} ${PY_MODULE_TYPE} ${ARGN}) +# target_link_libraries(${_NAME} ${PYTHON_LIBRARIES}) + + if(PYTHON_MODULE_${_NAME}_BUILD_SHARED) + set_target_properties(${_NAME} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") + if(WIN32 AND NOT CYGWIN) + set_target_properties(${_NAME} PROPERTIES SUFFIX ".pyd") + endif() + endif() + + endif() +endfunction() + +function(PYTHON_WRITE_MODULES_HEADER _filename) + + get_property(PY_STATIC_MODULES_LIST GLOBAL PROPERTY PY_STATIC_MODULES_LIST) + + get_filename_component(_name "${_filename}" NAME) + string(REPLACE "." "_" _name "${_name}") + string(TOUPPER ${_name} _nameUpper) + set(_filename ${CMAKE_CURRENT_BINARY_DIR}/${_filename}) + + set(_filenameTmp "${_filename}.in") + file(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n") + file(APPEND ${_filenameTmp} +"#ifndef ${_nameUpper} +#define ${_nameUpper} + +#include + +#ifdef __cplusplus +extern \"C\" { +#endif /* __cplusplus */ + +") + + foreach(_currentModule ${PY_STATIC_MODULES_LIST}) + file(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n") + endforeach() + + file(APPEND ${_filenameTmp} +"#ifdef __cplusplus +} +#endif /* __cplusplus */ + +") + + + foreach(_currentModule ${PY_STATIC_MODULES_LIST}) + file(APPEND ${_filenameTmp} "int ${_name}_${_currentModule}(void) \n{\n static char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n") + endforeach() + + file(APPEND ${_filenameTmp} "void ${_name}_LoadAllPythonModules(void)\n{\n") + foreach(_currentModule ${PY_STATIC_MODULES_LIST}) + file(APPEND ${_filenameTmp} " ${_name}_${_currentModule}();\n") + endforeach() + file(APPEND ${_filenameTmp} "}\n\n") + file(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n ${_name}_LoadAllPythonModules();\n}\n#endif\n\n#endif\n") + +# with configure_file() cmake complains that you may not use a file created using file(WRITE) as input file for configure_file() + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET) + +endfunction() diff --git a/build3/cmake/SelectLibraryConfigurations.cmake b/build3/cmake/SelectLibraryConfigurations.cmake new file mode 100644 index 000000000..dce6f9926 --- /dev/null +++ b/build3/cmake/SelectLibraryConfigurations.cmake @@ -0,0 +1,70 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#.rst: +# SelectLibraryConfigurations +# --------------------------- +# +# +# +# select_library_configurations( basename ) +# +# This macro takes a library base name as an argument, and will choose +# good values for basename_LIBRARY, basename_LIBRARIES, +# basename_LIBRARY_DEBUG, and basename_LIBRARY_RELEASE depending on what +# has been found and set. If only basename_LIBRARY_RELEASE is defined, +# basename_LIBRARY will be set to the release value, and +# basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND. +# If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will +# take the debug value, and basename_LIBRARY_RELEASE will be set to +# basename_LIBRARY_RELEASE-NOTFOUND. +# +# If the generator supports configuration types, then basename_LIBRARY +# and basename_LIBRARIES will be set with debug and optimized flags +# specifying the library to be used for the given configuration. If no +# build type has been set or the generator in use does not support +# configuration types, then basename_LIBRARY and basename_LIBRARIES will +# take only the release value, or the debug value if the release one is +# not set. + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro( select_library_configurations basename ) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) ) + # if the generator supports configuration types or CMAKE_BUILD_TYPE + # is set, then set optimized and debug options. + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/data/block.urdf b/data/block.urdf new file mode 100644 index 000000000..9ff64decf --- /dev/null +++ b/data/block.urdf @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/block_grasp_log.bin b/data/block_grasp_log.bin new file mode 100644 index 000000000..1bf3d5050 Binary files /dev/null and b/data/block_grasp_log.bin differ diff --git a/data/kuka_iiwa/kuka_with_gripper.sdf b/data/kuka_iiwa/kuka_with_gripper.sdf new file mode 100644 index 000000000..739eac349 --- /dev/null +++ b/data/kuka_iiwa/kuka_with_gripper.sdf @@ -0,0 +1,760 @@ + + + + + + + 0 0 0 0 -0 0 + + -0.1 0 0.07 0 -0 0 + 0 + + 0.05 + 0 + 0 + 0.06 + 0 + 0.03 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + /meshes/link_0.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_0.stl + + + + 1 0 0 1 + 0.5 0.5 0.5 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + 0 0 0.1575 0 -0 0 + + 0 -0.03 0.12 0 -0 0 + 4 + + 0.1 + 0 + 0 + 0.09 + 0 + 0.02 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_1.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_1.stl + + + + 1 0 0 1 + 0.5 0.5 0.5 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_1 + lbr_iiwa_link_0 + + 0 0 1 + + -2.96706 + 2.96706 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + 0 0 0.36 1.5708 -0 -3.14159 + + 0.0003 0.059 0.042 0 -0 0 + 4 + + 0.05 + 0 + 0 + 0.018 + 0 + 0.044 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_2.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_2.stl + + + + 1 0 0 1 + 1.0 0.42 0.04 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_2 + lbr_iiwa_link_1 + + 0 0 1 + + -2.0944 + 2.0944 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + 0 -0 0.5645 0 0 0 + + 0 0.03 0.13 0 -0 0 + 3 + + 0.08 + 0 + 0 + 0.075 + 0 + 0.01 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_3.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_3.stl + + + + 1 0 0 1 + 0.6 0.6 0.6 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_3 + lbr_iiwa_link_2 + + 0 0 1 + + -2.96706 + 2.96706 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + 0 -0 0.78 1.5708 0 0 + + 0 0.067 0.034 0 -0 0 + 2.7 + + 0.03 + 0 + 0 + 0.01 + 0 + 0.029 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_4.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_4.stl + + + + 1 0 0 1 + 0.6 0.6 0.6 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_4 + lbr_iiwa_link_3 + + 0 0 1 + + -2.0944 + 2.0944 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + 0 -0 0.9645 0 -0 -3.14159 + + 0.0001 0.021 0.076 0 -0 0 + 1.7 + + 0.02 + 0 + 0 + 0.018 + 0 + 0.005 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_5.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_5.stl + + + + 1 0 0 1 + 0.6 0.6 0.6 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_5 + lbr_iiwa_link_4 + + 0 0 1 + + -2.96706 + 2.96706 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + 0 0 1.18 1.5708 -0 -3.14159 + + 0 0.0006 0.0004 0 -0 0 + 1.8 + + 0.005 + 0 + 0 + 0.0036 + 0 + 0.0047 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_6.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_6.stl + + + + 1 0 0 1 + 1.0 0.42 0.04 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_6 + lbr_iiwa_link_5 + + 0 0 1 + + -2.0944 + 2.0944 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + 0 0 1.261 0 0 0 + + 0 0 0.02 0 -0 0 + 0.3 + + 0.001 + 0 + 0 + 0.001 + 0 + 0.001 + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_7.stl + + + + + 0 0 0 0 -0 0 + + + 1 1 1 + meshes/link_7.stl + + + + 1 0 0 1 + 0.6 0.6 0.6 1 + 0.1 0.1 0.1 1 + 0 0 0 0 + + + + + lbr_iiwa_link_7 + lbr_iiwa_link_6 + + 0 0 1 + + -3.05433 + 3.05433 + 300 + 10 + + + 0.5 + 0 + 0 + 0 + + + + + + + lbr_iiwa_link_7 + base_link + + + 0 0 1.305 0 -0 0 + + 0 0 0 0 -0 0 + 1.2 + + 1 + 0 + 0 + 1 + 0 + 1 + + + + 0 0 0 0 0 0 + + + 0.05 0.05 0.1 + + + + + + + base_link + left_finger + + 0 1 0 + + -0.4 + 0.01 + 100 + 0 + + + 0 + 0 + 0 + 0 + + + + + 0 0.024 1.35 0 -0.05 0 + + 0 0 0.04 0 0 0 + 0.1 + + 0.1 + 0 + 0 + 0.1 + 0 + 0.1 + + + + 0 0 0.04 0 0 0 + + + 0.01 0.01 0.08 + + + + + + left_finger + left_finger_base + + + -0.005 0.024 1.43 0 -0.3 0 + + -0.003 0 0.04 0 0 0 + 0.2 + + 0.1 + 0 + 0 + 0.1 + 0 + 0.1 + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_base_left.stl + + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_base_left.stl + + + + + + left_finger_base + left_finger_tip + + 0 1 0 + + -0.1 + 0.3 + 0 + 0 + + + 0 + 0 + 0 + 0 + + + + + + 0.8 + 1.0 + + -0.02 0.024 1.49 0 0.2 0 + + -0.005 0 0.026 0 0 0 + 0.2 + + 0.1 + 0 + 0 + 0.1 + 0 + 0.1 + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_tip_left.stl + + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_tip_left.stl + + + + + + base_link + right_finger + + 0 1 0 + + -0.01 + 0.4 + 100 + 0 + + + 0 + 0 + 0 + 0 + + + + + 0 0.024 1.35 0 0.05 0 + + 0 0 0.04 0 0 0 + 0.1 + + 0.1 + 0 + 0 + 0.1 + 0 + 0.1 + + + + 0 0 0.04 0 0 0 + + + 0.01 0.01 0.08 + + + + + + right_finger + right_finger_base + + + 0.005 0.024 1.43 0 0.3 0 + + 0.003 0 0.04 0 0 0 + 0.2 + + 0.1 + 0 + 0 + 0.1 + 0 + 0.1 + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_base_right.stl + + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_base_right.stl + + + + + + right_finger_base + right_finger_tip + + 0 1 0 + + -0.3 + 0.1 + 0 + 0 + + + 0 + 0 + 0 + 0 + + + + + + 0.8 + 1.0 + + 0.02 0.024 1.49 0 -0.2 0 + + 0.005 0 0.026 0 0 0 + 0.2 + + 0.1 + 0 + 0 + 0.1 + 0 + 0.1 + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_tip_right.stl + + + + + 0 0 0 0 0 0 + + + 1 1 1 + meshes/finger_tip_right.stl + + + + + + + diff --git a/data/kuka_iiwa/meshes/finger_base_left.stl b/data/kuka_iiwa/meshes/finger_base_left.stl new file mode 100755 index 000000000..4ef433272 Binary files /dev/null and b/data/kuka_iiwa/meshes/finger_base_left.stl differ diff --git a/data/kuka_iiwa/meshes/finger_base_right.stl b/data/kuka_iiwa/meshes/finger_base_right.stl new file mode 100755 index 000000000..0e7c91f14 Binary files /dev/null and b/data/kuka_iiwa/meshes/finger_base_right.stl differ diff --git a/data/kuka_iiwa/meshes/finger_tip_left.stl b/data/kuka_iiwa/meshes/finger_tip_left.stl new file mode 100755 index 000000000..2a258e339 Binary files /dev/null and b/data/kuka_iiwa/meshes/finger_tip_left.stl differ diff --git a/data/kuka_iiwa/meshes/finger_tip_right.stl b/data/kuka_iiwa/meshes/finger_tip_right.stl new file mode 100755 index 000000000..458f26b05 Binary files /dev/null and b/data/kuka_iiwa/meshes/finger_tip_right.stl differ diff --git a/data/tray/tray.urdf b/data/tray/tray.urdf new file mode 100755 index 000000000..06f596e8b --- /dev/null +++ b/data/tray/tray.urdf @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/tray/tray_textured4.mtl b/data/tray/tray_textured4.mtl new file mode 100755 index 000000000..1a2697882 --- /dev/null +++ b/data/tray/tray_textured4.mtl @@ -0,0 +1,13 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl None +Ns 0.000000 +Ka 0.000000 0.000000 0.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.800000 0.800000 0.800000 +Ke 0.000000 0.000000 0.000000 +Ni 1.000000 +d 1.000000 +illum 2 +#map_Kd tray.jpg diff --git a/data/tray/tray_textured4.obj b/data/tray/tray_textured4.obj new file mode 100755 index 000000000..a367c02cb --- /dev/null +++ b/data/tray/tray_textured4.obj @@ -0,0 +1,256 @@ +# Blender v2.77 (sub 0) OBJ File: '' +# www.blender.org +mtllib tray_textured5.mtl +o edge_2_Cube +v 0.593683 0.625721 0.255175 +v 0.406317 0.459389 0.004580 +v 0.576239 0.625721 0.266503 +v 0.593683 -0.580640 0.255175 +v 0.423761 0.459389 -0.006748 +v 0.576239 -0.580640 0.266503 +v 0.423761 -0.413369 -0.007320 +v 0.406317 -0.413369 0.004008 +vt 0.9410 0.8520 +vt 0.7523 0.8566 +vt 0.9234 0.8524 +vt 0.8896 0.1426 +vt 0.7698 0.8562 +vt 0.8721 0.1430 +vt 0.7185 0.1468 +vt 0.7009 0.1472 +vn -0.2561 0.8826 -0.3943 +vn 0.8394 0.0003 -0.5435 +vn 0.8390 0.0001 -0.5441 +vn 0.8389 0.0000 -0.5443 +vn -0.2569 -0.8818 -0.3956 +vn -0.8390 -0.0003 0.5441 +vn -0.8394 -0.0001 0.5436 +vn -0.8395 -0.0000 0.5434 +vn -0.5446 0.0005 -0.8387 +vn 0.5446 -0.0000 0.8387 +vn 0.8396 0.0004 -0.5433 +vn -0.8388 -0.0004 0.5444 +usemtl None +s 1 +f 1/1/1 2/2/1 3/3/1 +f 4/4/2 5/5/3 1/1/4 +f 6/6/5 7/7/5 4/4/5 +f 3/3/6 8/8/7 6/6/8 +f 5/5/9 8/8/9 2/2/9 +f 4/4/10 3/3/10 6/6/10 +f 1/1/1 5/5/1 2/2/1 +f 4/4/2 7/7/11 5/5/3 +f 6/6/5 8/8/5 7/7/5 +f 3/3/6 2/2/12 8/8/7 +f 5/5/9 7/7/9 8/8/9 +f 4/4/10 1/1/10 3/3/10 +o edge_3_Cube.002 +v 0.580000 -0.573309 0.261247 +v -0.419400 -0.409917 0.008678 +v -0.580000 -0.573309 0.261247 +v 0.580000 -0.590083 0.250354 +v 0.419883 -0.409917 0.009162 +v -0.580000 -0.590083 0.250354 +v 0.419883 -0.426691 -0.001731 +v -0.419400 -0.426691 -0.002215 +vt 0.8690 0.1040 +vt 0.1365 0.1739 +vt 0.0188 0.1040 +vt 0.8690 0.0968 +vt 0.7517 0.1739 +vt 0.0188 0.0968 +vt 0.7517 0.1668 +vt 0.1365 0.1668 +vn -0.0002 0.8392 0.5438 +vn -0.0000 0.8395 0.5433 +vn 0.0000 0.8396 0.5432 +vn 0.8825 0.2562 -0.3945 +vn 0.0002 -0.8396 -0.5433 +vn 0.0000 -0.8392 -0.5438 +vn 0.0000 -0.8391 -0.5439 +vn -0.8821 0.2565 -0.3950 +vn -0.8822 0.2565 -0.3950 +vn 0.0005 0.5446 -0.8387 +vn 0.0000 -0.5446 0.8387 +vn -0.0003 0.8391 0.5440 +vn 0.0003 -0.8397 -0.5430 +usemtl None +s 1 +f 9/9/13 10/10/14 11/11/15 +f 12/12/16 13/13/16 9/9/16 +f 14/14/17 15/15/18 12/12/19 +f 11/11/20 16/16/21 14/14/21 +f 13/13/22 16/16/22 10/10/22 +f 12/12/23 11/11/23 14/14/23 +f 9/9/13 13/13/24 10/10/14 +f 12/12/16 15/15/16 13/13/16 +f 14/14/17 16/16/25 15/15/18 +f 11/11/20 10/10/21 16/16/21 +f 13/13/22 15/15/22 16/16/22 +f 12/12/23 9/9/23 11/11/23 +o base_Cube.004 +v 0.417551 0.466622 0.009942 +v -0.417551 0.466622 -0.009942 +v -0.417551 0.466622 0.009942 +v 0.417551 -0.415378 0.009942 +v 0.417551 0.466622 -0.009942 +v -0.417551 -0.415378 0.009942 +v 0.417551 -0.415378 -0.009942 +v -0.417551 -0.415378 -0.009942 +vt 0.7524 0.8072 +vt -0.3038 0.8371 +vt -0.3038 0.8371 +vt 0.7012 0.1905 +vt 0.7524 0.8072 +vt -0.3550 0.2204 +vt 0.7012 0.1905 +vt -0.3550 0.2204 +vn 0.0000 1.0000 0.0000 +vn 1.0000 -0.0000 0.0000 +vn 0.0000 -1.0000 0.0000 +vn -1.0000 -0.0000 0.0000 +vn 0.0000 0.0000 -1.0000 +vn 0.0000 -0.0000 1.0000 +usemtl None +s 1 +f 17/17/26 18/18/26 19/19/26 +f 20/20/27 21/21/27 17/17/27 +f 22/22/28 23/23/28 20/20/28 +f 19/19/29 24/24/29 22/22/29 +f 21/21/30 24/24/30 18/18/30 +f 20/20/31 19/19/31 22/22/31 +f 17/17/26 21/21/26 18/18/26 +f 20/20/27 23/23/27 21/21/27 +f 22/22/28 24/24/28 23/23/28 +f 19/19/29 18/18/29 24/24/29 +f 21/21/30 23/23/30 24/24/30 +f 20/20/31 17/17/31 19/19/31 +o edge_4_Cube.001 +v -0.576397 0.631608 0.266791 +v -0.423603 0.464243 -0.007768 +v -0.593877 0.631608 0.255439 +v -0.576397 -0.577253 0.266791 +v -0.406123 0.464243 0.003584 +v -0.593877 -0.577253 0.255439 +v -0.406123 -0.409889 0.004087 +v -0.423603 -0.409889 -0.007265 +vt 0.9046 0.2397 +vt 0.7929 0.2434 +vt 0.9174 0.2393 +vt 0.9537 0.7559 +vt 0.7801 0.2438 +vt 0.9664 0.7554 +vt 0.8291 0.7599 +vt 0.8419 0.7595 +vn 0.2565 0.8821 -0.3950 +vn 0.8392 0.0002 0.5438 +vn 0.8395 0.0000 0.5433 +vn 0.8396 -0.0000 0.5432 +vn 0.2568 -0.8819 -0.3954 +vn -0.8396 -0.0002 -0.5433 +vn -0.8392 -0.0000 -0.5438 +vn -0.8391 0.0000 -0.5439 +vn 0.5446 -0.0005 -0.8387 +vn -0.5446 -0.0000 0.8387 +vn 0.8391 0.0003 0.5440 +vn -0.8397 -0.0003 -0.5430 +usemtl None +s 1 +f 25/25/32 26/26/32 27/27/32 +f 28/28/33 29/29/34 25/25/35 +f 30/30/36 31/31/36 28/28/36 +f 27/27/37 32/32/38 30/30/39 +f 29/29/40 32/32/40 26/26/40 +f 28/28/41 27/27/41 30/30/41 +f 25/25/32 29/29/32 26/26/32 +f 28/28/33 31/31/42 29/29/34 +f 30/30/36 32/32/36 31/31/36 +f 27/27/37 26/26/43 32/32/38 +f 29/29/40 31/31/40 32/32/40 +f 28/28/41 25/25/41 27/27/41 +o edge_5_Cube.005 +v -0.326052 0.623641 0.266072 +v -0.174054 0.457147 -0.007058 +v -0.343442 0.623641 0.254779 +v -0.326052 -0.578931 0.266072 +v -0.156664 0.457147 0.004235 +v -0.343442 -0.578931 0.254779 +v -0.156664 -0.412938 0.005326 +v -0.174054 -0.412938 -0.005967 +vt 0.0506 0.8517 +vt 0.1935 0.8492 +vt 0.0342 0.8520 +vt 0.0164 0.1914 +vt 0.2099 0.8489 +vt 0.0001 0.1917 +vt 0.1757 0.1886 +vt 0.1594 0.1889 +vn 0.2565 0.8821 -0.3950 +vn 0.8387 0.0005 0.5446 +vn 0.8394 0.0001 0.5434 +vn 0.8396 -0.0000 0.5432 +vn 0.2565 -0.8822 -0.3950 +vn -0.8395 -0.0005 -0.5434 +vn -0.8388 -0.0001 -0.5445 +vn -0.8386 0.0000 -0.5448 +vn 0.5446 -0.0011 -0.8387 +vn -0.5446 -0.0000 0.8387 +vn 0.8384 0.0007 0.5451 +vn -0.8398 -0.0007 -0.5429 +usemtl None +s 1 +f 33/33/44 34/34/44 35/35/44 +f 36/36/45 37/37/46 33/33/47 +f 38/38/48 39/39/48 36/36/48 +f 35/35/49 40/40/50 38/38/51 +f 37/37/52 40/40/52 34/34/52 +f 36/36/53 35/35/53 38/38/53 +f 33/33/44 37/37/44 34/34/44 +f 36/36/45 39/39/54 37/37/46 +f 38/38/48 40/40/48 39/39/48 +f 35/35/49 34/34/55 40/40/50 +f 37/37/52 39/39/52 40/40/52 +f 36/36/53 33/33/53 35/35/53 +o edge_1_Cube.003 +v 0.580000 0.640851 0.250354 +v -0.419960 0.477459 -0.001860 +v -0.580000 0.640851 0.250354 +v 0.580000 0.624077 0.261247 +v 0.420014 0.477459 -0.001059 +v -0.580000 0.624077 0.261247 +v 0.420014 0.460685 0.009834 +v -0.419960 0.460685 0.009033 +vt 0.8346 0.9187 +vt 0.2203 0.8574 +vt 0.1480 0.9187 +vt 0.8346 0.9129 +vt 0.7623 0.8574 +vt 0.1480 0.9129 +vt 0.7623 0.8511 +vt 0.2203 0.8511 +vn 0.0004 0.8386 -0.5448 +vn 0.0001 0.8391 -0.5439 +vn 0.0000 0.8393 -0.5437 +vn 0.8823 -0.2564 -0.3948 +vn -0.0004 -0.8392 0.5439 +vn -0.0001 -0.8386 0.5447 +vn 0.0000 -0.8385 0.5449 +vn -0.8826 -0.2560 -0.3942 +vn 0.0008 -0.5446 -0.8387 +vn 0.0000 0.5446 0.8387 +vn 0.0005 0.8383 -0.5452 +vn -0.0005 -0.8394 0.5435 +usemtl None +s 1 +f 41/41/56 42/42/57 43/43/58 +f 44/44/59 45/45/59 41/41/59 +f 46/46/60 47/47/61 44/44/62 +f 43/43/63 48/48/63 46/46/63 +f 45/45/64 48/48/64 42/42/64 +f 44/44/65 43/43/65 46/46/65 +f 41/41/56 45/45/66 42/42/57 +f 44/44/59 47/47/59 45/45/59 +f 46/46/60 48/48/67 47/47/61 +f 43/43/63 42/42/63 48/48/63 +f 45/45/64 47/47/64 48/48/64 +f 44/44/65 41/41/65 43/43/65 diff --git a/examples/pybullet/examples/kuka_grasp_block_playback.py b/examples/pybullet/examples/kuka_grasp_block_playback.py new file mode 100644 index 000000000..d22335975 --- /dev/null +++ b/examples/pybullet/examples/kuka_grasp_block_playback.py @@ -0,0 +1,91 @@ +import pybullet as p +import time +import math +from datetime import datetime +from numpy import * +from pylab import * +import struct +import sys +import os, fnmatch +import argparse +from time import sleep + +def readLogFile(filename, verbose = True): + f = open(filename, 'rb') + + print('Opened'), + print(filename) + + keys = f.readline().decode('utf8').rstrip('\n').split(',') + fmt = f.readline().decode('utf8').rstrip('\n') + + # The byte number of one record + sz = struct.calcsize(fmt) + # The type number of one record + ncols = len(fmt) + + if verbose: + print('Keys:'), + print(keys) + print('Format:'), + print(fmt) + print('Size:'), + print(sz) + print('Columns:'), + print(ncols) + + # Read data + wholeFile = f.read() + # split by alignment word + chunks = wholeFile.split(b'\xaa\xbb') + log = list() + for chunk in chunks: + if len(chunk) == sz: + values = struct.unpack(fmt, chunk) + record = list() + for i in range(ncols): + record.append(values[i]) + log.append(record) + + return log + +#clid = p.connect(p.SHARED_MEMORY) +p.connect(p.GUI) +p.loadSDF("kuka_iiwa/kuka_with_gripper.sdf") +p.loadURDF("tray/tray.urdf",[0,0,0]) +p.loadURDF("block.urdf",[0,0,2]) + +log = readLogFile("data/block_grasp_log.bin") + +recordNum = len(log) +itemNum = len(log[0]) +objectNum = p.getNumBodies() + +print('record num:'), +print(recordNum) +print('item num:'), +print(itemNum) + +def Step(stepIndex): + for objectId in range(objectNum): + record = log[stepIndex*objectNum+objectId] + Id = record[2] + pos = [record[3],record[4],record[5]] + orn = [record[6],record[7],record[8],record[9]] + p.resetBasePositionAndOrientation(Id,pos,orn) + numJoints = p.getNumJoints(Id) + for i in range (numJoints): + jointInfo = p.getJointInfo(Id,i) + qIndex = jointInfo[3] + if qIndex > -1: + p.resetJointState(Id,i,record[qIndex-7+17]) + + +stepIndexId = p.addUserDebugParameter("stepIndex",0,recordNum/objectNum-1,0) + +while True: + stepIndex = int(p.readUserDebugParameter(stepIndexId)) + Step(stepIndex) + p.stepSimulation() + Step(stepIndex) + diff --git a/examples/pybullet/examples/reset_dynamic_info.py b/examples/pybullet/examples/reset_dynamic_info.py index 0158f2e17..78d476a27 100644 --- a/examples/pybullet/examples/reset_dynamic_info.py +++ b/examples/pybullet/examples/reset_dynamic_info.py @@ -6,15 +6,15 @@ p.connect(p.GUI) planeId = p.loadURDF(fileName="plane.urdf",baseOrientation=[0.25882,0,0,0.96593]) p.loadURDF(fileName="cube.urdf",baseOrientation=[0.25882,0,0,0.96593],basePosition=[0,0,2]) cubeId = p.loadURDF(fileName="cube.urdf",baseOrientation=[0,0,0,1],basePosition=[0,0,4]) -p.changeDynamicsInfo(bodyUniqueId=2,linkIndex=-1,mass=0.1) -#p.changeDynamicsInfo(bodyUniqueId=2,linkIndex=-1,mass=100.0) +#p.changeDynamics(bodyUniqueId=2,linkIndex=-1,mass=0.1) +p.changeDynamics(bodyUniqueId=2,linkIndex=-1,mass=100.0) p.setGravity(0,0,-10) p.setRealTimeSimulation(0) t=0 while 1: t=t+1 if t > 400: - p.changeDynamicsInfo(bodyUniqueId=0,linkIndex=-1,lateralFriction=0.01) + p.changeDynamics(bodyUniqueId=0,linkIndex=-1,lateralFriction=0.01) mass1,frictionCoeff1=p.getDynamicsInfo(bodyUniqueId=planeId,linkIndex=-1) mass2,frictionCoeff2=p.getDynamicsInfo(bodyUniqueId=cubeId,linkIndex=-1) print mass1,frictionCoeff1 diff --git a/examples/pybullet/gym/agents/actor_net.py b/examples/pybullet/gym/agents/actor_net.py new file mode 100644 index 000000000..ac6aaff8a --- /dev/null +++ b/examples/pybullet/gym/agents/actor_net.py @@ -0,0 +1,21 @@ +"""An actor network.""" +import tensorflow as tf +import sonnet as snt + +class ActorNetwork(snt.AbstractModule): + """An actor network as a sonnet Module.""" + + def __init__(self, layer_sizes, action_size, name='target_actor'): + super(ActorNetwork, self).__init__(name=name) + self._layer_sizes = layer_sizes + self._action_size = action_size + + def _build(self, inputs): + state = inputs + for output_size in self._layer_sizes: + state = snt.Linear(output_size)(state) + state = tf.nn.relu(state) + + action = tf.tanh( + snt.Linear(self._action_size, name='action')(state)) + return action diff --git a/examples/pybullet/gym/agents/simplerAgent.py b/examples/pybullet/gym/agents/simpleAgent.py similarity index 95% rename from examples/pybullet/gym/agents/simplerAgent.py rename to examples/pybullet/gym/agents/simpleAgent.py index 4f12f04db..6588e73ba 100644 --- a/examples/pybullet/gym/agents/simplerAgent.py +++ b/examples/pybullet/gym/agents/simpleAgent.py @@ -10,11 +10,12 @@ import numpy as np import tensorflow as tf import pdb -class SimplerAgent(): +class SimpleAgent(): def __init__( self, session, ckpt_path, + actor_layer_size, observation_dim=31 ): self._ckpt_path = ckpt_path diff --git a/examples/pybullet/gym/agents/simpleAgentWithSonnet.py b/examples/pybullet/gym/agents/simpleAgentWithSonnet.py new file mode 100644 index 000000000..08a4cf1fa --- /dev/null +++ b/examples/pybullet/gym/agents/simpleAgentWithSonnet.py @@ -0,0 +1,46 @@ +"""Loads a DDPG agent without too much external dependencies +""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import collections +import numpy as np +import tensorflow as tf + +import sonnet as snt +from agents import actor_net + +class SimpleAgent(): + def __init__( + self, + session, + ckpt_path, + actor_layer_size, + observation_size=(31,), + action_size=8, + ): + self._ckpt_path = ckpt_path + self._actor_layer_size = actor_layer_size + self._observation_size = observation_size + self._action_size = action_size + self._session = session + self._build() + + def _build(self): + self._agent_net = actor_net.ActorNetwork(self._actor_layer_size, self._action_size) + self._obs = tf.placeholder(tf.float32, (31,)) + with tf.name_scope('Act'): + batch_obs = snt.nest.pack_iterable_as(self._obs, + snt.nest.map(lambda x: tf.expand_dims(x, 0), + snt.nest.flatten_iterable(self._obs))) + self._action = self._agent_net(batch_obs) + saver = tf.train.Saver() + saver.restore( + sess=self._session, + save_path=self._ckpt_path) + + def __call__(self, observation): + out_action = self._session.run(self._action, feed_dict={self._obs: observation}) + return out_action[0] diff --git a/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.data-00000-of-00001 b/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.data-00000-of-00001 new file mode 100644 index 000000000..b25aa2872 Binary files /dev/null and b/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.data-00000-of-00001 differ diff --git a/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.index b/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.index new file mode 100644 index 000000000..8abcb6ea5 Binary files /dev/null and b/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.index differ diff --git a/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.meta b/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.meta new file mode 100644 index 000000000..e1369a3d1 Binary files /dev/null and b/examples/pybullet/gym/data/agent/tf_graph_data/tf_graph_data.ckpt.meta differ diff --git a/examples/pybullet/gym/minitaurGymEnvTest.py b/examples/pybullet/gym/minitaurGymEnvTest.py index 3bbabd9a4..484842102 100644 --- a/examples/pybullet/gym/minitaurGymEnvTest.py +++ b/examples/pybullet/gym/minitaurGymEnvTest.py @@ -10,8 +10,15 @@ import numpy as np import tensorflow as tf from envs.bullet.minitaurGymEnv import MinitaurGymEnv -from agents import simplerAgent +try: + import sonnet + from agents import simpleAgentWithSonnet as agent_lib + ckpt_path = 'data/agent/tf_graph_data/tf_graph_data_converted.ckpt-0' +except ImportError: + from agents import simpleAgent as agent_lib + ckpt_path = 'data/agent/tf_graph_data/tf_graph_data.ckpt' + def testSinePolicy(): """Tests sine policy """ @@ -53,14 +60,14 @@ def testDDPGPolicy(): environment = MinitaurGymEnv(render=True) sum_reward = 0 steps = 1000 - ckpt_path = 'data/agent/tf_graph_data/tf_graph_data_converted.ckpt-0' + observation_shape = (31,) action_size = 8 - actor_layer_sizes = (100, 181) + actor_layer_size = (100, 181) n_steps = 0 tf.reset_default_graph() with tf.Session() as session: - agent = simplerAgent.SimplerAgent(session, ckpt_path) + agent = agent_lib.SimpleAgent(session=session, ckpt_path=ckpt_path, actor_layer_size=actor_layer_size) state = environment.reset() action = agent(state) for _ in range(steps):