Hi @Bocconocini, welcome to the forum ![]()
You don’t need to use a custom operator for this. As you have found, it can be a bit difficult.
I would start to write your code like this:
using JuMP
using Ipopt
T = 5 # end time {seconds}
delT = 2.5 # time step {seconds}
x0 = 0 # metres
y0 = -3 # metres
theta0 = 0 # rad
u0 = 20 # m/s
v0 = 0 # m/s
r0 = 0 # m/s
m = 1914 # kg
Izz = 2600 # kg*m^2
a = 1.35 # metres
b = 1.5 # metres
kx = 100_000 # N/m
cf = 80_000 # 2*1437*dpr # N/m
cr = 80_000 # 2*1507*dpr # N/m
# slip_ratio = ???
N = ceil(Int, T / delT)
model = Model(Ipopt.Optimizer)
@variable(model, slip[1:N])
@variable(model, steer[1:N])
@variable(model, x[1:N + 1, 1:6])
fix.(x[1,:], [x0, y0, theta0, u0, v0, r0])
for i in 1:N
t = (i - 1) * delT
@constraints(model, begin
x[i+1,1] == x[i,1] + (x[i,4]*cos(x[i,3])-x[i,5]*sin(x[i,3]))*delT
x[i+1,2] == x[i,2] + (x[i,4]*sin(x[i,3])+x[i,5]*cos(x[i,3]))*delT
x[i+1,3] == x[i,3] + (x[i,6]*pi/180)*delT #theta_dot (radians)
x[i+1,4] == x[i,4] + (2*kx*slip_ratio[i]/m)*delT #u_dot
x[i+1,5] == x[i,5] + ((cf*steer[i] - (x[i,5]*(cf+cr) + (x[i,6]*pi/180)*(a*cf - b*cr + m*x[i,4]^2))/x[i,4])/m)*delT #v_dot
x[i+1,6] == x[i,6] + ((180/pi)*(cf*a*steer[i] - (x[i,5]*(a*cf - b*cr) +(x[i,6]*pi/180)*(a^2 * cf + b^2 *cr))/x[i,4])/Izz)*delT #r_dot (deg/s)
end)
end
There are a few bits missing, but it should point you in the right direction.
There are a few optimal control tutorials in the documentation. Check out: Example: nonlinear optimal control of a rocket · JuMP, Example: optimal control for a Space Shuttle reentry trajectory · JuMP