-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathov_mm7.ks
217 lines (179 loc) · 5.8 KB
/
ov_mm7.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
////////////////////////////////////////////////////////////////////////////////
// OV MAJOR MODE 7 (ORBITAL CALCULATIONS)
////////////////////////////////////////////////////////////////////////////////
FUNCTION MM7_ENTER {
// SET UP THE NODE
GLOBAL ORBITAL_NODE TO NODE(TIME:SECONDS+200, 0, 0, 0).
IF NOT HASNODE {
ADD ORBITAL_NODE.
} ELSE {
SET ORBITAL_NODE TO NEXTNODE.
}
// SOME GLOBAL VARS
GLOBAL TIME_ESTIMATE TO 0.
}
FUNCTION MM7_LEAVE {
//
}
FUNCTION MM7_TRANSFER {
// ALWAYS RESET DISPLAY
RESET_DISPLAY().
// ESTIMATE ENTRY BURN DV
IF MINOR_MODE = 0 {
// RESET ENTRY DV ESTIMATION
SET ORBITAL_NODE:ETA TO 5000.
SET ORBITAL_NODE:PROGRADE TO -50.
MM7_RESET_EI_ESTIMATE(5000).
TASK_SCHEDULE(1, MM7_COMPUTE_ENTRY_DV_TASK@).
}
// ESTIMATE ENTRY BURN TIME
IF MINOR_MODE = 1 {
// RESET ENTRY TIME ESTIMATION
GLOBAL TIME_OFFSET TO 300.
SET ORBITAL_NODE:ETA TO TIME_OFFSET.
MM7_RESET_EI_ESTIMATE(TIME_ESTIMATE + TIME_OFFSET).
TASK_SCHEDULE(1, MM7_COMPUTE_ENTRY_TIME_TASK@).
}
}
FUNCTION MM7_COMMAND {
PARAMETER VERB, VALUE.
// RESET CALCULATIONS
IF VERB = 1 {
IF MINOR_MODE = 0 {
MM7_COMPUTE_ENTRY_DV_NEXT_ESTIMATE().
SET ORBITAL_NODE:PROGRADE TO -VALUE.
}
IF MINOR_MODE = 1 {
MM7_COMPUTE_ENTRY_TIME_NEXT_ESTIMATE().
SET TIME_OFFSET TO VALUE.
SET ORBITAL_NODE:ETA TO TIME_OFFSET.
}
}
IF VERB = 2 {
MM7_RESET_EI_ESTIMATE(VALUE).
}
}
//
// RESET ENTRY INTERFACE ESTIMATION
//
FUNCTION MM7_RESET_EI_ESTIMATE { PARAMETER ETA.
GLOBAL DR_DT TO 0.
GLOBAL DT_MUL TO 1.0.
GLOBAL EI_DOWNRANGE TO 0.
GLOBAL EI_FLIGHTPATH TO 0.
GLOBAL EI_ESTIMATE TO TIME:SECONDS + ETA.
}
//
// ESTIMATE ENTRY INTERFACE TIME
//
FUNCTION MM7_ESTIMATE_EI_STEP {
LOCAL DT0 IS 1.0.
LOCAL R1 IS (SHIP:BODY:ALTITUDEOF(POSITIONAT(SHIP, EI_ESTIMATE - DT0)) - 70000)^2.
LOCAL R2 IS (SHIP:BODY:ALTITUDEOF(POSITIONAT(SHIP, EI_ESTIMATE + DT0)) - 70000)^2.
// COMPUTE DERIVATIVE AND CHECK CONVERGENCE RATE
LOCAL DR_DT1 TO 0.00001*(R2 - R1)/DT0.
IF (DR_DT < 0) AND (DR_DT1 > 0) {
SET DT_MUL TO DT_MUL*0.5.
}
IF (DR_DT > 0) AND (DR_DT1 < 0) {
SET DT_MUL TO DT_MUL*0.5.
}
SET DR_DT TO DR_DT1.
// UPDATE ESTIMATE
SET EI_ESTIMATE TO MAX(TIME:SECONDS, EI_ESTIMATE - DR_DT*DT_MUL).
}
//
// RESET VELOCITY ESTIMATE
//
FUNCTION MM7_COMPUTE_ENTRY_DV_NEXT_ESTIMATE {
SET ORBITAL_NODE:PROGRADE TO ORBITAL_NODE:PROGRADE - 5.
SET ORBITAL_NODE:ETA TO 5000.
SET EI_ESTIMATE TO TIME:SECONDS + ORBITAL_NODE:ETA + 300.
}
FUNCTION MM7_COMPUTE_ENTRY_DV_TASK { PARAMETER DT.
// CHECK IF TARGET ORBIT IS VALID AT ALL
IF ORBITAT(SHIP, TIME:SECONDS + ORBITAL_NODE:ETA + 100):PERIAPSIS > 50000.0 {
MM7_COMPUTE_ENTRY_DV_NEXT_ESTIMATE().
} ELSE {
// ESTIMATE ENTRY INTERFACE
MM7_ESTIMATE_EI_STEP().
// CHECK FLIGHT PATH ANGLE
LOCAL DT0 IS 5.0.
LOCAL ALTITUDE0 IS SHIP:BODY:ALTITUDEOF(POSITIONAT(SHIP, EI_ESTIMATE - DT0)).
LOCAL ALTITUDE1 IS SHIP:BODY:ALTITUDEOF(POSITIONAT(SHIP, EI_ESTIMATE + DT0)).
LOCAL VELOCITY0 IS VELOCITYAT(SHIP, EI_ESTIMATE):ORBIT:MAG.
SET EI_FLIGHTPATH TO ARCTAN((ALTITUDE0 - ALTITUDE1)/(VELOCITY0*2*DT0)).
// CHECK IF ESTIMATE IS BAD
IF (EI_ESTIMATE < TIME:SECONDS+1) AND (DR_DT > 0) {
MM7_COMPUTE_ENTRY_DV_NEXT_ESTIMATE().
}
// CHECK IF FLIGHT PATH IS BAD
IF ABS(DR_DT) < 0.1 {
IF EI_FLIGHTPATH < 8.20 {
MM7_COMPUTE_ENTRY_DV_NEXT_ESTIMATE().
} ELSE {
SET TIME_ESTIMATE TO EI_ESTIMATE - TIME:SECONDS - 5000.0.
TRANSFER_MODE(7,1).
}
}
}
IF MINOR_MODE = 0 {
TASK_SCHEDULE(1, MM7_COMPUTE_ENTRY_DV_TASK@).
}
}
//
// RESET TIME ESTIMATE
//
FUNCTION MM7_COMPUTE_ENTRY_TIME_NEXT_ESTIMATE {
//SET TIME_ESTIMATE TO (EI_ESTIMATE - TIME:SECONDS) - ORBITAL_NODE:ETA.
SET TIME_OFFSET TO TIME_OFFSET + 5.
SET ORBITAL_NODE:ETA TO TIME_OFFSET.
MM7_RESET_EI_ESTIMATE(ORBITAL_NODE:ETA + 500).
}
FUNCTION MM7_COMPUTE_ENTRY_TIME_TASK { PARAMETER DT.
// ESTIMATE ENTRY INTERFACE
MM7_ESTIMATE_EI_STEP().
// CALCULATE EI DOWNRANGE
LOCAL EI_POSITION TO SHIP:BODY:GEOPOSITIONOF(POSITIONAT(SHIP, EI_ESTIMATE)).
// ESTIMATE WITH EQUIRECTANGULAR APPROXIMATION
LOCAL L1 IS CONSTANT:PI*(EI_POSITION:LNG - RUNWAY:LNG)/180.0.
LOCAL F1 IS CONSTANT:PI*(EI_POSITION:LAT + RUNWAY:LAT)/180.0.
LOCAL F2 IS CONSTANT:PI*(EI_POSITION:LAT - RUNWAY:LAT)/180.0.
LOCAL X IS L1*COS(F1/2).
LOCAL Y IS F2.
SET EI_DOWNRANGE TO SQRT(X^2 + Y^2)*BODY("KERBIN"):RADIUS.
// CHECK IF ESTIMATE IS BAD
//IF (EI_ESTIMATE < TIME:SECONDS+1) AND (DR_DT > 0) {
//SET EI_ESTIMATE TO TIME:SECONDS + ORBITAL_NODE:ETA + 700.0.
//MM7_COMPUTE_ENTRY_DV_NEXT_ESTIMATE().
//}
// CHECK IF ENTRY DOWNRANGE IS BAD
IF ABS(DR_DT) < 0.1 {
IF (EI_DOWNRANGE < 440000) OR (EI_DOWNRANGE > 480000) {
MM7_COMPUTE_ENTRY_TIME_NEXT_ESTIMATE().
} ELSE {
// ..
}
}
IF MINOR_MODE = 1 {
TASK_SCHEDULE(1, MM7_COMPUTE_ENTRY_TIME_TASK@).
}
}
FUNCTION MM7_UI_TASK { PARAMETER DT.
TASK_SCHEDULE(2, MM7_UI_TASK@).
IF (MINOR_MODE = 0) OR (MINOR_MODE = 1) {
UI_VARIABLE(" EI", "SEC", EI_ESTIMATE - TIME:SECONDS, 1,7, NUMBER, 0,1).
UI_VARIABLE(" PHI", "DEG", EI_FLIGHTPATH, 2,7, SIGNED, 0,2).
UI_VARIABLE(" EI ALT", "M", SHIP:BODY:ALTITUDEOF(POSITIONAT(SHIP,EI_ESTIMATE)), 0,7, NUMBER, 0,3).
UI_VARIABLE("DOWNRANGE", "M", ROUND(EI_DOWNRANGE/100,0)*100, 1,7, NUMBER, 0,4).
UI_VARIABLE(" DRDT", "M/S", DR_DT, 1,7, SIGNED, 0,7).
}
}.
////////////////////////////////////////////////////////////////////////////////
MODE_NAMES:ADD(70, "ENTRY BURN DV ").
MODE_NAMES:ADD(71, "ENTRY BURN TIME ").
MODE_ENTER (7, MM7_ENTER@).
MODE_TRANSFER (7, MM7_TRANSFER@).
MODE_LEAVE (7, MM7_LEAVE@).
MODE_COMMAND (7, MM7_COMMAND@).
MODE_TASK (7, MM7_UI_TASK@).