I've just started looking at GEKKO for solving OCPs, and I've run into an issue. How would one go about solving the maximum radius orbit transfer problem as seen in Bryson and Ho (also here). The main question is adding the terminal constraint on the velocity v(tf), which is a function of the final position r(tf).
Any help is greatly appreciated!
Thank you!
import numpy as np
import matplotlib.pylab as plt
from gekko import GEKKO
if __name__ == '__main__':
m = GEKKO()
# Constants
nt = 101
m.time = np.linspace(0, 193, nt)
thr = 0.85
mu = (3.32/193)**2
m0 = 10000
mdot = 12.9
# Params
u1 = m.MV(value=0)
u1.STATUS = 1
u1.DCOST = 0
u2 = m.MV(value=np.pi, fixed_initial=False)
u2.STATUS = 1
u2.DCOST = 0
# Vars
t = m.Var(value=0, fixed_initial=True)
r = m.Var(value=1, fixed_initial=True)
u = m.Var(value=0, fixed_initial=True)
v = m.Var(value=np.sqrt(mu), fixed_initial=True)
# Find Index at Final Time
p = np.zeros(nt)
p[-1] = 1.0
final = m.Param(value=p)
# Equations
m.Equation(t.dt() == 1)
m.Equation(r.dt() == u)
m.Equation(u.dt() == v**2/r - mu/r**2 + thr*u1/(m0-mdot*t))
m.Equation(v.dt() == -u*v/r + thr*u2/(m0-mdot*t))
# Constraints
m.fix(u, pos=nt-1, val=0.0)
#m.fix(v, pos=nt-1, val=m.sqrt(mu/r[nt-1])) # <-- How do I correctly add this constraint?
# Objective Function -- Max Radius at Final Time
m.Obj(-r*final)
# Solve!
m.options.IMODE = 6
m.options.NODES = 4
m.options.MV_TYPE = 1
m.options.SOLVER = 3
m.solve()
