# Constraints and Parameters for Specific Time-Steps, external?

Hi everyone,

Here I come again with a question regarding the acados problem formulation.

So far, I happily found that I can use external dynamics and costs from CasADi functions, which is great! Now, a perhaps harder question comes to mind:

1. Is it possible to specify constraints that are active only in specific steps of the Receding Horizon (RH)? The closes I found was this thread, in particular, `ocp.set('cost_y_ref', yr, i)` seems to set the parameter for horizon i, so I could do the same with `ocp.set('lbx', bnd, i)` to set the lower bound for X at stage i ? How does the interface work?

2. In the same way, is it possible to set external parameters to be used in specific RH steps?

Thanks a lot!
Pedro,

Hi Pedro,

I guess you are still using Python?

So the equivalent in Python to the Matlab snippet you posted
`ocp.set('lbx', bnd, i)`
would be this:
`acados_ocp_solver.constraints_set(stage, "lbx", lbx)`

The functions how to interact with `AcadosOcpSolver` are documented here: https://docs.acados.org/interfaces/#acados_template.acados_ocp_solver.AcadosOcpSolver

Setting parameters for individual stages works like this:
`acados_ocp_solver.set(stage, "p", p_value)`

Best,
Jonathan

Thanks Jonathan!

So it seems I can just use “p” as a parameter array that then is updated for each stage of the horizon (and in a default manner, initalize it before solving the problem). So the last question is just if I can use these parameters with external cost functions (to use a state-reference for instance)?

Cheers!
Pedro,

Sure, you can use external cost functions with parameters.
However, if you have a state reference in the cost, you can most likely formulate your problem more efficiently with a linear or nonlinear leas-squares cost function and update `yref`.

Cheers,
Jonathan

In my case, the cost is not just || x - xr|| , since the way we calculate the error between two quaternions is nonlinear (atm I convert them to R matrices and use Lee’s equations, but also plan on avoiding that). Unless we use euler, I don’t see an easy way to calculate the attitude error using least squares

I’ll take a look at those parameters sometime soon, and will report back.

Cheers,
Pedro