1+ # Transfer optimal control problem definition used by tests and examples.
2+ #
3+ # Returns a NamedTuple with fields:
4+ # - ocp :: the CTParser-defined optimal control problem
5+ # - obj :: reference optimal objective value (Ipopt / MadNLP, Collocation)
6+ # - name :: a short problem name
7+ # - init :: NamedTuple of components for CTSolvers.initial_guess
8+
9+ asqrt (x; ε= 1e-9 ) = sqrt (sqrt (x^ 2 + ε^ 2 )) # Avoid issues with AD
10+
11+ const μ = 5165.8620912 # Earth gravitation constant
12+
13+ function F0 (x)
14+ P, ex, ey, hx, hy, L = x
15+ pdm = asqrt (P / μ)
16+ cl = cos (L)
17+ sl = sin (L)
18+ w = 1 + ex * cl + ey * sl
19+ F = [0 , 0 , 0 , 0 , 0 , w^ 2 / (P * pdm)]
20+ return F
21+ end
22+
23+ function F1 (x)
24+ P, ex, ey, hx, hy, L = x
25+ pdm = asqrt (P / μ)
26+ cl = cos (L)
27+ sl = sin (L)
28+ F = pdm * [0 , sl, - cl, 0 , 0 , 0 ]
29+ return F
30+ end
31+
32+ function F2 (x)
33+ P, ex, ey, hx, hy, L = x
34+ pdm = asqrt (P / μ)
35+ cl = cos (L)
36+ sl = sin (L)
37+ w = 1 + ex * cl + ey * sl
38+ F = pdm * [2 * P / w, cl + (ex + cl) / w, sl + (ey + sl) / w, 0 , 0 , 0 ]
39+ return F
40+ end
41+
42+ function F3 (x)
43+ P, ex, ey, hx, hy, L = x
44+ pdm = asqrt (P / μ)
45+ cl = cos (L)
46+ sl = sin (L)
47+ w = 1 + ex * cl + ey * sl
48+ pdmw = pdm / w
49+ zz = hx * sl - hy * cl
50+ uh = (1 + hx^ 2 + hy^ 2 ) / 2
51+ F = pdmw * [0 , - zz * ey, zz * ex, uh * cl, uh * sl, zz]
52+ return F
53+ end
54+
55+ function Transfer (; Tmax= 60 )
56+
57+ cTmax = 3600 ^ 2 / 1e6 ; T = Tmax * cTmax # Conversion from Newtons to kg x Mm / h²
58+ mass0 = 1500 # Initial mass of the spacecraft
59+ β = 1.42e-02 # Engine specific impulsion
60+ P0 = 11.625 # Initial semilatus rectum
61+ ex0, ey0 = 0.75 , 0 # Initial eccentricity
62+ hx0, hy0 = 6.12e-2 , 0 # Initial ascending node and inclination
63+ L0 = π # Initial longitude
64+ Pf = 42.165 # Final semilatus rectum
65+ exf, eyf = 0 , 0 # Final eccentricity
66+ hxf, hyf = 0 , 0 # Final ascending node and inclination
67+ Lf = 3 π # Estimation of final longitude
68+ x0 = [P0, ex0, ey0, hx0, hy0, L0] # Initial state
69+ xf = [Pf, exf, eyf, hxf, hyf, Lf] # Final state
70+
71+ ocp = @def begin
72+ tf ∈ R, variable
73+ t ∈ [0 , tf], time
74+ x = (P, ex, ey, hx, hy, L) ∈ R⁶, state
75+ u ∈ R³, control
76+ x (0 ) == x0
77+ x[1 : 5 ](tf) == xf[1 : 5 ]
78+ mass = mass0 - β * T * t
79+ ẋ (t) == F0 (x (t)) + T / mass * (u₁ (t) * F1 (x (t)) + u₂ (t) * F2 (x (t)) + u₃ (t) * F3 (x (t)))
80+ u₁ (t)^ 2 + u₂ (t)^ 2 + u₃ (t)^ 2 ≤ 1
81+ tf → min
82+ end
83+
84+ init = @init ocp begin
85+ tf_i = 15
86+ x (t) := x0 + (xf - x0) * t / tf_i # Linear interpolation
87+ u (t) := [0.1 , 0.5 , 0. ] # Initial guess for the control
88+ tf := tf_i # Initial guess for final time
89+ end
90+
91+ return (ocp= ocp, obj= 14.79643132 , name= " transfer" , init= init)
92+ end
0 commit comments