Minimal OSQP integration for MATLAB/Simulink with CMake-based build system.
-
Setup & Memory Allocation
osqp_setup()need allocated memory- This can be done in initialization (e.g. Pre-Op -> Safe-Op)
-
CSC Matrix Format
Pmatrix must be symmetric and only upper triangular part is allowedP_sparse = csc_matrix(np.triu(P)) # correct P_sparse = csc_matrix(P) # wrong
-
Solver settings: Enable polishing and set maxIter to 50 or 100
if (m_osqp_settings) { osqp_set_default_settings(m_osqp_settings); m_osqp_settings->polishing = 1; m_osqp_settings->polish_refine_iter = 3; m_osqp_settings->scaled_termination = 0; m_osqp_settings->scaling = 10; m_osqp_settings->max_iter = 50; }
- See
section 4 solution polishingof OSQP paper
- See
-
Prefer Vector Updates only (Matrix update needs inversion of new KKT matrix)
- See
section 6 Parametric programsof OSQP paper - If system dynamics and sparsity do not change, update
q,l,uonly in realtime
- See
-
Matrix Updates
- Allowed only if sparsity structure is unchanged
- See example, use
OSQP_NULLas index to update values
-
Constraints
- Avoid unnecessary box constraints that are never active
- E.g. Maximum position/velocity/acceleration
- NO need if the controller stays stable around set points