σ
β
̇
⃗
θ ϕ
⃗⃗
γ ψ
θ
ϕ
γ
ψ
⃗
( )
(
)
( )
( )
ω
α
δ
α
α
α
σ
ε
ε
λ
δ
≤
≤
γ
γ
9,4
9,6
9,8
10
10,2
10,4
10,6
10,8
11
11,2
11,4
1200
1250
1300
1350
1400
M
axi
m
u
m
o
ve
rp
re
ssur
e
[
Pa]
Flight Time [s]
0
0,2
0,4
0,6
0,8
1
1,2
1,4
0
1000
2000
3000
4000
5000
6000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
0
0,5
1
1,5
2
2,5
0
5
10
15
20
25
1442
1462
1482
1502
1522
1542
Ma
ch
[-]
A
lt
it
ud
e
[
km]
Ground track distance [km]
Altitude
Mach
0
2
4
6
8
10
12
0
10
20
30
40
50
60
70
80
90
0
500
1000
1500
Ground track distance [km]
Ma
ch
[-]
A
lt
it
ud
e
[
km]
ALTITUDE
MACHNUM
a)
b)
c)
0
0,05
0,1
0,15
0,2
0,25
0,3
0,35
0
500
1000
1500
Sta
gn
ati
o
n
Hea
t
Flux
[M
W
/m²]
Flight Time [s]
γ
γ
0
0,2
0,4
0,6
0,8
1
1,2
1,4
0
1000
2000
3000
4000
5000
6000
Sta
gn
ati
o
n
he
at
fl
u
x
[M
W
/m²]
Flight time [s]
0
0,2
0,4
0,6
0,8
1
1,2
1,4
1,6
1,8
0
5
10
15
20
25
1428
1478
1528
M
ac
h
[
-]
A
ltitu
d
e
[
km
]
Ground Track distance [km]
Altitude
Mach
a)
b)
c)
0
2
4
6
8
10
12
0
10
20
30
40
50
60
70
80
90
0
500
1000
1500
M
ac
h
[
-]
A
ltitu
d
e
[
km
]
Ground Track Distance [km]
Altitude
0
0,05
0,1
0,15
0,2
0,25
0,3
0,35
0,4
0
500
1000
1500
St
ag
na
ti
o
n
H
ea
t
Fl
ux
[
MW
/m
²]
Flight time [s]
≈
̇
(
(
)
̇
)
̇
)
̇
√
[ (
)
] { (
)
[(
)
]
}
0
0,2
0,4
0,6
0,8
1
1,2
1,4
0
1000
2000
3000
4000
5000
6000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight time [s]
0
0,2
0,4
0,6
0,8
1
1,2
1,4
0
1000
2000
3000
4000
5000
6000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight time [s]
0
0,2
0,4
0,6
0,8
1
1,2
1,4
0
1000
2000
3000
4000
5000
6000
St
ag
na
ti
o
n
he
at
f
lux
[
MW
/m
²]
Flight time [s]
72
74
76
74,23
74,56
74,32 74,95
A
ltitu
d
e
[
km
]
7000
7100
7200
7300
7400
7.360,7
7.283,3
7.231,3
7.136,5
Veloc
ity
[m
/s]
1,23
1,26
1,29
1,32
1,257
1,287
1,298
1,293
Stag
n
ati
on
h
eat
fl
u
x
[MW/m
²]
70
75
80
85
Nominal
Reduction
3 s Isp
Ascent
prop -20 t
Failure 1
engine
75,38
76,91
78,12
81,85
To
tal Fl
ig
h
t
Ti
m
e
[m
in
u
te
s]
17200
17400
17600
17800
Nominal
Reduction 3
s Isp
Ascent prop
-20 t
Failure 1
engine
17527,76
17586,67
17705,29
17401,04
To
tal g
ro
u
n
d
tr
ac
k
[km
]
( )
( )
( (
) )
(
)
( )
( )
( )
̇
( )
̇
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
( )
( )
( )
(
)
ρ
( (
)
)
̇ √
(
)
̇
( )
α
̇
0,00
0,02
0,04
0,06
0,08
0,10
0,12
0,14
0,16
0
2
4
6
8
10 12 14
C
D[
-]
AoA [°]
CD turbolent
CD laminar
-2,0
-1,5
-1,0
-0,5
0,0
0,5
1,0
1,5
2,0
2,5
3,0
3,5
4,0
0
2
4
6
8
10 12 14
L/D
[-]
AoA [°]
L/D turbolent
L/D laminar
( ) √ (
)
( )
√ (
)
√ ( )
( )
( )
| |
̇
̇
∫
( )
( )
(
)
(
)
(
)
∫
( )
Waypoint
(201°E-73°N)
Start Descent
phase
( )
( )
( )
( )
)
(
)
( )
(
)
( )
(
) (
)
(
)
( )
(
̇
)
( )
( )
(
)
̇
(
)
(
)
(
)
(
)
(
)
(
)
∫
(
)(
)
(
)
(
(
)
)
(
)
∫
(
)(
)
(
)
(
(
)
(
)
)
(
)
(
) (
)
𝝈
𝑫
𝑺
{
( ( ))
( (
( ( )))
)
̇
( ( ))
(
)
( )(
) (
)
(
)
(
)
(
)
(
) (
)
(
) (
)
(
)
(
)
(
) (
) ( )
( )
(
)
(
)
(
)
{
(
)
(
)
(
)
(
) (
) (
)
[
(
)]
(
)
(
)
(
)
(
( )
( )
)
(
)
(
) (
)
(
)
(
)
[
(
)
]
( )
̇
[
]
[
]
(
‖
‖
)
‖
‖
(
‖
‖
‖
‖
)
‖ ‖ ‖ ‖(
‖
‖
‖
‖
)
‖
‖
*************************INPUT FILE Australia - Europe****************************** Filepath
X:\Entry_guidance\Australia-Europe\1Step X:\Entry_guidance\Australia-Europe\2Step --WAYPOINT Bearing Strait--
Longitude (E) 201.600 Latitude (N) 73.020 Radius in km 6421 Specific energy in km²/s² -44.320
--TAEM INTERFACE CONDITION-- Longitude 7.460 Latitude 54.680 Radius in km 6394 Specific energy in km²/s² -62
FIRST ENTRY PLANNING######################################################### angle of attack
14
Direction trajectory (+1 on left or -1 to right) +1
heading error corridor (upper band) 10 10
heading error corridor (lower band) -10 -10
First bank change: Value of time step in tosca to anticipate (-) or postpone (+) 0
Second bank change: Value of time step in tosca to anticipate (-) or postpone (+) -1
SECOND ENTRY PLANNING######################################################## angle of attack
14
Direction trajectory (+1 on left or -1 to right) +1
heading error corridor (upper band) 20 -5
heading error corridor (lower band) -20 -25
First bank change: Value of time step in tosca to anticipate (-) or postpone (+) -2
Second bank change: Value of time step in tosca to anticipate (-) or postpone (+) 0
0 bank angle: Value of time step in tosca to anticipate (-) or posticipate (+) +1
( )
Time [s]
H
eading erro
r
[deg
]
θ
φ
γ
0
0,2
0,4
0,6
0,8
1
1,2
1,4
1,6
1,8
2
0
1000
2000
3000
4000
5000
6000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
γ
θ
φ
α
0
0,2
0,4
0,6
0,8
1
1,2
1,4
1,6
1,8
2
0
1000
2000
3000
4000
5000
6000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
γ
θ
φ
̇
0
0,2
0,4
0,6
0,8
1
1,2
1,4
1,6
1,8
2
0
1000
2000
3000
4000
5000
6000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
γ
θ
φ
0
0,5
1
1,5
2
2,5
3
0
1000
2000
3000
4000
5000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
θ
φ
0
0,5
1
1,5
2
2,5
3
0
500
1000
1500
2000
2500
3000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
θ
φ
α
0
0,5
1
1,5
2
2,5
0
1000
2000
3000
4000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
θ
φ
α
0
0,2
0,4
0,6
0,8
1
1,2
1,4
1,6
1,8
0
1000
2000
3000
4000
Stagn
ation
h
e
at
fl
u
x
[M
W/m
²]
Flight Time [s]
////============================================================================ // SpaceLiner 7-3 entry guidance
// This is the first reentry guidance program used in Chapter 5.
// Elena Casali // November 2015
//==============================================================================
clear;
xdel(winsid());
//Planet-specific constants: Earth entry.
rho_ref = 1.225; //kg/m^3.
mu = 398600; //km^3/s^2
H = 8.5; //Scale height in km.
g_ref = 9.81; //Grav acc m/s^2.
R = 6378; //Radius of Earth in km.
Sp_ratio = 1.4; //Specific ratio of Air.
R_Air = 0.000287; //Gas constant of Air in km²/s²°K.
//Spacecraft constants: SpaceLiner 7-3
S=461; //Reference Area in m²
Rn = 0.205; // nose radius of vehicle in m
ch = 202544000; // W/m²- Stagnation heat flux constant
v_ref=10; //km - velocity reference for the estimation of heat flux
//Read the input
file---fcd=mopen(pwd() +'\INPUT.dat','r');// open file
mgetl(fcd,3);
filepath1=mgetl(fcd,1); mgetl(fcd,27);
alpha1=mfscanf(fcd,'%e'); // Fix value of angle-of-attack for reentry
mgetl(fcd,2);
sign_Sigma1=mfscanf(fcd,'%e'); mgetl(fcd,2);
hplus=mfscanf(fcd,'%e %e');// heading error corridor (upper band)
mgetl(fcd,2);
hmin=mfscanf(fcd,'%e %e');// heading error corridor (lower band)
mgetl(fcd,2);
fbc=mfscanf(fcd,'%e');// First bank change: Value of time step in tosca to anticipate (-) or posticipate (+)
mgetl(fcd,2);
sbc=mfscanf(fcd,'%e');// Second bank change: Value of time step in tosca to anticipate (-) or posticipate (+)
mclose(fcd);
h2(1,1)=hplus(1,2); h1(2,1)=hmin(1,1); h2(2,1)=hmin(1,2); clear fcd hplus hmin;
//Aerodynamic
database---//matrix of Cd for the corresponding fix angle-of-attack at each mach number (0.7 0.9 1.1 2.0 4.0 6.0 10.0 14.0 17.9 18.1 22.0 26.0)
fcd=mopen(filepath1+'\aero_trim.tosca','r');// open file
mgetl(fcd,17);
M=mfscanf(fcd,'%e %e %e %e %e %e %e %e %e %e %e %e'); //read the value of Mach number
Mach=M.';
mgetl(fcd,5+alpha1);//skip lines untile the value of alpha1 choosen
CD=zeros(Mach);
for i=1:length(Mach)//Take the value of the drag coefficient corrisponding to the value of alpha, for each value of Mach number
CD(i,1)=mfscanf(fcd, '%e'); mgetl(fcd,31);
end
mgetl(fcd,1); CL=zeros(Mach);
for i=1:length(Mach)//Take the value of the lift coefficient corrisponding to the value of alpha, for each value of Mach number
CL(i,1)=mfscanf(fcd, '%e'); mgetl(fcd,31);
end
LD=CL./CD;
Aero_database=[Mach,CD,LD];//Create the matrix of aerodynamic database
clear M Mach CD i CL LD; mclose(fcd);
clear fcd;
//Initial conditions============================================================
//Read the corrected parameters from tosca_out.data for the initial conditions
all = mgetl(filepath1+'\tosca_in.data'); all(176:218)=string(alpha1) +" "+string(0);
// Replace all the lines of the old input file with the newly made input file
fd = mopen(filepath1+'\tosca_in.data','wt');
for q = 1:size(all,1)
mfprintf(fd,'%s \n',all(q));
end
mclose(fd); clear q all fd;
disp("Correct value of alpha written in tosca_in.data. Run TOSCA to generate the right tosca_out.data")
pause;
//---RUN TOSCA
1---Tosca_outD =fscanfMat(filepath1+'\tosca_out.data',"%lg"); h_0=Tosca_outD(1,5); //read the value of initial altitude km
lon_0 = Tosca_outD(1,6); lat_0 = Tosca_outD(1,7); hea_0 = Tosca_outD(1,4); V_0 = Tosca_outD(1,2); //km/s gamma_0 = Tosca_outD(1,3); r_0 = Tosca_outD(1,37); //km
E_0 = Tosca_outD(1,34)/1000; //initial energy in km^2/s^2
m=Tosca_outD(1,8); M_0=Tosca_outD(1,24);
//Read the initial condition of drag
Cd_0=Tosca_outD(1,23);
D_0=Tosca_outD(1,21)/m; //in m/s²
g_0= mu/(r_0^2);
//WAYPOINT condition
fcd=mopen(pwd() +'\INPUT.dat','r');// open file
mgetl(fcd,8);
lon_1=mfscanf(fcd,'%e'); mgetl(fcd,2);
lat_1 =mfscanf(fcd,'%e'); mgetl(fcd,2);
r_1=mfscanf(fcd,'%e'); //radius in km
mgetl(fcd,2);
E_1=mfscanf(fcd,'%e');//Specific energy in km²/s²
mclose(fcd); clear fcd;
Xt=r_1.*[cosd(lon_1)*cosd(lat_1); sind(lon_1)*cosd(lat_1); sind(lat_1)]; //Target position vector
//// Constraints
// Max heating and loading allowed, based on the max heating and loading analysis conducted on the previous SpaceLiner configuration
q_lim = 2000000; //max heat flux allowed in W/m^2
ac_lim = 24.5; //max loading allowed in g's.
p_lim = 60000; //Max dynamic pressure allowed in Pa.
exec(pwd() +'\fround.sci', -1); mkdir(pwd()+'/Graphs');
////============================================================================ //---START FIRST ENTRY PLANNING---////============================================================================
//GREAT CIRCLE ARC APPROXIMATION================================================
r=(r_1+r_0)/2; //Mean radius
h=r-R;//altitude
[T] = CL_mod_atmUS76(h); //Temperature at mean radius
g=mu/(r^2); //Gravity at mean radius
Cen_angler=acos(sind(lat_0)*sind(lat_1)+cosd(lat_0)*cosd(lat_1)*cosd(abs(lon_0-lon_1)));
L=r*Cen_angler; //Trajectory lenght desired //clear Cen_angler;
//Create energy interval
x=60;//Split energy interval in x part
p=(E_1-E_0)/x; eref = [E_0:p:E_1]; l=length(eref)+1;
e(1,l)=[];//create new vector for a new point
e(1,1)=eref(1,1);
e(1,2)=eref(1,1)-0.0001;
e(1,3:l)=eref(1,2:length(eref)); clear eref l;
//Calculate velocity and mach number
for i=1:length(e)
V(1,i)=sqrt(2*(e(1,i)+mu/r));
M(1,i)=V(1,i)/(sqrt(Sp_ratio*R_Air*T)); end
clear i;
//Value of Cd and L/D for each energy //Linear interpolation
a=Aero_database(:,1).';//value of mach number
b=Aero_database(:,2).';//value of Cd c=Aero_database(:,3).';//value of L/D Cd=interpln([a;b],M); L_D=interpln([a;c],M); for i=1:length(e)-1 Cdpr(1,i)=(Cd(1,i+1)-Cd(1,i))/(-p); Cdpr(1,length(e))=Cdpr(1,i); end clear a b c i;
//Defining entry corridor---//Vehicle constraints
//Maximum and minimum value of drag acceleration in m/s²
for i=1:length(e)
Dmax_p (1,i)=p_lim.*Cd(1,i).*S./m; Dmax_ac (1,i)=ac_lim*(1+L_D(1,i)^2)^-0.5; Dmax_q
(1,i)=(((q_lim)^2*Cd(1,i)*S*rho_ref*Rn*(V(1,i)*1000)^2)/(2*m*ch^2*1))*(V(1,i)/v_ref)^(
-2*3.05);
Dmin_eq0(1,i)=((g-(V(1,i)^2)/r)*(L_D(1,i))^-1)*1000; //in m/s²
e_norm(1,i)=((e(1,i)-E_0)./(E_1-E_0)); //Normalized energy
end
Corr=[Dmax_p;Dmax_ac;Dmax_q;Dmin_eq0]; scf(0);
plot(e_norm',Corr')
a=gca(); // Handle on current axes entity
a.data_bounds=[0 0;1 18]; xlabel("Normalized energy"); ylabel("Drag acceleration[m/s²]");
xs2eps(scf(0), pwd()+'/Graphs/Corridor1.eps'); clear a Dmax_p Dmax_ac Dmax_q Dmin_eq0 i;
//Calculate Drag
profile---Cdpr_0=(Cd(1,2)-Cd_0)/(-p); //Value of derivative at initial time (from ascent to start descent)
Dpr_0=(2*D_0/1000)/V_0^2+Cdpr_0*D_0/(1000*Cd_0)+sind(gamma_0)*(1/H+2*g_0/V_0^2)//Value of drag derivative at initial time (from ascent to start descent) in 1/km
e_1 = e(1,2);//Energy step changes
exec(pwd() +'\fun.sci', -1); exec(pwd() +'\dFdx.sci', -1); exec(pwd() +'\drag.sci', -1);
scf(1);
plot(e_norm',[drag(e)' Corr']); set(gca(),"grid",[1 1]);
a=gca(); // Handle on current axes entity
a.data_bounds=[0 0;1 18];
xlabel("Normalized energy [E-E0/E1-E0]"); ylabel("Drag acceleration [m/s²]");
legend(["Drag accelleration profile";"Maximum dynamic pressure";"Maximum acceleration";"Maximum heat flux";"Equilibrium glide"]);
xs2eps(scf(1), pwd()+'/Graphs/DragProfile1.eps'); clear a ;
//Check if the drag profile chosen fits into the corridor
d=drag(e);//In m/s²
for i=1:length (e)
if e(1,i)>=e_1
if d(1,i)<Corr(4,i) then
disp("ERROR. Below equilibrium glide condition. Increase angle-of-attack or reconsider drag derivatives (increase time step of energy)");
break;
else if d(1,i)>=Corr(3,i) then
disp("ERROR. Beyond heat flux constraints. Increase angle-of-attack. "); break;
end
end
else if e(1,i)<=e_1 & e(1,i)>=E_1 if d(1,i)<Corr(4,i) then
disp("ERROR. Below equilibrium glide condition. Decrease angle-of-attack"); break;
else if d(1,i)>=Corr(3,i) then
disp("ERROR. Beyond heat flux constraints. Increase angle-of-attack"); break; end end end end end
D=d./1000; //In km/s²
D_1=d(1,2); c=D_1/1000;
b=E_1-e_1; //intervall
Dpr_1=(D(1,length(e))-c)/b; Dpr=zeros(length(D)); Dpr(1,1:2)=Dpr_0; //in 1/km Dpr(1,3:length(e))=Dpr_1;//in 1/km clear a b c i; /////---//LONGITUDINAL PLANNIGN CONTROL================================================= /////---//Estimate L/Dcos(sigma)
Long_contr0=zeros(length(D));
for i=1:length(D) a(1,i)=(-D(1,i)*((Cdpr(1,i)^2)/(Cd(1,i)^2))+Dpr(1,i)*(2/(V(1,i)^2)+Cdpr(1,i)/Cd(1,i)) -4*D(1,i)/(V(1,i)^4)+(1/(D(1,i)*V(1,i)^2))*(g-(V(1,i)^2)/r)*(1/H+2*g/(V(1,i)^2))); b(1,i)=(-(1/(V(1,i)^2))*(1/H+2*g/(V(1,i)^2))); Long_contr0(1,i)=-a(1,i)/b(1,i); end clear i a b;
//EXTRACTION r(E) and gamma(E)==================================================
//Calculating gamma at E0 and E1 and estimate the derivative with the finite difference approximation at initial energy.
gamma_a= asin((Dpr(1,1)-2*D(1,1)/(V(1,1)^2)-D(1,1)*Cdpr(1,1)/Cd(1,1))/(1/H+2*g/(V(1,1)^2))); gamma_b= asin((Dpr(1,2)-2*D(1,2)/(V(1,2)^2)-D(1,2)*Cdpr(1,2)/Cd(1,2))/(1/H+2*g/(V(1,2)^2))); gamma_pr0=(gamma_b-gamma_a)/(-p)
//r EXTRACTION---//Solve r´ (e) `= -sin gamma (1/D) starting from r (E0)
//Evaluate r(E0)
a=2*e(1,1)*gamma_pr0*D(1,1)+Long_contr0(1,1)*D(1,1); b=-2*e(1,1)-2*mu*D(1,1)*gamma_pr0;
pol= [a -b mu]; x=roots(pol);
r_E0=real(x(2,1)); //Initial condition at E=0 in km.
V_E0sq=2*(E_0+mu/r_E0); //Velocity squared at E=0
g_E0=mu/(r_E0^2);
clear a b x pol gamma_a gamma_b gamma_pr0;
//Euler integration
rstar=zeros(size(e)); rstar(1) = r_E0; for i=1:(length (e)-1) k1 = (Dpr(1,i)/D(1,i)-2/(2*(e(1,i)+mu/rstar(i))) -Cdpr(1,i)/Cd(1,i))/(1/H+2*mu/((rstar(i)^2)*2*(e(1,i)+mu/rstar(i)))); rstar (i+1) = rstar(i)+k1*(-p); end;
clear i k1 ;
//gamma
EXTRACTION---gamma_E0=asin((Dpr(1,1)-2*D(1,1)/(V_E0sq)-D(1,1)*Cdpr(1,1)/Cd(1,1))/(1/H+2*g_E0/(V_E0sq)));
//gamma at initial energy with different velocity and gravity acceleration but not changes in Drag acceleration
//Euler integration
gamstar=zeros(size(e)); gamstar(1) = gamma_E0;
for i=1:(length (e)-1)
g1 = (mu/(rstar(i)^2)
-2*(e(1,i)+mu/rstar(i))/(rstar(i)))*(1/(D(1,i)*2*(e(1,i)+mu/rstar(i))))
-(1/(2*(e(1,i)+mu/rstar(i))))*(Long_contr0(1,i)); gamstar (i+1) = gamstar(i)+g1*(-p); end; clear i g1 gamma_E0; for i=1:length(e) Vnew(1,i)=sqrt(2*(e(1,i)+mu/rstar(1,i))); gnew(1,i)=mu/(rstar(1,i)^2); a(1,i)=(-D(1,i)*((Cdpr(1,i)^2)/(Cd(1,i)^2))+Dpr(1,i)*(2/(Vnew(1,i)^2)+Cdpr(1,i)/Cd(1,i))
-4*D(1,i)/(Vnew(1,i)^4)+(1/(D(1,i)*Vnew(1,i)^2))*(gnew(1,i)
-(Vnew(1,i)^2)/rstar(1,i))*(1/H+2*gnew(1,i)/(Vnew(1,i)^2))); b(1,i)=(-(1/(Vnew(1,i)^2))*(1/H+2*gnew(1,i)/(Vnew(1,i)^2))); Long_contr1(1,i)=-a(1,i)/b(1,i);
argu(1,i)=Long_contr1(1,i)/L_D(1,i); if argu(1,i)>1 then
argu(1,i)=0.99999; end
sigma(1,i)=acosd(argu(1,i));//Evaluating sigma
end
//Evaluating sigma
clear i a b Vnew gnew g_E0 r_E0 V_E0sq;
//SCHIFT TO TIME DOMAIN ======================================================== //Define function for the integral
exec(pwd() +'\f.sci', -1);
//Solve the integral for having each time step reloated to energy step.
tstar=zeros(1,length(e));
for j=1:length(e)-1
X=intg(e(1,j),e(1,(j+1)),f);//solve integral of y from ta to tb
tstar(1,j+1)=tstar(1,j)-X; //Calculate the time corrisponding to the value of successive energy
end
clear j X;
//Read timestep in Tosca
fcd=mopen(filepath1+'\tosca_in.data','r');// open file
tt=mfscanf(fcd,'%e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e %e'); //read the value of Time Step (43 gridpoints)
mclose(fcd);
t(1,1:43)=tt;
t(1,44:length(e))=%nan; clear fcd s in ;
//Interpolation between value of time.
for i=1:length(e)
if t(1,i)>tstar(1,length(tstar)) then
break; else
treal(1,i)=t(1,i); end
end
sigmaref=interpln([tstar;sigma],treal); clear i;
sigmaref=sign_Sigma1.*(sigmaref.'); sigmaref_round1=fround(sigmaref,2);
sigmaref_round1(length(sigmaref)+1:43,1)=0; in_file1=cat(2,sigmaref_round1, tt.'); deletefile('bankangle_ref1.dat');
write('bankangle_ref1.dat',in_file1,'(,2(f10.2,))');//generate the output file
//WRITE THE RESULT IN THE TOSCA INPUT FILE//////////////////////////////////// // Replace tosca_in.data with a version with the new inputs
// Open the original input file
all = mgetl(filepath1+'\tosca_in.data');
// Replace lines with new input lines // Active controls
all(176:218)=string(alpha1) +" "+string(sigmaref_round1(:,1))+ " " +string(tt.');
// Replace all the lines of the old input file with the newly made input file
fd = mopen(filepath1+'\tosca_in.data','wt');
for q = 1:size(all,1)
mfprintf(fd,'%s \n',all(q));
end
mclose(fd);
clear q all fd;
//Save final time and variables I need for the second entry planning
t_1s= t(1,length(treal)); //final time of the first entry planning
save("final1.sod","t_1s","rho_ref","mu", "H","g_ref","R",
"Sp_ratio","R_Air","S","Rn","ch","v_ref","alpha1","sigmaref_round1");
//---RUN
TOSCA---disp("Tosca_in.data is being changed with the reference value of bank angle. RUN TOSCA.");
pause;
////============================================================================ //--- LATERAL PLANNING---////============================================================================
//After the simulation of the reference value of sigma, investigate in the lateral planning. //Read the actual data from TOSCA after it was simulated with the bank angle calculated.
exec(pwd() +'\ToscaOUTread1.sce', -1);
//build the vector of energy until last value in reverse order for the interpolation
eflip=flipdim(e,2); //reverse order the energy step in feasible planning
Eb(1,1:length(e))=eflip(1,1:length(e)); //build vector of energy until the end of simulation
Eb(1,(length(e)+1):length(Ea))=[];
Ea=flipdim(Ea,1); //reverse order of energy simulated
Da=flipdim(Da,1);//reverse order of drag simulated
Da_pr=flipdim(Da_pr,1); //reverse order of drag derivative simulated
Cda=flipdim(Cda,1);//reverse order of drag coefficient simulated
drag_int=interpln([Ea.';Da.'],Eb);//interpolation of drag simulated in time step of the planning
dragder_int=interpln([Ea.';Da_pr.'],Eb); //interpolation of drag derivative simulated in time step of the planning
Cda_int=interpln([Ea.';Cda.'],Eb);//interpolation of drag coefficient simulated in time step of the planning
drag_int=flipdim(drag_int(1,1:length(e)),2)//restor order
dragder_int=flipdim(dragder_int(1,1:length(e)),2); Cda_int=flipdim(Cda_int(1,1:length(e)),2);
//Plot the reference and simulated drag
profile---scf(2);
plot(e_norm',[Dpr' dragder_int']); //plot difference in drag derivative
set(gca(),"grid",[1 1]); xlabel("Normalized energy");
ylabel("Drag acceleration derivatives [1/km]");
legend(["Drag reference derivative";"Drag simulated derivative"]); xs2eps(scf(2), pwd()+'/Graphs/Dragdersim1.eps');
scf(3);
plot(e_norm',[D' drag_int']); //plot difference in drag
set(gca(),"grid",[1 1]); xlabel("Normalized energy");
ylabel("Drag acceleration [km/s²]");
legend(["Drag reference";"Drag simulated"]); xs2eps(scf(3), pwd()+'/Graphs/Dragsim1.eps');
exec(pwd() +'\PLOT_HEADING1.sce', -1);
x=input("Add the Lateral planning? Check on Geoplot. (Yes/No) ","string");
if x==string('Yes') then
disp("Star the Lateral Planning");
else
disp("Star the Second Entry Planning"); abort;
end
//Actual bank angle: reference(if it is omitted the feedback) or after feedback
if exists("sigma_new1") then
sig_actual=sigma_new1;
else
sig_actual=sigmaref_round1;
end
//Read the actual data from TOSCA after it was simulated with the bank angle calculated.
exec(pwd() +'\ToscaOUTread1.sce', -1); exec(pwd() +'\lat_guidance1.sce', -1);
if n1(1,1)<=1 then
disp(" seconds are set to 0. Resume to plot the heading error. ",tt(1,sigma0),"Value of bank angle after ");
pause;
exec(pwd() +'\PLOT_HEADING1.sce', -1); abort;
end
disp("First change sign Done in tosca_in.data. RUN TOSCA. "); sigmaFIN1=sig_actual;
in_file1lat=cat(2,sigmaFIN1, tt.'); deletefile('bankangle1_lat.dat');
write('bankangle1_lat.dat',in_file1lat,'(,2(f10.2,))');//generate the output file
save("final1.sod","t_1s","rho_ref","mu", "H","g_ref","R",
"Sp_ratio","R_Air","S","Rn","ch","v_ref","alpha1","sig_actual");
pause;
//---RUN TOSCA
3---//Read the actual data from TOSCA after it was simulated with the bank angle calculated.
exec(pwd() +'\ToscaOUTread1.sce', -1); exec(pwd() +'\lat_guidance1.sce', -1);
disp("Second change sign Done in tosca_in.data. RUN TOSCA and then start second reentry. ");
sigmaFIN1=sig_actual;
in_file1lat=cat(2,sigmaFIN1, tt.'); deletefile('bankangle1_lat.dat');
write('bankangle1_lat.dat',in_file1lat,'(,2(f10.2,))');//generate the output file
save("final1.sod","t_1s","rho_ref","mu", "H","g_ref","R",
"Sp_ratio","R_Air","S","Rn","ch","v_ref","alpha1","sig_actual"); disp ("Show heading");
pause;
exec(pwd() +'\PLOT_HEADING1.sce', -1);
//---RUN TOSCA
4---function J=dFdx(x)
Endfunction
function F=fun(x) //function of the final value of drag
F=a+(b./(x-c)).*log(x./c);
endfunction
function d=drag(e)
for i=1:length (e)
if e(1,i)>=e_1
d(1,i) = D_0+Dpr_0*(e(1,i)-E_0)*1000; //first segment
D_1=d(1,i);//m/s²
S1=(1/Dpr_0)*log(D_1/D_0); //Range cover in the first segment
else if e(1,i)<=e_1 & e(1,i)>=E_1
S1=(1/Dpr_0)*log(D_1/D_0); //Range cover in the first segment
a=L+S1; //remain range to cover
b=E_1-e_1; //intervall
c=D_1/1000; //in km/s²
No = 0;//solve for the second segment - Newthon Method
x1 = 0;
x0 = 0.001; //initial value for start the computation
errors = 1e-4;
while (abs(fun(x0)) > errors)
disp(x0); x1 = x0 - fun (x0)./ dFdx(x0); x0 = x1; No = No + 1; end; Dpr_1=(x1-c)/b;
d(1,i)=D_1+Dpr_1*(e(1,i)-e_1)*1000; //second segment
end end end funcprot(0); endfunction //LATERAL PLANNING==============================================================
if exists("index") then
clear h_corr head_error index;
end
//Calculate the projection of velocity vector, and the difference position vector with respect to the horizontal plane.
Xt=r_1.*[cosd(lon_1)*cosd(lat_1); sind(lon_1)*cosd(lat_1); sind(lat_1)]; //Target position vector
for i=1:length(Va)
Vp(1,i)=Va(i,1)*cosd(gammaa(i,1))*(-cosd(teta(i,1))*sind(phi(i,1))*cosd(psi(i,1))
-sind(teta(i,1))*sind(psi(i,1))); //first component of the vector velocity pojected in the
horizontal plane
Vp(2,i)=Va(i,1)*cosd(gammaa(i,1))*(
-sind(teta(i,1))*sind(phi(i,1))*cosd(psi(i,1))+cosd(teta(i,1))*sind(psi(i,1))); Vp(3,i)=Va(i,1)*cosd(gammaa(i,1))*(cosd(phi(i,1))*cosd(psi(i,1)));