Coder Social home page Coder Social logo

robotology / osqp-eigen Goto Github PK

View Code? Open in Web Editor NEW
354.0 14.0 106.0 1.67 MB

Simple Eigen-C++ wrapper for OSQP library

Home Page: https://robotology.github.io/osqp-eigen/

License: BSD 3-Clause "New" or "Revised" License

CMake 32.27% C++ 67.49% C 0.24%
optimization qp osqp quadratic-programming convex-optimization

osqp-eigen's Introduction

osqp-eigen

General c++14 License
CI/CD Codacy Badge CI Azure
conda Conda Recipe Conda Downloads Conda Version Conda Platforms

Simple C++ wrapper for osqp library.

📚 Documentation

The documentation is available online at the accompanying website.

📄 Dependences

The project depends only on osqp and Eigen3. Please install Catch2 if you want to run the tests only for testing.

🛠️ Usage

📦 Install with conda (recommended)

You can easily the library with conda using the following command

conda install -c conda-forge osqp-eigen

conda will automatically install osqp and Eigen3.

⚙️ Build from source (advanced)

  1. Clone the repository
    git clone https://github.com/robotology/osqp-eigen.git
    
  2. Build it
    cd osqp-eigen
    mkdir build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX:PATH=<custom-folder> ../
    make
    make install
    
  3. Add the following environmental variable
    OsqpEigen_DIR=/path/where/you/installed/
    

🖥️ How to use the library

osqp-eigen provides native CMake support which allows the library to be easily used in CMake projects. osqp-eigen exports a CMake target called OsqpEigen::OsqpEigen which can be imported using the find_package CMake command and used by calling target_link_libraries as in the following example:

cmake_minimum_required(VERSION 3.0)
project(myproject)
find_package(OsqpEigen REQUIRED)
add_executable(example example.cpp)
target_link_libraries(example OsqpEigen::OsqpEigen)

🐛 Bug reports and support

All types of issues are welcome.

📝 License

Materials in this repository are distributed under the following license:

All software is licensed under the BSD 3-Clause License. See LICENSE file for details.

osqp-eigen's People

Contributors

chibi314 avatar enricodetoma avatar fabinsch avatar gergondet avatar giulioromualdi avatar k2shah avatar kalj avatar kexianshen avatar mhubii avatar mpowelson avatar s-dafarra avatar traversaro avatar voldien avatar wxmerkt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osqp-eigen's Issues

fails building the master branch

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.

@GiulioRomualdi

API of getting dual solution

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!

Segmentation fault (core dumped) on MPCExample

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

if(!solver.initSolver()) return 1;

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.

Can't build successfully.

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"

Provide conda-forge package for osqp-eigen

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

why i set a hard problem, it can be solved, while i set a very easy problem(0,0,0,0,0,.....), it cant be solved , and the estimate get larger and larger

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.

Ownership of bounds, gradient, Hessian, and constraint matrix

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.

Cant instantiate the solver; "OsqpEigen::Solver solver"

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)

osqp-sol

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;
}

Unexplained error "upper bound must be greater than or equal to lower bound"

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 i build my project , it shows that it cant find osqg.h

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

Warning of the MPC example compilation

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?

Target links to target "OSQPEigen::OSQPEigen" but the target was not found.

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

Properly checkouting git submodules in a given repo

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):

  • if we checkout the branch master (commit 6fb6db9), the respective commit value for the submodule lin_sys/direct/qdldl/qdldl_sources is 12d56ee (tag v0.1.4).
  • if we checkout the tag 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?

Several of the Solver methods may result in a segfault if the solver is not initialized

See for example

template<typename T, int n, int m>
bool OsqpEigen::Solver::setWarmStart(const Eigen::Matrix<T, n, 1> &primalVariable,
const Eigen::Matrix<T, m, 1> &dualVariable)
{
if(primalVariable.rows() != m_workspace->data->n){
debugStream() << "[OsqpEigen::Solver::setWarmStart] The size of the primal variable vector has to be equal to "
<< " the number of variables."
<< std::endl;
return false;
}
if(dualVariable.rows() != m_workspace->data->m){
debugStream() << "[OsqpEigen::Solver::setWarmStart] The size of the dual variable vector has to be equal to "
<< " the number of constraints."
<< std::endl;
return false;
}
m_primalVariables = primalVariable.template cast <c_float>();
m_dualVariables = dualVariable.template cast <c_float>();
return (osqp_warm_start(m_workspace.get(), m_primalVariables.data(), m_dualVariables.data()) == 0);
}
template<typename T, int n>
bool OsqpEigen::Solver::setPrimalVariable(const Eigen::Matrix<T, n, 1> &primalVariable)
{
if(primalVariable.rows() != m_workspace->data->n){
debugStream() << "[OsqpEigen::Solver::setPrimalVariable] The size of the primal variable vector has to be equal to "
<< " the number of variables."
<< std::endl;
return false;
}
m_primalVariables = primalVariable.template cast <c_float>();
return (osqp_warm_start_x(m_workspace.get(), m_primalVariables.data()) == 0);
}
template<typename T, int m>
bool OsqpEigen::Solver::setDualVariable(const Eigen::Matrix<T, m, 1> &dualVariable)
{
if(dualVariable.rows() != m_workspace->data->m){
debugStream() << "[OsqpEigen::Solver::setDualVariable] The size of the dual variable vector has to be equal to "
<< " the number of constraints."
<< std::endl;
return false;
}
m_dualVariables = dualVariable.template cast <c_float>();
return (osqp_warm_start_y(m_workspace.get(), m_dualVariables.data()) == 0);
}
template<typename T, int n>
bool OsqpEigen::Solver::getPrimalVariable(Eigen::Matrix<T, n, 1> &primalVariable)
{
if(n == Eigen::Dynamic){
primalVariable.resize(m_workspace->data->n, 1);
}
else{
if (n != m_workspace->data->n){
debugStream() << "[OsqpEigen::Solver::getPrimalVariable] The size of the vector has to be equal to the number of "
<< "variables. (You can use an eigen dynamic vector)"
<< std::endl;
return false;
}
}
primalVariable = Eigen::Map<Eigen::Matrix<c_float, n, 1>>(m_workspace->x, m_workspace->data->n).template cast <T>();
return true;
}
template<typename T, int m>
bool OsqpEigen::Solver::getDualVariable(Eigen::Matrix<T, m, 1> &dualVariable)
{
if(m == Eigen::Dynamic){
dualVariable.resize(m_workspace->data->m, 1);
}
else{
if (m != m_workspace->data->m){
debugStream() << "[OsqpEigen::Solver::getDualVariable] The size of the vector has to be equal to the number of "
<< "constraints. (You can use an eigen dynamic vector)"
<< std::endl;
return false;
}
}
dualVariable = Eigen::Map<Eigen::Matrix<c_float, m, 1>>(m_workspace->y, m_workspace->data->m).template cast <T>();
return true;
}

they all access to the workspace data, but that could not have been set yet.

cc @GiulioRomualdi

Devel breaks idyntree::optimal_control

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.

@GiulioRomualdi @traversaro

Add possibility (e.g. cmake flag) to disable or redirect error output

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.

Weird constraint behavior when implementing simple bounds

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.

How to set run time limit?

Is there any setting for time limit, like the original osqp setting?
image
usually it takes longer if the solver fails. I want to set a limit for run time.
Thanks!

osqp-eigen not compatible with osqp 0.6.0

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:

  1. osqp/osqp@78d1135 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
  1. osqp/osqp@06678c7 osqp now accepts only upper triangular Hessian matrices
diff --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

Segmentation fault (core dumped)

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.

Matlab S-function freeze

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

when operator slover class, an error occured, it shows that there is a undefined reference

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

when i build this project, this error occurs. My osqp is version 0.4.1.

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

Solve unconstrained optimization problems

This issue shows how to set osqp-eigen to solve an unconstrained optimization problem

We now want to solve the following optimization problem

qp

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.

cc @S-Dafarra @traversaro @lrapetti

Consider the possibility to store the gradient and the bounds vectors inside the library

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

osqp.h: No such file or directory #include <osqp.h>

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.

Migrate to robotology

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).

cc @DanielePucci

make error: "recipe for target 'CMakeFiles/OsqpEigen.dir/src/Solver.cpp.o' failed", osqp-eigen:v0.6.3, osqp:v0.6.2

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.

setHessianMatrix is deprecated

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?

Compilation error of tests

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.

Change template function definition to support Visual Studio

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~

My commit is deleted

I send a PR #25 and it was merged into devel, but now I couldn't find it in devel and master.

Protect master branch and use only pull request on it

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 ?

Dynamic allocations

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.

‘OSQPWrapper’ has not been declared

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.

Can I use osqp-eigen on Windows10 with QT?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.