Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OSQP as an alternative solver in the contacts computation #10

Merged
merged 5 commits into from
Nov 30, 2020

Conversation

nunoguedelha
Copy link
Collaborator

@nunoguedelha nunoguedelha commented Nov 26, 2020

The initial idea was to replace quadprog with qpOASES, but since it will soon be deprecated from the superbuild (refer to this comment, we went for OSQP, which actually can be directly called from MATLAB code, i.e. from the class method Contacts.compute_unilateral_linear_contact.

The changes are:

  • Add option to select OSQP instead of quadprog
  • In prepare_optimization_matrix(), replaced single boundary b by
    double boundary AxUb and AxLb, and created the OSQP problem object.
  • Implemented in compute_unilateral_linear_contact() the setup(), update()
    and solve() steps for the OSQP solver.
  • Setting the environment variable OSQP_MATLAB_PATH is now required for
    finding the OSQP library (https://github.com/oxfordcontrol/osqp-matlab).

References

https://osqp.org/docs/index.html
https://osqp.org/docs/get_started/matlab.html
https://osqp.org/docs/interfaces/matlab.html#matlab-interface

@traversaro
Copy link
Contributor

FYI in one month qpOASES will be removed by the robotology-superbuild: robotology/robotology-superbuild#239 (comment) .

@nunoguedelha
Copy link
Collaborator Author

Thanks @traversaro for the reminder. The migration to OSQP should be easy once the change here is complete: the QP Simulink block will be called instead of the the programmatic call to quadprog.

@nunoguedelha nunoguedelha force-pushed the enhanct/replace-quadprog-by-qpoases branch from 1b234de to 7b3767d Compare November 27, 2020 15:12
- Add option to select OSQP instead of quadprog
- In `prepare_optimization_matrix()`, replaced single boundary `b` by
  double boundary `AxUb` and `AxLb`, and created the OSQP problem object.
- Implemented in `compute_unilateral_linear_contact()` the setup(), update()
  and solve() steps for the OSQP solver.
- Setting the environment variable `OSQP_MATLAB_PATH` is now required for
  finding the OSQP library (https://github.com/oxfordcontrol/osqp-matlab).
- We were setting `Px` to the full H (lower triangular part elements = 0)
  instead of the vector of only the upper triangular elements.
- We were setting `Ax` to the upper triangular part of A, while the full
  A is required.
@nunoguedelha nunoguedelha force-pushed the enhanct/replace-quadprog-by-qpoases branch from 7b3767d to cf2adc7 Compare November 28, 2020 15:41
@nunoguedelha nunoguedelha changed the title Add qpOASES as an alternative solver in the contacts computation Add OSQP as an alternative solver in the contacts computation Nov 28, 2020
@nunoguedelha nunoguedelha changed the title Add OSQP as an alternative solver in the contacts computation Add ~qpOASES~ OSQP as an alternative solver in the contacts computation Nov 28, 2020
@nunoguedelha nunoguedelha changed the title Add ~qpOASES~ OSQP as an alternative solver in the contacts computation Add OSQP as an alternative solver in the contacts computation Nov 28, 2020
@nunoguedelha
Copy link
Collaborator Author

@traversaro , as OSQP can be directly from MATLAB code, we went for OSQP right away. I've updated the PR description.

@nunoguedelha
Copy link
Collaborator Author

How to validate this PR.

The simulation should work as usual.
Run the test model with the default parameters.

@nunoguedelha nunoguedelha marked this pull request as ready for review November 28, 2020 15:54
@nunoguedelha nunoguedelha self-assigned this Nov 28, 2020
@CarlottaSartore
Copy link
Collaborator

CarlottaSartore commented Nov 30, 2020

I have tried and everything worked fine! I had only minor comments

Copy link
Collaborator

@CarlottaSartore CarlottaSartore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything worked fine! From my point of view, this PR can be merge once the comments have been addressed C.C. @Giulero

I would anyway add osqp as an external dependency in the main ReadMe to avoid future problems (as well as the fact that now you need to add the variable OSQP_MATLAB_PATH to your bashrc)

lib/+wbs/@Contacts/Contacts.m Outdated Show resolved Hide resolved
lib/+wbs/@Contacts/Contacts.m Outdated Show resolved Hide resolved
lib/+wbs/@Contacts/Contacts.m Outdated Show resolved Hide resolved
@traversaro
Copy link
Contributor

I guess the README needs to be updated to describe how OSQP is supposed to be installed.

@traversaro
Copy link
Contributor

I guess the README needs to be updated to describe how OSQP is supposed to be installed.

Sorry, I had not saw the @CarlottaSartore comment in #10 (review) .

init.m Outdated Show resolved Hide resolved
@Giulero
Copy link
Collaborator

Giulero commented Nov 30, 2020

Thanks @nunoguedelha! Everything went smooth :)

@nunoguedelha
Copy link
Collaborator Author

Damn, I just realized there is something wrong with the behavior. When the right foot heel touches the ground, the foot doesn't rotate. This only happens when I use both steps setup and update of the OSQP. If I use systematically setup, it works fine.

Looking into it now.

…of stepImpl because update() is bugged.

- There is an issue with the OSQP library update() step, or the documentation is
  missing something. Opened issue #12
  for further analysis.
@nunoguedelha
Copy link
Collaborator Author

Unlike what I believed (by following the OSQP HowTo), probably the Px and Ax and

Damn, I just realized there is something wrong with the behavior. When the right foot heel touches the ground, the foot doesn't rotate. This only happens when I use both steps setup and update of the OSQP. If I use systematically setup, it works fine.

Looking into it now.

There is an issue either with OSQP library C code (the bindings MATLAB code looks fine after some checks and tests), either with the documentation which is missing something. Opened issue #12 . Will document better later.

Pushed a workaround using always setup() step.

@nunoguedelha nunoguedelha merged commit 5139717 into devel Nov 30, 2020
@nunoguedelha nunoguedelha deleted the enhanct/replace-quadprog-by-qpoases branch November 30, 2020 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants