Hello kaethe!
Oh I feel sorry for not giving clear description, let me add more.
x, y are my system states, so in real control process, the SQP solver will know their values at the beginning of building an optimal control problem, and use mpc to predict a set of future values which is relative to the future inputs, so if I denote x0 , y0 as known start state in a period mpc control programming.
Then in the process of building ocp, I want to update my constraints cause it’s relative to my state, but I don’t know how to do it.
(plus: I’m now working on python code and try to add nonlinear constraints when building my robot model, I may show you some part of it, I mentioned ’ “”“here are my constraints”“” ', so you may understand my problem)
from acados_template import AcadosModel
import casadi as ca
import numpy as np
import yaml
def bluerov2_model_cbf(param):
# colom
sym_tau = ca.SX.sym("tau", 6, 1)
# system state and its derivative
x, y, z = ca.SX.sym("x"), ca.SX.sym("y"), ca.SX.sym("z")
u, v, w = ca.SX.sym("u"), ca.SX.sym("v"), ca.SX.sym("w")
eta_linear = ca.vertcat(x, y, z)
nu_linear = ca.vertcat(u, v, w)
phi, theta, psi = ca.SX.sym("phi"), ca.SX.sym("theta"), ca.SX.sym("psi")
p, q, r = ca.SX.sym("p"), ca.SX.sym("q"), ca.SX.sym("r")
eta_angluar = ca.vertcat(phi, theta, psi)
nu_angluar = ca.vertcat(p, q, r)
nu = ca.vertcat(nu_linear, nu_angluar)
state = ca.vertcat(eta_linear, eta_angluar, nu_linear, nu_angluar)
#.............
# state equation
# @ means mtime
eta_dot = J @ nu
nu_dot = ca.inv(M) @ (
sym_tau - (C_RB + C_A) @ nu - (D_linear + D_nonlinear) @ nu - g_eta
)
state_dot = ca.vertcat(eta_dot, nu_dot)
model = AcadosModel()
#.............
model.x = state
model.xdot = state_dot
"""this is special part for obstacles cased constraints"""
obstacles = param["obstacles"]
n_ob = len(obstacles)
constr = []
"""here are my constraints"""
for i in range(n_ob):
h_fcn = (
(x - obstacles[i][1]) ** 2
+ (y - obstacles[i][2]) ** 2
- obstacles[i][7] ** 2
)
constr.apped(h)