How do you add specific slack value?

Consider when defining slack values you can define them for the control input, state, set constraints and non-linear constraints.

You need the slack values to be higher than gain Q-matrix so the controller will attempt to not violate them. This means that the controller will not violate constraints that decreases the cost function if violated. However consider the set constraint which states that an error must be inside a set, and furthermore consider an non-linear obstacle constraint. Ideally the set error constraint will have lower slack values than the obstacle constraint and the obstacle constraint will have higher slack values than the gain matrix. The effect I want is that that system will stay inside the set until an obstacle arrives which causes the relaxation of the set error constraint.

But I cannot see a way set the slack values deterministically. I know I could probably try my luck with the ordering but is there a documentation for this?

hi @xamza1608,

I’m not 100% sure that I fully understand your question correctly, but from what I’m getting is that you want a way to set the weights (z_l, z_u, Z_l, Z_u) of the slack variables (s_l, s_u). I’m following the notation from the official documentation here.

Further, I don’t know what interface you are using. I’m only familiar with the C and Python interfaces.

Python: For simplicity, I’m setting all weights to unity. You will need to adapt according to your problem.

cost_type = "NONLINEAR_LS"
cost = AcadosOcpCost()
cost.cost_type = cost_type
cost.cost_type_e = cost_type

# Cost weighting matrix
cost.W = np.eye(nx)
cost.W_e = np.eye(nx_e)

# Linear cost on slack
cost.zl = np.ones((nz, ))  
cost.zu = np.ones((nz, ))
cost.zl_e = np.ones((nz_e, ))
cost.zu_e = np.ones((nz_e, ))

# Quadratic cost on slack
cost.Zl = np.ones((nz, ))  
cost.Zu = np.ones((nz, ))
cost.Zl_e = np.ones((nz_e, ))
cost.Zu_e = np.ones((nz_e, ))

With the C-interface, you want to use the ocp_nlp_cost_model_set function.

You can get the ocp_nlp_config, ocp_nlp_dims and ocp_nlp_in from the “solver_capsule” object.
Note that you need to call this function for every step from i = 0, ..., H.

std::array<double, nz> linear_slack_weights = ...;
ocp_nlp_cost_model_set(ocp_nlp_config, ocp_nlp_dims, ocp_nlp_in, i, "zl", linear_slack_weights.data());

Hope this helps.