How to change convex-over-nonlinear constraints

Hi everyone,

For my thesis, I am using the python interface of acados to prototype an MPC for a multicopter. The generated C code is then used with a C++ ROS-node.

The controlled multicopter is equipped with two sensors with different fields of view. The target point should stay in any of those two FOVs at any time.
As of now, I have implemented the FOV constraint as a soft convex-over-nonlinear constraint and can specify the active sensor using model parameters.

Approaching the target, I want to deactivate the FOV constraint.
I tried extending the constraints to make them irrelevant with:

acados_ocp_solver.constraints_set(k, 'lphi', np.array([-1000.]))

However, the following error appears:

error: ocp_nlp_constraint_dims_get_from_attr: field lphi not available

I am aware, that the documentation does not state ‘lphi’ as a valid input argument. Using ‘uphi’ - which should work according to the documentation - produces the same kind of error.

Alternatively, I could lower the costs on the slack variables at the relevant time steps, instead of changing the constraints. Which of those methods can be realized, and how?
I do not care that much about the Python interface, as long as there is a solution using C.

Thanks in advance,
Martin

Hi Martin,

That sounds great!

I think both should be possible.
I think there shouldn’t be anything else missing than support for the field uphi in the function you mentioned.

Can you try to add it there and recompile acados?
If it works a pull request is also welcome.

Otherwise changing the slack penalties should also work.

Cheers and good luck with the thesis!
Jonathan

I added uphi to the function

ocp_nlp_constraint_dims_get_from_attr

On the last commit on this PR: https://github.com/acados/acados/pull/784

Let me know if it works.

Hi Jonathan!

Thank you for your quick reply!
I added the code from the pull request and changed one line, so that it reads:

else if (!strcmp(field, "uphi") || !strcmp(field, "lphi"))

Changing uphi and lphi now seems to work! However, I don’t know yet, how to do the same in C. Is there an equivalent function?

Can you also hint me on which function to use to change the costs on slack variables? I can’t find a fitting setter in the documentation.

Cheers,
Martin

Hi Martin,

I didn’t add lphi, because it shouldn’t really be there.
Say the outer convex function is x^2. If lphi is > 0, then the constraint is not convex anymore.
I saw some comment in the code that lphi should be removed.

How to do it in C:
Check what the constraints_set function in Python does internally.
It basically just calls ocp_nlp_constraints_model_set.

Cheers!