-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball2.ks
executable file
·154 lines (144 loc) · 3.71 KB
/
ball2.ks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function GETDENSITY {
parameter altitude.
set LOWDENS TO 0.
set HIGHDENS TO 0.
SET MIX TO 1.
if (altitude < 2500)
{
SET LOWDENS TO 1.225.
SET HIGHDENS TO 0.898.
SET MIX TO altitude/2500.
} else if (altitude < 5000)
{
SET LOWDENS TO 0.898.
SET HIGHDENS TO 0.642 .
SET MIX TO (altitude-2500)/2500.
} else if (altitude < 7500)
{
SET LOWDENS TO 0.642 .
SET HIGHDENS TO 0.446.
SET MIX TO (altitude-5000)/2500.
} else if (altitude < 10000)
{
SET LOWDENS TO 0.446.
SET HIGHDENS TO 0.288.
SET MIX TO (altitude-7500)/2500.
} else if (altitude < 15000)
{
SET LOWDENS TO 0.288.
SET HIGHDENS TO 0.108 .
SET MIX TO (altitude-10000)/5000.
} else if (altitude < 20000)
{
SET LOWDENS TO 0.108.
SET HIGHDENS TO 0.040 .
SET MIX TO (altitude-15000)/5000.
} else if (altitude < 25000)
{
SET LOWDENS TO 0.040 .
SET HIGHDENS TO 0.015 .
SET MIX TO (altitude-20000)/5000.
} else if (altitude < 30000)
{
SET LOWDENS TO 0.015 .
SET HIGHDENS TO 0.006 .
SET MIX TO (altitude-25000)/5000.
} else if (altitude < 40000)
{
SET LOWDENS TO 0.006 .
SET HIGHDENS TO 0.001.
SET MIX TO (altitude-30000)/10000.
} else if (altitude < 70000)
{
SET LOWDENS TO 0.001.
SET HIGHDENS TO 0.0001.
SET MIX TO (altitude-40000)/30000.
} else
{
RETURN 0.
}
RETURN (LOWDENS*(1-MIX))+(HIGHDENS*(MIX)).
}.
function GETBALLISTICX {
parameter STARTINGALT.
parameter Uo.
parameter Vo.
parameter Cd.
SET g to body:mu / (STARTINGALT + body:radius)^2.
SET Vt TO SQRT((2*SHIP:MASS*g)/(Cd*Density)).
SET ESTFALLTIME TO (Vo/g)*2.
SET ymax TO (Vt^2 / (2 * g)) * ln ((Vo^2 + Vt^2)/Vt^2).
SET ITERATIONS TO 10.
UNTIL (ITERATIONS = 0)
{
SET NEWG TO body:mu / ((STARTINGALT+ymax) + body:radius)^2.
SET Vt TO SQRT((2*SHIP:MASS*NEWG)/(Cd*GETDENSITY((STARTINGALT+ymax)/2))).
SET ymax TO (Vt^2 / (2 * NEWG)) * ln ((Vo^2 + Vt^2)/Vt^2).
SET AVGG TO (g+NEWG)/2.
SET FALLTIMENEW TO (Vo/AVGG)*2.
SET X TO ((Vt*Vt)/AVGG)*(LN(((Vt*Vt)+AVGG*Uo*FALLTIMENEW)/(Vt*Vt))).
SET ITERATIONS TO ITERATIONS - 1.
}.
RETURN X.
}
function PRINTDATA {
LOCK CALCHORV TO COS((ARCSIN(SHIP:VERTICALSPEED/SHIP:AIRSPEED)))*SHIP:AIRSPEED.
IF (SHIP:VERTICALSPEED > 0)
{
PRINT "CURRENT X:" + GETBALLISTICX(ALTITUDE, SHIP:VERTICALSPEED, CALCHORV, Cd) at (20,0).
}.
PRINT "KSCDIST: " + KSCSPOT:DISTANCE AT (20,1).
PRINT "KSDCLOSING: "+ KSCCLOSINGV AT (20,2).
PRINT "STAGE: " + MISSIONSTAGE AT (20,3).
}
CLEARSCREEN.
SET Cd TO 0.007.
SET Density TO 1.225.
SET MISSIONSTAGE TO 0.
SET KSCALT TO ALTITUDE.
SET KSCSPOT to SHIP:GEOPOSITION.
SET LASTKSCDIST TO KSCSPOT:DISTANCE.
SET KSCCLOSINGV TO 0.
SET KSCGEO TO SHIP:GEOPOSITION.
LOCK CALCHORV TO COS((ARCSIN(SHIP:VERTICALSPEED/SHIP:AIRSPEED)))*SHIP:AIRSPEED.
SET DELTATIME TO 0.1.
SET LASTTIME TO TIME:SECONDS.
WAIT 0.01.
SET DELTATIME TO TIME:SECONDS - LASTTIME.
STAGE.
UNTIL (FALSE)
{
PRINTDATA().
WAIT 0.01.
SET DELTATIME TO TIME:SECONDS - LASTTIME.
SET LASTTIME TO TIME:SECONDS.
SET ABOVEKSC TO LATLNG(KSCGEO:LAT,KSCGEO:LNG):ALTITUDEPOSITION(ALTITUDE).
SET KSCDIST TO SHIP:GEOPOSITION:LNG - KSCSPOT:LNG.
SET KSCCLOSINGV TO (KSCDIST-LASTKSCDIST)/DELTATIME.
SET LASTKSCDIST TO KSCDIST.
IF (MISSIONSTAGE = 0)
{
LOCK STEERING TO HEADING(90,85 + (15 * (1-((1500-ALTITUDE)/1500)))).
LOCK THROTTLE TO 1.0.
IF (ALTITUDE > 1500)
{
SET MISSIONSTAGE TO 1.
}
}
IF (MISSIONSTAGE = 1)
{
//LOCK STEERING TO LATLNG(KSCGEO:LAT,KSCGEO:LNG):ALTITUDEPOSITION(ALTITUDE).
LOCK STEERING TO HEADING(270,70).
LOCK THROTTLE TO 1.0.
SET BALLX TO GETBALLISTICX(ALTITUDE, SHIP:VERTICALSPEED, CALCHORV, Cd).
IF (BALLX > KSCDIST AND KSCCLOSINGV < 0)
{
SET MISSIONSTAGE TO 2.
}
}
IF (MISSIONSTAGE = 2)
{
LOCK STEERING TO HEADING(270,90).
LOCK THROTTLE TO 0.0.
}
}.