Skip to content

Commit

Permalink
fixed python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ichumuh committed Oct 12, 2017
1 parent 0073425 commit ce525c4
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 3 deletions.
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ set(SRCS
src/Utils.cpp)
add_library(${PROJECT_NAME} ${SRCS})

set(qpOASES_PYTHON_SRC
interfaces/python/qpoases.pxd
interfaces/python/qpoases.pyx
)

#
# building example applications
#
Expand Down Expand Up @@ -73,3 +78,28 @@ install(DIRECTORY include/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.hpp"
PATTERN ".svn" EXCLUDE)

# the files listed above are present when qpoases_svn (i.e. getting source files) is completed
add_custom_command(OUTPUT ${qpOASES_SRC} ${qpOASES_PYTHON_SRC}
DEPENDS ${PROJECT_NAME})

# Custom build Python wrappers
add_custom_target(qpOASES_Python ALL
COMMAND python setup.py build_ext --include-dirs include ${INCLUDE_DIRECTORIES} --build-lib ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION} --build-temp ${CMAKE_CURRENT_BINARY_DIR} --sources ${qpOASES_PYTHON_SRC} ${SRCS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${PROJECT_NAME}
COMMENT "Building Python wrappers."
)

# Tell CMake about the build output
set(qpOASES_PYTHON_LIB
${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION}/qpoases.so
)

add_custom_command(OUTPUT ${qpOASES_PYTHON_LIB}
DEPENDS qpOASES_Python)

# Install
install(FILES ${qpOASES_PYTHON_LIB}
DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}
)
6 changes: 3 additions & 3 deletions interfaces/python/qpoases.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ cdef extern from "qpOASES/extras/SolutionAnalysis.hpp" namespace "qpOASES":
SolutionAnalysis(const SolutionAnalysis&)
# ~SolutionAnalysis()
# SolutionAnalysis& operator=(const SolutionAnalysis&)
returnValue getKktViolation(const QProblem*, const real_t*, const real_t*, const real_t*)
returnValue getKktViolation(const QProblemB*, const real_t*, const real_t*, const real_t*)
returnValue getKktViolation(const SQProblem*, const real_t*, const real_t*, const real_t*)
real_t getKktViolation(const QProblem*, const real_t*, const real_t*, const real_t*)
real_t getKktViolation(const QProblemB*, const real_t*, const real_t*, const real_t*)
real_t getKktViolation(const SQProblem*, const real_t*, const real_t*, const real_t*)
returnValue getVarianceCovariance(QProblem*, real_t*, real_t*)
returnValue getVarianceCovariance(QProblemB*, real_t*, real_t*)
returnValue getVarianceCovariance(SQProblem*, real_t*, real_t*)
Expand Down
79 changes: 79 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python
"""qpOASES python distutils setup script."""

#
# This file is part of qpOASES.
#
# qpOASES -- An Implementation of the Online Active Set Strategy.
# Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,
# Christian Kirches et al. All rights reserved.
#
# qpOASES is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# qpOASES is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with qpOASES; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

#
# Filename: setup.py
# Author: Sebastian F. Walter, Manuel Kudruss (thanks to Felix Lenders)
# Version: 3.2
# Date: 2013-2017
#

import sys
import numpy as np

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize

# HACK for passing source files via command line
sources_index = sys.argv.index('--sources')
sources = sys.argv[(sources_index + 1):]
sys.argv = sys.argv[:sources_index]

extra_params = {
'include_dirs': [
np.get_include()
],
'extra_compile_args': [
"-O2",
"-Wno-unused-variable",
"-Wall",
"-pedantic",
"-Wshadow",
"-Wfloat-equal",
"-O3",
"-Wconversion",
"-Wsign-conversion",
"-finline-functions",
"-fPIC",
"-DLINUX",
"-D__USE_LONG_INTEGERS__",
"-D__USE_LONG_FINTS__",
"-D__NO_COPYRIGHT__",
],
'extra_link_args': ["-Wl,--as-needed"],
'language': 'c++'
}

ext_modules = [
Extension("qpoases", sources, **extra_params),
]

setup(
name='qpOASES interface',
cmdclass={'build_ext': build_ext},
ext_modules=cythonize(ext_modules),
)

0 comments on commit ce525c4

Please sign in to comment.