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

Fix matplotlibcpp seg-fault with qpOASES #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs/
cmake-build-release/
cmake-build-debug/
cmake-build-relwithdebinfo/
tmp/
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@ set(CMAKE_CXX_FLAGS "-O3")
#set(CMAKE_CXX_FLAGS "-Wall -Os")
SET(CMAKE_BUILD_TYPE Release)

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h)

find_package(OsqpEigen)
find_package(Eigen3)

find_package(PythonLibs 3.8 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
include_directories(
include
third_party/cvxgen
third_party/qpOASES
third_party/qpOASES/include
/usr/include/python3.8
/usr/lib/python3.8/site-packages/numpy/core/include/
third_party/matplotlib-cpp
)

set(INCLUDE_DIRS
include
third_party/cvxgen
third_party/qpOASES
third_party/qpOASES/include
third_party/matplotlib-cpp # TODO learn why this is working and not include_directories
)

set(QUADPROG_SRCS
Expand All @@ -52,8 +54,9 @@ add_subdirectory(third_party)
set(CMAKE_BUILD_TYPE Debug)

add_library(nonlinear_controls ${CONTROL_SRCS} ${QUADPROG_SRCS})
target_link_libraries(nonlinear_controls qpOASES_cpp epigraph OsqpEigen::OsqpEigen ${PYTHON_LIBRARIES})
target_link_libraries(nonlinear_controls qpOASES epigraph OsqpEigen::OsqpEigen ${PYTHON_LIBRARIES})
target_include_directories(nonlinear_controls PUBLIC . ${INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(nonlinear_controls PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

# tests
add_executable(test_main tests/test_nlc.cpp)
Expand All @@ -69,4 +72,3 @@ target_link_libraries(osqpMPCExample nonlinear_controls)
add_executable(example_point_mass examples/mpc_point_mass.cpp)
target_link_libraries(example_point_mass nonlinear_controls)


2 changes: 1 addition & 1 deletion examples/mpc_point_mass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ void run_simulation(const int horizon, SOLVER_TYPE solve_type_) {
}

int main(int argc, char *argv[]) {

int N{5};
SOLVER_TYPE solver_type_{SOLVER_TYPE::EPIGRAPH};

Expand Down Expand Up @@ -194,3 +193,4 @@ int main(int argc, char *argv[]) {
std::cout << "N: " << N << " solver type " << int(solver_type_) << std::endl;
run_simulation(N, solver_type_);
}

2 changes: 0 additions & 2 deletions include/controls/mpc_qpoases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define _NONLINEAR_CONTROLS_MPC_QPOASES_HPP_

#include "common/qpoases_eigen.hpp"
#include <deque>
#include <vector>
#include "controls/linear_mpc.hpp"
#include "common/log.hpp"

Expand Down
8 changes: 6 additions & 2 deletions include/dynamics/point_mass.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#ifndef _NONLINEAR_CONTROLS_DYNAMICS_POINT_MASS_HPP_
#define _NONLINEAR_CONTROLS_DYNAMICS_POINT_MASS_HPP_

#include <eigen3/Eigen/Dense>
#include <iostream>
#include <vector>

//#include "nonlinear_controls.h"
#include "matplotlibcpp.h"

namespace nonlinear_controls {
namespace plt = matplotlibcpp;
namespace nonlinear_controls {

class PointMass3D {
public:
Expand Down Expand Up @@ -129,4 +132,5 @@ class PointMass3D {

};

}
} // namespace nonlinear controls
#endif // _NONLINEAR_CONTROLS_DYNAMICS_POINT_MASS_HPP_
26 changes: 26 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

mkdir tmp
cd tmp

git clone --recursive https://github.com/osqp/osqp
git clone --recursive https://github.com/embotech/ecos.git
git clone --recursive https://github.com/robotology/osqp-eigen.git

cd osqp
mkdir build && cd build
cmake -G "Unix Makefiles" ..
cmake --build .
sudo cmake --build . --target install

cd ../../ecos
mkdir build && cd build
cmake ..
make
sudo make install

cd ../../osqp-eigen
mkdir build && cd build
cmake ..
make
sudo make install
29 changes: 5 additions & 24 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
#add_subdirectory(qpOASES)
set(qpOASES_SRC_DIR qpOASES)
set(qpOASES_SRCS
${qpOASES_SRC_DIR}/src/BLASReplacement.cpp
${qpOASES_SRC_DIR}/src/Bounds.cpp
${qpOASES_SRC_DIR}/src/Constraints.cpp
${qpOASES_SRC_DIR}/src/Flipper.cpp
${qpOASES_SRC_DIR}/src/Indexlist.cpp
${qpOASES_SRC_DIR}/src/LAPACKReplacement.cpp
${qpOASES_SRC_DIR}/src/Matrices.cpp
${qpOASES_SRC_DIR}/src/MessageHandling.cpp
${qpOASES_SRC_DIR}/src/Options.cpp
${qpOASES_SRC_DIR}/src/OQPinterface.cpp
${qpOASES_SRC_DIR}/src/QProblemB.cpp
${qpOASES_SRC_DIR}/src/QProblem.cpp
${qpOASES_SRC_DIR}/src/SolutionAnalysis.cpp
${qpOASES_SRC_DIR}/src/SparseSolver.cpp
${qpOASES_SRC_DIR}/src/SQProblem.cpp
${qpOASES_SRC_DIR}/src/SQProblemSchur.cpp
${qpOASES_SRC_DIR}/src/SubjectTo.cpp
${qpOASES_SRC_DIR}/src/Utils.cpp
)
add_library(qpOASES_cpp ${qpOASES_SRCS})
target_include_directories(qpOASES_cpp PUBLIC . ${qpOASES_SRC_DIR}/include)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(QPOASES_AVOID_LA_NAMING_CONFLICTS ON)
add_subdirectory(qpOASES)

add_subdirectory(matplotlib-cpp)
include_directories(matplotlib-cpp)

set(ENABLE_OSQP TRUE)
Expand Down
2 changes: 1 addition & 1 deletion third_party/matplotlib-cpp
Submodule matplotlib-cpp updated 2 files
+2 −3 .gitignore
+10 −11 matplotlibcpp.h