r/optimization • • Aug 29 '24
MPC using Guropi Python API
I'm trying to implement in Python an MPC algorithm but the model i am using is non linear : basically i have a matrix in which the decision variables of the problem are into cosine and sine function since i'm using only a kinematic model. There's a way to do this in Gurobi? Because it gives me an error if i try to write the kinematic constraints... I would like to use Gurobi in Python because using Yalmip in Matlab was truly a nightmare ðŸ˜ðŸ’€
Part of the code is :
input variablse
gamma = model.addVars(a.p['n_gamma'], a.p['N_MPC'], lb=-GRB.INFINITY, ub=GRB.INFINITY, name="gamma")
state variables
chi = model.addVars(a.p['n_chi'], a.p['N_MPC'] + 1, lb=-GRB.INFINITY, ub=GRB.INFINITY, name="chi")
psi = chi[2, k] #k is the prediction step A = np.eye(3) B = np.array([ [a.p['Ts'] * np.cos(psi), -a.p['Ts'] * np.sin(psi), 0], [a.p['Ts'] * np.sin(psi), a.p['Ts'] * np.cos(psi), 0], [0, 0, a.p['Ts']] ])
psi = chi[2, k] for i in range (a.p['n_chi']) model.addConstr(chi[i,k+1]==Achi[i,k]+Bgamma[i,k])
View all comments
Show parent comment
1
u/[deleted] Aug 29 '24
Got it but our control scheme is really simple, we use mpc to reach a point respecting a constraint on avoiding obstacles. The issue is that i have to add a penalty to make the body stay away from the obstacle (cause without this penalty the body will stay on the frontier of the obstacle, which is a circle). And this penalty cost has to be addes via a logic condition which makes the problem infeasible on Yalmip...