robotology / osqp-eigen Goto Github PK
View Code? Open in Web Editor NEWSimple Eigen-C++ wrapper for OSQP library
Home Page: https://robotology.github.io/osqp-eigen/
License: BSD 3-Clause "New" or "Revised" License
Simple Eigen-C++ wrapper for OSQP library
Home Page: https://robotology.github.io/osqp-eigen/
License: BSD 3-Clause "New" or "Revised" License
I guess git clone --recursive
is now necessary.
Hi.
When I compile the MPC example, there appears lots of warnings.
The following is one of them.
/home/anzai/Library/osqp-eigen/example/src/MPCExample.cpp: In function ‘int main()’:
/home/anzai/Library/osqp-eigen/example/src/MPCExample.cpp:260:48: warning: ‘bool OsqpEigen::Data::setHessianMatrix(const Eigen::SparseMatrix<Scalar>&) [with T = double]’ is deprecated: Use setHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix) instead [-Wdeprecated-declarations]
if(!solver.data()->setHessianMatrix(hessian)) return 1;
What is the best way to cope with this warning?
And what is the best way to convert Eigen::Dense
matrix to Eigen::SparseCompressedBase
matrix?
Hi everyone,
osqp for cuda has been released for a year.
It provides python api and the backend is a branch of osqp main repo.
Any plan to support cuosqp?
thanks.
Some branches are out of date. The idea is to remove all the obsolete branches.
The following brenches will be removed:
devel_updated_matrices
;name_refactoring
;refactoring
.This is how I build the wrapper: (I am using windows btw)
git clone https://github.com/robotology/osqp-eigen.git
cd osqp-eigen
mkdir build && cd build
cmake ../
cmake --build . --config Debug
This is my CmakeLists.txt file:
cmake_minimum_required(VERSION "3.20.0")
project("-----")
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
find_package(osqp REQUIRED)
find_package(OsqpEigen REQUIRED PATHS "C:/Users/Dhruv/Documents/GitHub/osqp-eigen/build")
include_directories("C:/Users/Dhruv/Documents/mujoco200_win64/include")
link_directories("C:/Users/Dhruv/Documents/mujoco200_win64/bin")
add_executable("${PROJECT_NAME}" "main.cpp")
target_link_libraries("${PROJECT_NAME}"
mujoco200
mujoco200nogl
glfw3
glfw3static
Eigen3::Eigen
osqp::osqpstatic
# osqp::osqp
OsqpEigen::OsqpEigen)
I am able to compile and run the "osqp" example problems from their website. I am able to include the OsqpEigen.h in my project. When I just instantiate the solver using the wrapper, I am able to build and run the .exe but no output that I was expecting is generated. Just builds and runs with zero errors and nothing happens.
#include <iostream>
#include <Eigen/Core>
#include "osqp.h"
#include "OsqpEigen/OsqpEigen.h"
int main(void){
std::cout << "Hello1" << std::endl;
// instantiate the solver
OsqpEigen::Solver solver;
std::cout << "Hello2" << std::endl;
return 1;
}
Hi.
I'd like to get the dual solution (y), but couldn't find the API.
In Solver.hpp, there's getDualSolution
API which gives m_workspace->solution->x
.
I also want to get m_workspace->solution->y
.
Thanks!
@GiulioRomualdi can you forward merge master to devel? The Unstable branches of the superbuild seems to be broken otherwise: https://github.com/robotology/robotology-superbuild/runs/2091673792?check_suite_focus=true .
As pointed by @joaospinto in #16, it is not clear how the ownership of the optimization elements (matrices and vector) are handled.
As already explained in #16 (comment), osqp
itself stores the hessian and the constraint matrix into its data structure. While, on the other hand, the vectors are not saved inside the osqp library and so the user has to guarantee the existence of the objects (e.g. save as a member of the class). I think that this asymmetry may cause confusion and may be a source of error.
What do you think to save the gradient and the bounds inside the osqp-eigen?
cc @traversaro and @S-Dafarra
I can't build project when I add source code of osqp-eigen to my project. my .pro file is as follows:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = autocarwin
TEMPLATE = app
CONFIG+= c++11
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
INCLUDEPATH+=D:\eigen-3.3.7\Eigen
INCLUDEPATH+=D:\eigen-3.3.7
# INCLUDEPATH+=E:\00-Qt\VS\boost_build\include\boost-1_74
# LIBS += -LE:\00-Qt\VS\boost_build\lib
INCLUDEPATH += /usr/include/eigen3/Eigen
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
ivmapview.cpp \
ivview.cpp \
main.cpp \
mainwindow.cpp \
kd_tree.cpp \
mpc_control.cpp \
myview.cpp \
mpc.cpp \
Data.cpp \
Settings.cpp \
Solver.cpp
HEADERS += \
ivmapview.h \
ivview.h \
mainwindow.h \
kd_tree.h \
mpc_control.h \
modulecomm.h \
myview.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#LIBS += $$PWD/modulecomm1.lib
unix:LIBS += -L$$PWD/../../../bin/ -lmodulecomm
unix:LIBS += -L/usr/local/lib -lipopt
RESOURCES += \
pic.qrc
INCLUDEPATH +=D:\osqp\include
unix|win32: LIBS += -L$$PWD/./ -lmodulecomm1
INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/.
win32: LIBS += -L$$PWD/../../osqp/build/out/ -losqp
INCLUDEPATH += $$PWD/../../osqp/build/out
DEPENDPATH += $$PWD/../../osqp/build/out
INCLUDEPATH +=D:\osqp-eigen\include
D:\QT\5.6\mingw49_32\bin\qmake.exe -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" -o Makefile autocarwin.pro
D:/QT/Tools/mingw492_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'D:/project/autocarwin'
g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_XML_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I. -I..\..\eigen-3.3.7\Eigen -I..\..\eigen-3.3.7 -I/usr/include/eigen3/Eigen -I..\..\osqp\include -I. -I..\..\osqp\build\out -I..\..\osqp-eigen\include -I..\..\QT\5.6\mingw49_32\include -I..\..\QT\5.6\mingw49_32\include\QtWidgets -I..\..\QT\5.6\mingw49_32\include\QtGui -I..\..\QT\5.6\mingw49_32\include\QtANGLE -I..\..\QT\5.6\mingw49_32\include\QtXml -I..\..\QT\5.6\mingw49_32\include\QtCore -Idebug -I. -I..\..\QT\5.6\mingw49_32\mkspecs\win32-g++ -o debug\Data.o Data.cpp
g++ -Wl,-subsystem,windows -mthreads -o debug\autocarwin.exe object_script.autocarwin.Debug -lmingw32 -LD:\QT\5.6\mingw49_32\lib D:\QT\5.6\mingw49_32\lib\libqtmaind.a -lshell32 -LC:\utils\my_sql\my_sql\lib -LC:\utils\postgresql\pgsql\lib -LD:\project\autocarwin -lmodulecomm1 -LD:\osqp\build\out -losqp D:\QT\5.6\mingw49_32\lib\libQt5Widgetsd.a D:\QT\5.6\mingw49_32\lib\libQt5Guid.a D:\QT\5.6\mingw49_32\lib\libQt5Xmld.a D:\QT\5.6\mingw49_32\lib\libQt5Cored.a
./debug\mpc.o: In function `ZN9OsqpEigen18SparseMatrixHelper22createOsqpSparseMatrixIN5Eigen12SparseMatrixIdLi0EiEEEEbRKNS2_20SparseCompressedBaseIT_EERP3csc':
D:\project\autocarwin/../../osqp-eigen/include/OsqpEigen/SparseMatrixHelper.tpp:32: undefined reference to `csc_spalloc'
./debug\Data.o: In function `ZN9OsqpEigen4Data18clearHessianMatrixEv':
D:\project\autocarwin/Data.cpp:49: undefined reference to `csc_spfree'
./debug\Data.o: In function `ZN9OsqpEigen4Data28clearLinearConstraintsMatrixEv':
D:\project\autocarwin/Data.cpp:58: undefined reference to `csc_spfree'
./debug\Settings.o: In function `ZN9OsqpEigen8SettingsC2Ev':
D:\project\autocarwin/Settings.cpp:16: undefined reference to `osqp_set_default_settings'
./debug\Settings.o: In function `ZN9OsqpEigen8Settings20resetDefaultSettingsEv':
D:\project\autocarwin/Settings.cpp:26: undefined reference to `osqp_set_default_settings'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver20OSQPWorkspaceDeleterEP13OSQPWorkspace':
D:\project\autocarwin/Solver.cpp:18: undefined reference to `osqp_cleanup'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver10initSolverEv':
D:\project\autocarwin/Solver.cpp:90: undefined reference to `osqp_setup'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver5solveEv':
D:\project\autocarwin/Solver.cpp:124: undefined reference to `osqp_solve'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver14updateGradientERKN5Eigen3RefIKNS1_6MatrixIdLin1ELi1ELi0ELin1ELi1EEELi0ENS1_11InnerStrideILi1EEEEE':
D:\project\autocarwin/Solver.cpp:184: undefined reference to `osqp_update_lin_cost'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver16updateLowerBoundERKN5Eigen3RefIKNS1_6MatrixIdLin1ELi1ELi0ELin1ELi1EEELi0ENS1_11InnerStrideILi1EEEEE':
D:\project\autocarwin/Solver.cpp:202: undefined reference to `osqp_update_lower_bound'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver16updateUpperBoundERKN5Eigen3RefIKNS1_6MatrixIdLin1ELi1ELi0ELin1ELi1EEELi0ENS1_11InnerStrideILi1EEEEE':
D:\project\autocarwin/Solver.cpp:221: undefined reference to `osqp_update_upper_bound'
./debug\Solver.o: In function `ZN9OsqpEigen6Solver12updateBoundsERKN5Eigen3RefIKNS1_6MatrixIdLin1ELi1ELi0ELin1ELi1EEELi0ENS1_11InnerStrideILi1EEEEESA_':
D:\project\autocarwin/Solver.cpp:247: undefined reference to `osqp_update_bounds'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [debug\autocarwin.exe] Error 1
mingw32-make: *** [debug] Error 2
Makefile.Debug:102: recipe for target 'debug\autocarwin.exe' failed
mingw32-make[1]: Leaving directory 'D:/project/autocarwin'
makefile:34: recipe for target 'debug' failed
11:37:44: 进程"D:\QT\Tools\mingw492_32\bin\mingw32-make.exe"退出,退出代码 2 。
Error while building/deploying project autocarwin (kit: Desktop Qt 5.6.2 MinGW 32bit)
When executing step "Make"
Currently, there are hard coded unconditional error messages using std::cerr
which cannot be disabled. It would be great if it would be possible to disable them, or perhaps define your own log callback which is invoked to print the messages. This would allow an application using osqp-eigen
to incorporate these error messages in whatever logging framework it prefers.
This is the error I get:
[ 28%] Built target OsqpEigen
Scanning dependencies of target MPCUpdateMatricesTest
[ 35%] Building CXX object tests/CMakeFiles/MPCUpdateMatricesTest.dir/MPCUpdateMatricesTest.cpp.o
In file included from /home/sdafarra/Software/googletest/build/install/include/gtest/gtest.h:62,
from /home/sdafarra/Software/robotology-superbuild/robotology/OsqpEigen/tests/MPCUpdateMatricesTest.cpp:9:
/home/sdafarra/Software/googletest/build/install/include/gtest/internal/gtest-internal.h:1402:53: error: static assertion failed: test_name must not be empty
1402 | static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/home/sdafarra/Software/googletest/build/install/include/gtest/gtest.h:2339:3: note: in expansion of macro ‘GTEST_TEST_’
2339 | GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \
| ^~~~~~~~~~~
/home/sdafarra/Software/googletest/build/install/include/gtest/gtest.h:2345:42: note: in expansion of macro ‘GTEST_TEST’
2345 | #define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)
| ^~~~~~~~~~
/home/sdafarra/Software/robotology-superbuild/robotology/OsqpEigen/tests/MPCUpdateMatricesTest.cpp:186:1: note: in expansion of macro ‘TEST’
186 | TEST(MPCTest,)
| ^~~~
make[2]: *** [tests/CMakeFiles/MPCUpdateMatricesTest.dir/build.make:63: tests/CMakeFiles/MPCUpdateMatricesTest.dir/MPCUpdateMatricesTest.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:943: tests/CMakeFiles/MPCUpdateMatricesTest.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
I am on Ubuntu 20.04.
Hi.
I installed osqp
from source as described here. Then, I installed osqp-eigen
. I installed both system wide.
I am using catkin build
to build my applications. In my CMakeLists.txt, I set the following,
find_package(OsqpEigen)
find_package(osqp REQUIRED)
I use the following include in my header file
#include "OsqpEigen/OsqpEigen.h"
When I try to compile, I get
osqp.h: No such file or directory #include <osqp.h>
Any advice on how to solve this issue?
Thanks.
osqp-eigen
is not compatible with the latest version of osqp
(0.6.0) osqp/osqp#170
The incompatibility is caused by the following two commits:
osqp_setup
now returns an exit flag instead of OSQPWorkspace*
diff --git a/include/osqp.h b/include/osqp.h
index 4a25388f..8ced8cac 100644
--- a/include/osqp.h
+++ b/include/osqp.h
@@ -50,12 +50,12 @@ void osqp_set_default_settings(OSQPSettings *settings);
* NB: This is the only function that allocates dynamic memory and is not used
*during code generation
*
+ * @param work Solver workspace
* @param data Problem data
* @param settings Solver settings
- * @return Solver environment
+ * @return Exitflag for errors (0 if no errors)
*/
-OSQPWorkspace* osqp_setup(const OSQPData *data,
- OSQPSettings *settings);
+c_int osqp_setup(OSQPWorkspace** work, const OSQPData* data, const OSQPSettings* settings);
# endif // #ifndef EMBEDDED
osqp
now accepts only upper triangular Hessian matricesdiff --git a/src/osqp.c b/src/osqp.c
index c5508f0f..1d4ef186 100644
--- a/src/osqp.c
+++ b/src/osqp.c
@@ -111,7 +111,7 @@ c_int osqp_setup(OSQPWorkspace** work, const OSQPData *data, const OSQPSettings
(*work)->data = c_malloc(sizeof(OSQPData));
(*work)->data->n = data->n; // Number of variables
(*work)->data->m = data->m; // Number of linear constraints
- (*work)->data->P = csc_to_triu(data->P); // Cost function matrix
+ (*work)->data->P = copy_csc_mat(data->P); // Cost function matrix
(*work)->data->q = vec_copy(data->q, data->n); // Linear part of cost function
(*work)->data->A = copy_csc_mat(data->A); // Linear constraints matrix
(*work)->data->l = vec_copy(data->l, data->m); // Lower bounds on constraints
In file included from /usr/local/include/OsqpEigen/OsqpEigen.h:10:0,
from /home/ruoyo/car/nav_ws/src/trajectory_planning/src/hard_constrained/trajectory_corridor-based.cpp:6:
/usr/local/include/OsqpEigen/Constants.hpp:12:10: fatal error: osqp.h: No such file or directory
#include <osqp.h>
^~~~~~~~
compilation terminated.
CMakeFiles/CTG.dir/build.make:62: recipe for target 'CMakeFiles/CTG.dir/src/hard_constrained/trajectory_corridor-based.cpp.o' failed
make[3]: *** [CMakeFiles/CTG.dir/src/hard_constrained/trajectory_corridor-based.cpp.o] Error 1
CMakeFiles/Makefile2:2278: recipe for target 'CMakeFiles/CTG.dir/all' failed
make[2]: *** [CMakeFiles/CTG.dir/all] Error 2
CMakeFiles/Makefile2:233: recipe for target 'CMakeFiles/main.dir/rule' failed
make[1]: *** [CMakeFiles/main.dir/rule] Error 2
Makefile:175: recipe for target 'main' failed
make: *** [main] Error 2
CMakeFiles/main.dir/main.cpp.o:in the function‘testQP()’:
main.cpp:(.text+0x5b5):for‘OsqpEigen::Solver::Solver()’an undefined reference
CMakeFiles/main.dir/main.cpp.o:in the function‘std::default_deleteOsqpEigen::Settings::operator()(OsqpEigen::Settings*) const’:
main.cpp:(.text.ZNKSt14default_deleteIN9OsqpEigen8SettingsEEclEPS1[ZNKSt14default_deleteIN9OsqpEigen8SettingsEEclEPS1]+0x1e):‘OsqpEigen::Settings::~Settings()’an undefined reference
CMakeFiles/main.dir/main.cpp.o:in the function‘std::default_deleteOsqpEigen::Data::operator()(OsqpEigen::Data*) const’:
main.cpp:(.text.ZNKSt14default_deleteIN9OsqpEigen4DataEEclEPS1[ZNKSt14default_deleteIN9OsqpEigen4DataEEclEPS1]+0x1e):‘OsqpEigen::Data::~Data()’an undefined reference
collect2: error: ld returned 1 exit status
src/CMakeFiles/main.dir/build.make:120: recipe for target '../bin/main' failed
make[2]: *** [../bin/main] Error 1
CMakeFiles/Makefile2:85: recipe for target 'src/CMakeFiles/main.dir/all' failed
make[1]: *** [src/CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The option BUILD_TESTING
should be OFF
by default (https://github.com/robotology/osqp-eigen/blob/master/CMakeLists.txt#L110) in order to avoid cmake
errors when compiling from a clean setup where GTEST
suite is not installed.
Hi, I've just installed osqp-eigen and tried to run the example, which compiles fine but does not run.
In particular I get a segmentation fault when calling
solver.initSolver()
on line
osqp-eigen/example/src/MPCExample.cpp
Line 267 in 64cfeb6
My system is based on Ubuntu 20.04 with osqp version 0.6.2 installed from source.
Running the tests i get
Running tests...
Test project /home/tom/osqp-eigen/build
Start 1: SparseMatrixUnitTests
1/5 Test #1: SparseMatrixUnitTests ............ Passed 0.00 sec
Start 2: QPUnitTests
2/5 Test #2: QPUnitTests ......................***Exception: SegFault 0.22 sec
Start 3: UpdateMatricesUnitTests
3/5 Test #3: UpdateMatricesUnitTests ..........***Exception: SegFault 0.20 sec
Start 4: MPCUnitTests
4/5 Test #4: MPCUnitTests .....................***Exception: SegFault 0.21 sec
Start 5: MPCUpdateMatricesUnitTests
5/5 Test #5: MPCUpdateMatricesUnitTests .......***Exception: SegFault 0.21 sec
20% tests passed, 4 tests failed out of 5
Total Test time (real) = 0.85 sec
The following tests FAILED:
2 - QPUnitTests (SEGFAULT)
3 - UpdateMatricesUnitTests (SEGFAULT)
4 - MPCUnitTests (SEGFAULT)
5 - MPCUpdateMatricesUnitTests (SEGFAULT)
Errors while running CTest
make: *** [Makefile:107: test] Error 8
Do you have any pointers where I did something wrong or if there is a problem with osqp-eigen?
Thanks in advance.
osqp-eigen can be now easily installed using coda
conda install -c robotology osqp-eigen
Since osqp
(please check here) is already provided in conda-forge
and osqp-eigen
is not only used by the robotology
community, I think it makes sense to move the receipt in conda-forge
.
cc @traversaro
Scanning dependencies of target OsqpEigen
[ 40%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Data.cpp.o
[ 40%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Settings.cpp.o
[ 60%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o
[ 80%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Debug.cpp.o
In file included from /home/rgs/Downloads/osqp_e/osqp-eigen/src/Settings.cpp:8:0:
/home/rgs/Downloads/osqp_e/osqp-eigen/include/OsqpEigen/Settings.hpp:92:105: warning: ‘deprecated’ attribute directive ignored [-Wattributes]
[[deprecated("Use setMaxIteration(int) instead.")]] void setMaxIteraction(const int maxIteration);
^
In file included from /home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:10:0:
/home/rgs/Downloads/osqp_e/osqp-eigen/include/OsqpEigen/Settings.hpp:92:105: warning: ‘deprecated’ attribute directive ignored [-Wattributes]
[[deprecated("Use setMaxIteration(int) instead.")]] void setMaxIteraction(const int maxIteration);
^
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp: In constructor ‘OsqpEigen::Solver::Solver()’:
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:24:18: error: ‘make_unique’ is not a member of ‘std’
m_settings = std::make_uniqueOsqpEigen::Settings();
^
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:24:54: error: expected primary-expression before ‘>’ token
m_settings = std::make_uniqueOsqpEigen::Settings();
^
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:24:56: error: expected primary-expression before ‘)’ token
m_settings = std::make_uniqueOsqpEigen::Settings();
^
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:25:14: error: ‘make_unique’ is not a member of ‘std’
m_data = std::make_uniqueOsqpEigen::Data();
^
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:25:46: error: expected primary-expression before ‘>’ token
m_data = std::make_uniqueOsqpEigen::Data();
^
/home/rgs/Downloads/osqp_e/osqp-eigen/src/Solver.cpp:25:48: error: expected primary-expression before ‘)’ token
m_data = std::make_uniqueOsqpEigen::Data();
^
CMakeFiles/OsqpEigen.dir/build.make:88: recipe for target 'CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o' failed
make[2]: *** [CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o] Error 1
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/OsqpEigen.dir/all' failed
make[1]: *** [CMakeFiles/OsqpEigen.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
I built this project on Ubuntu 16.04, gcc:4.8.5, cmake version 3.15.0-rc2, while osqp version is v0.6.2(latest for the moment).
Really appreciate your help.
I'm trying to build the tests and I'm getting this error:
[build] ~/osqp-eigen/tests/MPCUpdateMatricesTest.cpp:153:26: error: ‘OSQPWrapper’ has not been declared
[build] bool updateHessianMatrix(OSQPWrapper::OptimizerSolver &solver,
[build] ^~~~~~~~~~~
I can't find any mention of OSQPWrapper in this repo or in osqp.
I also had to change #include <osqp.h>
to #include <osqp/osqp.h>
everywhere in order to get it to build.
When I run the example MPCExample.cpp
it has an error: Segmentation fault (core dumped).
Then I debug the program, it shows the error in the following lines.
solver.settings()->setWarmStart(true);
how to solve the issue? Thanks a lot.
When I make the project,I got this :
make: No targets specified and no makefile found.
but cmake is ok.
The C compiler identification is MSVC 18.0.21005.1
The CXX compiler identification is MSVC 18.0.21005.1
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: D:/360Downloads/Software/VS2013/VC/bin/x86_amd64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: D:/360Downloads/Software/VS2013/VC/bin/x86_amd64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done
Generating done
I know what error means, but I don't know why it's happening.
Here is an example of my up/lo bounds (they are a lot bigger than this example but somewhat similar in composition). In a class constructor, I prepare two matrices and fill them with data that is constant (RES
= reserved for later):
lo_bound = [RES, RES, 0, 0, -pi/2, -inf, -inf, -pi/2]
up_bound = [RES, RES, 0, 0, pi/2, inf, inf, pi/2]
Before every new solving step, I update RES
to the current condition. Identical values in both bounds, for example, let's say:
lo_bound = [0.2, -1.4, 0, 0, -pi/2, -inf, -inf, -pi/2]
up_bound = [0.2, -1.4, 0, 0, pi/2, inf, inf, pi/2]
After that, I call:
solver.updateLowerBound(lo_bound_);
solver.updateUpperBound(up_bound_);
And in every step, I get the same error, even though every value in up_bound
is equal or greater than lo_bound
(I even update lo_bound
before up_bound
, so it cannot say that new up_bound
is lower than previous lo_bound
)
If it's needed, I can paste here real lo/up bounds from my app
When compiling the mpc example using VS2013 on Win10, the following error occurred.
fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1325)
...
After some testing I found that it seems to be a problem with the template parsing for functions of the following form.
template<int n> ret_type some_function(Eigen::Matrix<c_float, n, 1>& arg)
This could be remedied by changing the definition to the following.
template<class T, int n> ret_type some_function(Eigen::Matrix<T, n, 1>& arg)
For example, in Data.hpp & Data.tpp, there is a function called setGradient. The current version and the suggested revised version are as follows.
/*current*/ template<int n> bool Data::setGradient(Eigen::Matrix<c_float, n, 1>& gradient)
/*suggest*/ template<class T, int n> bool Data::setGradient(Eigen::Matrix<T, n, 1>& gradient)
Below are all the functions I found to have the same problems.
For Data.hpp & Data.tpp
template<int n> bool Data::setGradient(Eigen::Matrix<c_float, n, 1>& gradientVector);
template<int m> bool setLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBoundVector);
template<int m> bool setUpperBound(Eigen::Matrix<c_float, m, 1>& upperBoundVector);
For Solver.hpp & Solver.tpp
template<int n> bool updateGradient(Eigen::Matrix<c_float, n, 1>& gradient);
template<int m> bool updateLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBound);
template<int m> bool updateUpperBound(Eigen::Matrix<c_float, m, 1>& upperBound);
template<int m> bool updateBounds(Eigen::Matrix<c_float, m, 1>& lowerBound, Eigen::Matrix<c_float, m, 1>& upperBound);
It would be nice if someone could help fix all the definitions.
Thx~
Hi dear developers, I met the following error when I am working on a MPC problem with osqp-eigen. I followed the example to build the QP problem.
error: ‘bool OsqpEigen::Data::setHessianMatrix(const Eigen::SparseMatrix<Scalar>&) [with T = double]’ is deprecated: Use setHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix) instead [-Werror=deprecated-declarations]
if (!solver.data()->setHessianMatrix(Hessian_)) {
Do you know why I get this error?
master branch fails with the following error:
robotology-superbuild/robotology/OsqpEigen/src/Solver.cpp:82:8: error: no matching function for call to 'osqp_setup'
if(osqp_setup(&workspace, m_data->getData(),
^~~~~~~~~~
robotology-superbuild/build/install/include/osqp/osqp.h:57:16: note: candidate function not viable: requires 2 arguments, but 3 were provided
OSQPWorkspace* osqp_setup(const OSQPData *data,
^
1 error generated.
I followed the installation instructions in the README and have pointed cmake to the install directory:
export OsqpEigen_DIR=/usr/local/lib/cmake/OsqpEigen/
In my cmake I have:
find_package(OSQPEigen REQUIRED)
...
target_link_libraries(${PROJECT_NAME}_bin osqp::osqp)
target_link_libraries(${PROJECT_NAME}_bin OSQPEigen::OSQPEigen)
but it tells me the target "OSQPEigen::OSQPEigen" was not found.
I am using MacOS 10.15.1
iter objective pri res dua res rho time
1 0.0000e+00 1.00e+00 1.40e+12 1.00e-01 4.63e-04s
200 1.2286e+11 2.24e+00 9.29e+10 5.14e-01 1.47e-03s
400 1.1636e+11 2.24e+00 2.62e+11 2.91e+00 2.34e-03s
600 1.2547e+11 2.24e+00 9.66e+10 2.91e+00 3.17e-03s
800 1.1924e+11 2.24e+00 2.94e+11 2.91e+00 3.97e-03s
975 1.0000e+20 2.24e+00 3.04e+11 2.91e+00 4.68e-03s
status: primal infeasible
number of iterations: 975
run time: 4.70e-03s
optimal rho estimate: 4.29e+00
[OsqpEigen::Solver::solve] The solution is unfeasible.
Since the current GNU/Linux distribution supported by Travis is outdated (Ubuntu Trusty), we should update the Travis script to test the library on Ubuntu Xenial or Bionic via docker.
Related to robotology/robotology-superbuild#96
The first error is the following
t searching for unused variables given on the command line.
loading initial cache file /home/sdafarra/Software/robotology-superbuild/build/robotology/iDynTree/CMakeFiles/YCMTmp/iDynTree-cache-Release.cmake
-- Found Eigen3: /usr/include/eigen3 (Required is at least version "3.2.92")
-- Found YARP: /home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.3.2+43-20200411.3+gita33cf54b1")
-- Found YARP: /home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.3.2+43-20200411.3+gita33cf54b1")
-- Using iCub from install
-- Found YARP: /home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.3.2+43-20200411.3+gita33cf54b1")
CMake Error at /usr/share/cmake-3.16/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
By not providing "FindEigen.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Eigen", but
CMake did not find one.
Could not find a package configuration file provided by "Eigen" with any of
the following names:
EigenConfig.cmake
eigen-config.cmake
Add the installation prefix of "Eigen" to CMAKE_PREFIX_PATH or set
"Eigen_DIR" to a directory containing one of the above files. If "Eigen"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
/home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/OsqpEigen/OsqpEigenConfig.cmake:23 (find_dependency)
cmake/iDynTreeDependencies.cmake:51 (find_package)
cmake/iDynTreeDependencies.cmake:91 (idyntree_handle_dependency)
CMakeLists.txt:43 (include)
-- Configuring incomplete, errors occurred!
See also "/home/sdafarra/Software/robotology-superbuild/build/robotology/iDynTree/CMakeFiles/CMakeOutput.log".
make[2]: *** [CMakeFiles/iDynTree.dir/build.make:104: robotology/iDynTree/CMakeFiles/YCMStamp/iDynTree-configure] Error 1
make[1]: *** [CMakeFiles/Makefile2:1108: CMakeFiles/iDynTree.dir/all] Error 2
make: *** [Makefile:95: all] Error 2
which can be easily solved by changing https://github.com/robotology/osqp-eigen/blob/devel/CMakeLists.txt#L110
to
list(APPEND OSQP_EIGEN_EXPORTED_DEPENDENCIES osqp Eigen3)
but if I try to compile again I get the following error
[ 25%] Performing configure step for 'iDynTree'
Not searching for unused variables given on the command line.
loading initial cache file /home/sdafarra/Software/robotology-superbuild/build/robotology/iDynTree/CMakeFiles/YCMTmp/iDynTree-cache-Release.cmake
-- Found YARP: /home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.3.2+43-20200411.3+gita33cf54b1")
-- Found YARP: /home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.3.2+43-20200411.3+gita33cf54b1")
-- Using iCub from install
-- Found YARP: /home/sdafarra/Software/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.3.2+43-20200411.3+gita33cf54b1")
-- Found Eigen3: /usr/include/eigen3 (Required is at least version "2.91.0")
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
available. Run "cmake --help-policy CMP0072" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
FindOpenGL found both a legacy GL library:
OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so
and GLVND libraries for OpenGL and GLX:
OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so
OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
src/visualization/CMakeLists.txt:63 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
CMake Error at src/optimalcontrol/CMakeLists.txt:107 (add_library):
Target "idyntree-optimalcontrol" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at src/optimalcontrol/CMakeLists.txt:107 (add_library):
Target "idyntree-optimalcontrol" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
make[2]: *** [CMakeFiles/iDynTree.dir/build.make:104: robotology/iDynTree/CMakeFiles/YCMStamp/iDynTree-configure] Error 1
make[1]: *** [CMakeFiles/Makefile2:1108: CMakeFiles/iDynTree.dir/all] Error 2
make: *** [Makefile:95: all] Error 2
It seems weird since Eigen3::Eigen
should be added when finding Eigen3
.
Content to be added, opening it just as a remainder.
When writing a class that encapsulates the use of this library in my codebase, I noticed that I had to store all matrices/vectors as private variables, otherwise some of the pointers would become stale (your library does not seem to be taking ownership of those matrices/vectors). Is this intended? Took me a while to figure this out.
Also, the way you pass Eigen
objects around seems a bit unorthodox. You may want to read this.
I send a PR #25 and it was merged into devel
, but now I couldn't find it in devel
and master
.
I'm trying to compile the repository on Windows and seems that the cmake is not able to find Eigen3
. I think that the problem can be easily solved by adding FindEigen3.cmake
in the cmake folder
https://github.com/robotology/osqp-eigen/blob/master/include/OsqpEigen/Solver.hpp
The move constructor of class Solver is implicitly deleted.
Therefore the instance of Solver is unable to move.
Is there any reason of forbidding move operation?
If no, can I add default move constructor?
make
Scanning dependencies of target OsqpEigen
[ 25%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Data.cpp.o
[ 50%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Settings.cpp.o
[ 75%] Building CXX object CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o
/home/ruoyo/Apps/osqp-eigen/src/Solver.cpp: In member function ‘bool OsqpEigen::Solver::initSolver()’:
/home/ruoyo/Apps/osqp-eigen/src/Solver.cpp:83:44: error: cannot convert ‘OSQPWorkspace**’ to ‘const OSQPData*’ for argument ‘1’ to ‘OSQPWorkspace* osqp_setup(const OSQPData*, OSQPSettings*)’
m_settings->getSettings()) != 0 ){
^
CMakeFiles/OsqpEigen.dir/build.make:110: recipe for target 'CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o' failed
make[2]: *** [CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/OsqpEigen.dir/all' failed
make[1]: *** [CMakeFiles/OsqpEigen.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
how to set the initial value replacing the defaule default value
Hello.
I've hit a roadblock of sorts with this library. Usecase is following, I've implemented an MPC controller as a library and tested it with an ideal plant written in C++ (no noise, ideal delay, etc), and everything works fine. But for a more real use-case, we have a Simulink model so I've written s-function level 2 wrapper for the MPC controller. Every time I run the simulation, it works fine, but for some reason, Matlab hangs at the end of the simulation (or earlier if I hit stop). No error is given and the only way to recover is to kill the Matlab process and run everything from begging.
After a few hours of trying to find the source of the problem by commenting out everything and then block by block uncommenting and testing, I've narrowed it down to two lines:
solver.updateHessianMatrix(P_);
solver.updateLinearConstraintsMatrix(A_);
If I comment out both of them, Matlab behaves normally (except, MPC is useless without them)
P.S. updating bounds does not result in freeze:
solver.updateBounds(lo_bound_, up_bound_);
P.P.S.
we have already implemented and tested similar things with osqp and Matlab, but now we wanted to use Eigen wrapper since a lot of our data is in Eigen classes
This is is not to point out a real issue, but more a heads up and to verify with you, @GiulioRomualdi , @traversaro , that we are doing the same thing when selecting a given commit of a repo containing git submodules. Let's consider the example of https://github.com/oxfordcontrol/osqp.git (I open the issue here because of osqp
being an external repo obviously):
master
(commit 6fb6db9
), the respective commit value for the submodule lin_sys/direct/qdldl/qdldl_sources
is 12d56ee
(tag v0.1.4
).v0.6.0
(commit 0baddd3
), the respective commit value for the submodule lin_sys/direct/qdldl/qdldl_sources
should be 70596af
(commit message Merge pull request #22 ...
), but in fact, the actual commit checked out in the submodule stays the same: 12d56ee
(tag v0.1.4
). This "discrepancy" then appears as a change in the working tree of the parent repo osqp
:$ git status
HEAD detached at v0.6.0
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: lin_sys/direct/qdldl/qdldl_sources (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
So in order to select the real osqp
version v0.6.0
, we also have to checkout 70596af
(commit message Merge pull request #22 ...
) in the submodule.
Is this what we are doing when evaluating/selecting the desired versions of osqp
?
This issue shows how to set osqp-eigen
to solve an unconstrained optimization problem
We now want to solve the following optimization problem
The solution of the problem is x = [0 0]
osqp-eigen
can be used to solve the problem as follows
Initialize the variables. Please notice that the constraintMatrix
size is 0 x 2
(i.e. number of constraints x number of unknowns)
Eigen::SparseMatrix<double> hessian(2,2);
Eigen::SparseMatrix<double> constraintMatrix(0,2);
Eigen::Vector2d gradient;
Eigen::VectorXd bound(0);
gradient.setZero();
hessian.insert(0,0) = 1;
hessian.insert(1,1) = 1;
Now you can initialize the problem as usual
OsqpEigen::Solver solver;
solver.data()->setNumberOfVariables(2);
solver.data()->setNumberOfConstraints(0);
if(!solver.data()->setHessianMatrix(hessian)) return 1;
if(!solver.data()->setGradient(gradient)) return 1;
if(!solver.data()->setLinearConstraintsMatrix(constraintMatrix)) return 1;
if(!solver.data()->setLowerBound(bound)) return 1;
if(!solver.data()->setUpperBound(bound)) return 1;
You can finally solve the problem
if(!solver.initSolver()) return 1;
if(!solver.solve()) return 1;
Here the entire example
#include <iostream>
#include <Eigen/Sparse>
#include <Eigen/Dense>
#include <OsqpEigen/OsqpEigen.h>
int main()
{
Eigen::SparseMatrix<double> hessian(2,2);
Eigen::SparseMatrix<double> constraintMatrix(0,2);
Eigen::Vector2d gradient;
Eigen::VectorXd bound(0);
gradient.setZero();
hessian.insert(0,0) = 1;
hessian.insert(1,1) = 1;
OsqpEigen::Solver solver;
solver.data()->setNumberOfVariables(2);
solver.data()->setNumberOfConstraints(0);
if(!solver.data()->setHessianMatrix(hessian)) return 1;
if(!solver.data()->setGradient(gradient)) return 1;
if(!solver.data()->setLinearConstraintsMatrix(constraintMatrix)) return 1;
if(!solver.data()->setLowerBound(bound)) return 1;
if(!solver.data()->setUpperBound(bound)) return 1;
if(!solver.initSolver()) return 1;
if(!solver.solve()) return 1;
std::cout << "Solution = " << solver.getSolution().transpose() << std::endl;
return 0;
}
This is the CMakeLists.txt
that you can use to run the example
project(osqp-eigen-test)
cmake_minimum_required(VERSION 3.0)
find_package(OsqpEigen REQUIRED)
find_package(osqp REQUIRED)
find_package(Eigen3 REQUIRED)
add_executable(osqp-eigen-test main.cpp)
target_link_libraries(osqp-eigen-test OsqpEigen::OsqpEigen osqp::osqp Eigen3::Eigen)
The fact that the user should set the constraint matrix and the bounds even if the problem is unconstrained is counterintuitive.
Currently, this repo is used only by @S-Dafarra and @GiulioRomualdi but, in the short time, it will be added inside the robotology-superbuild
robotology/robotology-superbuild#55 so others users may be interested to use it and edit it.
In my opinion, we should force using pull requests, this can be ensured enabling GitHub branch restrictions for the branch master
https://help.github.com/articles/enabling-branch-restrictions/
Using pull requests we can take the trace of the development of the code and, moreover, they are useful to inform others what we are trying to do.
In order to make this as clean as possible an issue_template.md
and a pull_request_template.md
files should be added.
Sorry if I am too punctilious 😳
what do you think @traversaro, @S-Dafarra ?
See for example
osqp-eigen/include/OsqpEigen/Solver.tpp
Lines 215 to 309 in 9b00910
they all access to the workspace data, but that could not have been set yet.
Google Test
from the next releases will start to depend on abseil
, see here. Abseil
is a quite big C++ library that is not packaged in Ubuntu or Homebrew (see https://repology.org/project/abseil-cpp/versions), and will make Google Test
a non-trivial dependency to obtain. On light of this I would propose moving from Google Test
to Catch2
.
I'd like to integrate this library in a Xenomai setup but I'm afraid of dynamic allocations. I see some push_back in the code.
I was wondering If we could take advantage of the reserve
methods for std::vector<>
and eigen sparse matrices toa void any memory allocation between solver updates.
I'm seeing some odd behavior with OSQP when adding simple bounds to an MPC problem. I'm trying to add lower and upper bounds to the control input in the form of f_min <= u <= fmax. I'm adding an appropriately sized identity matrix to the constraint matrix and the vectorized version of f_min and f_max to the lower and upper bound matrices respectively. When I set these bounds to -OsqpEigen::Infty and OsqpEigen::Infty, the result is correct and the control efforts called for are all between 20 and 30. However, if I change either the lower bound to 0 or the upper bound to 50, the solver now outputs something like 0.02 for each control. Given that the bounds are still very wide and the optimal solution falls within them, I assumed that this constraint would be inactive and unable to change the output, but that doesn't seem to be the case. Is there any way this is an OSQP issue, maybe related to primal variable initialization?
The code is somewhat integrated with the rest of a project right now, but I can attempt to construct a MWE if this seems like an OSQP issue.
Ad discussed with @GiulioRomualdi and @S-Dafarra, it would be useful to move this repo to robotology .
For this, we should rename the repo to have a name compliant to robotology organization style.
@GiulioRomualdi let me know when you are ready to move (note that GitHub handles renaming quite well, so this should not be problematic in any way).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.