View difference between Paste ID: XGDE7Eck and WM7sAT43
SHOW: | | - or go back to the newest paste.
1-
//==Coyote Medium LS Launch script 1 and 1R==
1+
//==Coyote Medium LS Launch script 2, 2RB and 2R==
2
3
SET scriptVersion TO "v0.2.1".		//Version control
4
5
//~~CHANGELOG:~~
6
//0.1.0
7
// - First stable version
8
//
9
//0.2.0
10
//--Major improvements--
11
// - Added declared opMode to control vehicle version/operation mode
12
// - Added staging control for Mk2 versions
13
//--Minor improvements--
14
// - Improved handling of engines and activations/shutdowns
15
// - Improved fuel tank/fuel level handling
16
// - All fuel pumps will now be turned on before liftoff in order to keep
17
//   the boosters topped off in addition to the first and second stages
18
// - Removed redundant timers; antenna activation now occurs on fairing sep
19-
// - Commented out unused "exit loop"; saved for later iteration that
19+
// - Removed unused "exit loop"
20-
//   utilizes fault checking
20+
21
// - Changed script exit parameters; target apoapsis altitude is declared on
22
//   start and script closes when it is reached. A proper ascent should
23
//   allow for a healthy periapsis by this time.
24
//
25
//0.2.1
26
//--Major improvements--
27
// - Separated 1/1R versions from 2/2RB/2R versions to decrease script size
28-
// - Separated 1/1R versions from 2/2RB/2R versions to decrease script
28+
29-
//   size.
29+
30
31
32
//FUTURE SUBVERSION TODO:
33
// - Change engine startup/shutdown handling to use DOACTION instead of
34
//   DOEVENT
35-
// - Automatically adjust throttle to impose g-force limit
35+
// - Automatically adjust throttle/shutdown engines to impose g-force limit
36
// - Fault checking
37
// - Abort conditions and abort automation for future manned variant
38
// - Expanded readouts
39
// - Launch guidance assist (display vectors to aid manual control)
40-
// - Launch guidance automation (completely automate launch, one button
40+
// - Launch guidance automation (completely automate launch, one button press
41-
//   press to orbit)
41+
//   to orbit)
42
43-
DECLARE PARAMETER targetAlt.
43+
DECLARE targetAlt.
44
45
SET TERMINAL:WIDTH TO 50.
46
SET TERMINAL:HEIGHT TO 25.
47
CLEARSCREEN.
48
49
PRINT "========COYOTE MLS LAUNCH CONTROLLER SCRIPT=======".
50
PRINT "----------------------" + scriptVersion + "----------------------".
51
WAIT 0.25.
52
PRINT "Initializing...".
53
54
//~~~~~Variables~~~~~
55
SET countdown TO 10.		//Length of countdown. Minimum of five seconds required.
56
SET CDmessage TO " ".		//Holds messages for countdown loop
57
SET nextLine TO 7.		//Handles event log printing after liftoff
58
SET fairingSep TO FALSE.		//Variable to view fairing separation status; false = still attached
59
SET BECOtimer TO 10000.		//Marks BECO time
60
SET S1ECOtimer TO 10000.		//Marks S1ECO time
61-
SET activeStage TO "1".		//Variable to view active stage
61+
SET SBSepLevel TO 0.		//Percent of fuel desired for side booster RTLS.
62
SET S1SepLevel TO 0.		//Percent of fuel desired for first stage RTLS.
63
SET activeStage TO "1B".		//Variable to view active stage, Mk2 versions start at 1B (booster)
64
SET updateRes TO 10.		//Determines how many refreshes per second for the readout script
65
66-
IF SHIP:PARTSTAGGED("Mk1"):LENGTH > 0 {
66+
67-
	SET opMode TO "1".
67+
68
IF SHIP:PARTSTAGGED("Mk2"):LENGTH > 0 {
69-
} ELSE IF SHIP:PARTSTAGGED("Mk1R"):LENGTH > 0 {
69+
	SET opMode TO "2".
70-
	SET opMode TO "1R".
70+
71-
//	COPY CMLSSBURN FROM 0.
71+
} ELSE IF SHIP:PARTSTAGGED("Mk2RB"):LENGTH > 0 {
72
	SET opMode TO "2RB".
73
//	COPY CMLSSBURN TO 3.
74-
	SET S1SepLevel TO 15.
74+
//	COPY CMLSSBURN TO 4.
75
//	DELETE CMLSSBURN FROM 1.
76
	SET SBSepLevel TO 15.
77
78
} ELSE IF SHIP:PARTSTAGGED("Mk2R"):LENGTH > 0 {
79
	SET opMode TO "2R".
80
//	COPY CMLSSBURN TO 2.
81
//	COPY CMLSSBURN TO 3.
82
//	COPY CMLSSBURN TO 4.
83
//	DELETE CMLSSBURN FROM 1.
84
	SET SBSepLevel TO 15.
85
	SET S1SepLevel TO 20.
86-
IF opMode = "1R" {
86+
87
}. //IF
88
89-
}. //IF opMode antenna
89+
90
RUN CMLSeng.		//Tags all engines and shuts down any running
91
SWITCH TO 1.
92
93
//~~~~~Parts~~~~~
94
95
SET interStage TO SHIP:PARTSTAGGED("intstage")[0].		//Interstage fairing and decoupler between first and second stage
96
SET fairingShell TO SHIP:PARTSTAGGED("fairinghalf").		//Both fairing halves
97
98
IF opMode = "2RB" OR opMode = "2R" {
99
	SET SBAnt TO SHIP:PARTSTAGGED("SBAnt").         //Small omnidirectional antennae for booster communication
100
	SET SBfinHinges TO SHIP:PARTSTAGGED("SBFinHinge").
101
}. //IF opMode
102
103
IF opMode = "2R" {
104
	SET S1Ant TO SHIP:PARTSTAGGED("S1Ant")[0].		//Small omnidirectional antenna for first stage communication
105
	SET S1finHinges TO SHIP:PARTSTAGGED("S1FinHinge").
106
}. //IF opMode
107
108-
LOCK loxAmount TO S1LOX:AMOUNT.
108+
109
110
SET lClamps TO SHIP:PARTSDUBBED("launchclamp1").		//Launch clamps holding first stage/boosters down
111
FOR part IN lClamps {
112
	part:GETMODULE("RefuelingPump"):DOEVENT("Toggle Pump").		//Turn on fuel pump to keep stage topped off
113
}. //FOR lClamps pump
114
115
SET S2Tank TO SHIP:PARTSTAGGED("S2Tank")[0].
116
SET S1Tank TO SHIP:PARTSTAGGED("S1Tank")[0].
117
118
FOR res IN S1Tank:RESOURCES {
119
	IF res:NAME = "LQDOXYGEN" {
120
		SET S1LOX TO res.
121
		SET loxCap TO S1LOX:CAPACITY.
122
		
123
	}. //IF res
124
}. //FOR res
125
126
SET SBDecouplers TO SHIP:PARTSTAGGED("SBDecoup").
127
SET LBTank[0] TO SHIP:PARTSTAGGED("LBTankA")[0].
128
SET LBTank[1] TO SHIP:PARTSTAGGED("LBTankB")[0].
129
SET RBTank[0] TO SHIP:PARTSTAGGED("RBTankA")[0].
130
SET RBTank[1] TO SHIP:PARTSTAGGED("RBTankB")[0].
131
132
FOR res IN LBTank[0]:RESOURCES {
133
	IF res:NAME = "LQDOXYGEN" {
134
		SET LBLOX[0] TO res.
135
	}. //IF res
136
}. //FOR res
137
138
FOR res IN LBTank[1]:RESOURCES {
139
	IF res:NAME = "LQDOXYGEN" {
140
		SET LBLOX[1] TO res.
141
	}. //IF res
142
}. //FOR res
143
144
FOR res IN RBTank[0]:RESOURCES {
145
	IF res:NAME = "LQDOXYGEN" {
146
		SET RBLOX[0] TO res.
147
	}. //IF res
148
}. //FOR res
149
150
FOR res IN RBTank[1]:RESOURCES {
151
	IF res:NAME = "LQDOXYGEN" {
152
		SET RBLOX[1] TO res.
153-
WHEN loxRemaining <= (S1SepLevel / 100) THEN {		//Checks to see if first stage is at sep level, shutdown engines and extend fins if true
153+
154-
	FOR eng IN S1All {
154+
155-
		eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").
155+
156-
	}. //FOR eng shutdown
156+
SET loxCap TO (LBLOX[0]:CAPACITY + LBLOX[1]:CAPACITY + RBLOX[0]:CAPACITY + RBLOX[1]:CAPACITY).
157
LOCK loxAmount TO MIN((LBLOX[0]:AMOUNT + LBLOX[1]:AMOUNT),(RBLOX[0]:AMOUNT + RBLOX[1]:AMOUNT)).		//Locks remaining LOX amount to the lesser of the two side booster tanks (two tanks on each booster)
158
LOCK loxRemaining TO (loxAmount / (loxCap + 0.01)).		//Locks percentage of fuel left in stage +0.01 to avoid divide by zero/NaN
159
160-
	IF opMode = "1R" {
160+
161-
		FOR part IN S1finHinges {
161+
162-
			PART:GETMODULE("MuMechToggle"):DOACTION("move -",TRUE).
162+
163-
		}. //FOR finhinge move
163+
164-
		S1Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate").
164+
165
PRINT "Countdown sequence started".
166-
	}. //IF opMode
166+
167
UNTIL countdown = 0 {		//Countdown loop
168-
	RCS ON.
168+
169-
	SAS ON.
169+
170-
	PRINT "T+" + missionClock + " Stage 1 at sep level, staging" AT(0,nextLine).
170+
171
		}. //FOR eng
172-
	SET S1ECOtimer to missionClock.		//Marks the time at which S1ECO occurred
172+
173
		SET BEItime to TIME:SECONDS.		//Records BEI time
174-
	WHEN missionClock >= (S1ECOtimer + 1.5) THEN {		//Checks to see if 1.5 seconds has passed since S1ECO, quit extending fins if true
174+
175-
		IF opMode = "1R" {
175+
176-
			FOR part IN S1finHinges {
176+
177
		SAS ON.
178
179-
			
179+
180-
			PRINT "T+" + missionClock + " Fins extended" AT(0,nextLine).
180+
181-
			SET nextLine TO nextLine + 1.
181+
182-
			
182+
183-
		}. //IF opMode
183+
184
	
185-
		WHEN missionClock >= (S1ECOtimer + 2.5) THEN {		//Checks to see if 2.5 seconds have passed since S1ECO, stage sep if true
185+
186-
			interStage:GETMODULE("ModuleDecouple"):DOEVENT("Decouple").
186+
187-
			PRINT "T+" + missionClock + " Staging confirmed" AT(0,nextLine).
187+
188-
			SET nextLine TO nextLine + 1.
188+
189-
			SET activeStage TO 2.		//Denotes that stage 2 is now the active stage
189+
190-
			SET loxCap TO S2Tank:RESOURCES[1]:CAPACITY.
190+
191-
			LOCK loxAmount TO S2Tank:RESOURCES[1]:AMOUNT.
191+
192
193-
			WHEN missionClock >= (S1ECOtimer + 7.5) THEN {		//Checks to see if 5 seconds have passed since stage sep, MEI if true
193+
194-
				FOR eng IN S2Alpha {
194+
195-
					eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine").
195+
196-
				}.
196+
197-
				
197+
198-
				PRINT "T+" + missionClock + " MEI" AT(0,nextLine).
198+
199
200
//~~~~~Staging control~~~~~
201-
				WHEN SHIP:ALTITUDE > 60000 AND missionClock >= (S1ECOtimer + 10.5) THEN {		//Fairing sep at 60km or 3 seconds after stage 2 ignition, both conditions need satisfied
201+
202-
						FOR PART IN fairingShell {
202+
WHEN loxRemaining <= (SBSepLevel / 100) THEN {		//Checks to see if side boosters are at sep level
203-
							PART:GETMODULE("ProceduralFairingDecoupler"):DOEVENT("Jettison").
203+
	FOR eng IN LBAll {
204-
						}. //FOR loop
204+
		eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").		//Shutdown right booster engines
205-
						SET fairingSep TO TRUE.		//Readout will update to confirm fairing sep status
205+
	}. //FOR eng
206-
						S2Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate").		//Activate small omni on second stage
206+
207-
						PRINT "T+" + missionClock + " Fairing separation confirmed" AT(0,nextLine).
207+
	FOR eng IN RBAll {
208
		eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").		//Shutdown left booster engines
209-
					
209+
	}. //FOR eng
210-
				}. //WHEN SHIP:ALTITUDE
210+
211-
			}. //WHEN stage2StartTimer
211+
	FOR part IN SBfinHinges {
212-
		}. //WHEN BECOtimer decouple
212+
		PART:GETMODULE("MuMechToggle"):DOACTION("move -",TRUE).		//Extend side booster fins
213-
	}. //WHEN BECOtimer finHinges
213+
	}. //FOR finhinge move
214
215
	FOR part IN SBAnt {
216
		SBAnt:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate").		//Activate side booster antennas
217
	}. //FOR SBant
218
219
	PRINT "T+" + missionClock + " Boosters at sep level. Staging" AT(0,nextLine).
220
	SET nextLine TO nextLine + 1.
221
	SET BECOtimer to missionClock.		//Sets BECOtimer
222
223
	WHEN missionClock >= (BECOtimer + 1.5) THEN {
224
		IF opMode = "Mk2RB" OR opMode = "Mk2R" {
225
			FOR part IN S2finHinges {
226
				PART:GETMODULE("MuMechToggle"):DOACTION("move -",FALSE).
227
			}. //FOR finhinge stop
228
		}. //IF
229
230
		WHEN missionClock >= (BECOtimer + 2.5) THEN {
231
			FOR part IN SBDecouplers {
232
				part:GETMODULE("&*&*&MODULE GOES HERE&*&*&*"):DOEVENT("Decouple").		//Decouple side boosters &*&*&*&*TODO&*&*&*&*
233
			}. //FOR part
234
235
236
			WHEN loxRemaining <= (S1SepLevel / 100) THEN {		//Checks to see if first stage is at sep level
237
				FOR eng IN S1All {
238
					eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").		//Shutdown S1 engines
239
				}. //FOR eng shutdown
240
241
				IF opMode = "2RB" or opMode = "2R" {
242
					FOR part IN S1finHinges {
243
						PART:GETMODULE("MuMechToggle"):DOACTION("move -",TRUE).		//Extend fin hinges for reuseable core
244
					}. //FOR finhinge move
245
					S1Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate").		//Activate antenna for reuseable core
246
				}. //IF opMode
247
248
				RCS ON.
249
				SAS ON.
250
				PRINT "T+" + missionClock + " Stage 1 at sep level, staging" AT(0,nextLine).
251
				SET nextLine TO nextLine + 1.
252
				SET S1ECOtimer to missionClock.		//Marks the time at which S1ECO occurred
253
254
				WHEN missionClock >= (S1ECOtimer + 1.5) THEN {		//Checks to see if 1.5 seconds has passed since S1ECO
255
					IF opMode = "1R" {
256
						FOR part IN S1finHinges {
257
							PART:GETMODULE("MuMechToggle"):DOACTION("move -",FALSE).		//Quit extending fin hinges
258
						}. //FOR finhinge stop
259
						PRINT "T+" + missionClock + " Fins extended" AT(0,nextLine).
260
						SET nextLine TO nextLine + 1.
261
					}. //IF opMode
262
263
					WHEN missionClock >= (S1ECOtimer + 2.5) THEN {		//Checks to see if 2.5 seconds have passed since S1ECO
264
						interStage:GETMODULE("ModuleDecouple"):DOEVENT("Decouple").		//Separate core and second stage
265
						PRINT "T+" + missionClock + " Staging confirmed" AT(0,nextLine).
266
						SET nextLine TO nextLine + 1.
267
						SET activeStage TO 2.		//Denotes that stage 2 is now the active stage
268
						SET loxCap TO S2Tank:RESOURCES[1]:CAPACITY.		//Sets loxCap to stage 2 lox capacity
269
						LOCK loxAmount TO S2Tank:RESOURCES[1]:AMOUNT.		//Locks loxAmount to stage 2 lox amount
270
271
						WHEN missionClock >= (S1ECOtimer + 7.5) THEN {		//Checks to see if 5 seconds have passed since stage sep,
272
							FOR eng IN S2Alpha {
273
								eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine").		//Main engine ignition
274
							}.
275
							PRINT "T+" + missionClock + " MEI" AT(0,nextLine).
276
							SET nextLine TO nextLine + 1.
277
278
							WHEN SHIP:ALTITUDE > 60000 AND missionClock >= (S1ECOtimer + 10.5) THEN {		//Fairing sep at 60km or 3 seconds after stage 2 ignition, both conditions need satisfied
279
								FOR PART IN fairingShell {
280
									PART:GETMODULE("ProceduralFairingDecoupler"):DOEVENT("Jettison").		//Separate fairings
281
								}. //FOR loop
282
								SET fairingSep TO TRUE.		//Readout will update to confirm fairing sep status
283
								S2Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate").		//Activate small omni on second stage
284
								PRINT "T+" + missionClock + " Fairing separation confirmed" AT(0,nextLine).
285
								SET nextLine TO nextLine + 1.
286
287
							}. //WHEN SHIP:ALTITUDE
288
						}. //WHEN stage2StartTimer
289
					}. //WHEN BECOtimer decouple
290
				}. //WHEN BECOtimer finHinges
291
			}. //WHEN loxRemaining
292
		}. //WHEN missionClock decouple
293
	}.//WHEN missionClock fins stop
294
}. //WHEN loxRemaining
295
296
//~~~~~Readouts~~~~~
297
298
CLEARSCREEN.
299
PRINT "============COYOTE MEDIUM LAUNCH SYSTEM===========" AT(0,0).
300
301
PRINT "ASL: " AT(0,2).		//Altitude above sea level readout at 6,2
302
PRINT "VEL: " AT(16,2).		//Surface or orbital velocity readout at 22,2
303
PRINT "CLK: " AT(33,2).		//Mission clock readout at 39,2
304
305
PRINT "STG: " AT(0,3).		//Current stage readout at 6,3
306
PRINT "SFL: " AT(16,3).		//Stage fuel level readout at 22,3
307
PRINT "FRG: " AT(33,3).		//Fairing status readout at 39,3
308
309
PRINT "-------------------EVENT LOG----------------------" AT(0,5).
310
311
PRINT "T-" + ROUND(ABS(BEItime - launchTime),2) + " BEI" AT(0,nextLine).		//Time of BEI, will be negative
312
SET nextLine TO nextLine + 1.
313
PRINT "T+0.0 Liftoff" AT(0,nextLine).
314
SET nextLine TO nextLine + 1.
315
316
UNTIL SHIP:APOAPSIS >= (targetAlt * 1000) {
317
	PRINT FLOOR(SHIP:ALTITUDE) + "   " AT(6,2).
318
319
	IF ALTITUDE <=50000 {		//Prints surface velocity below 50km, orbital above
320
		PRINT ROUND(VELOCITY:SURFACE:MAG,1) + "   " AT(22,2).
321
	} ELSE {
322
		PRINT ROUND(VELOCITY:ORBIT:MAG,1) + "   " AT(22,2).
323
	}. //IF-ELSE
324
325
	PRINT missionClock AT(39,2).
326
	PRINT activeStage AT(6,3).
327
	PRINT ROUND((loxRemaining * 100), 1) + "%  " AT(22,3).
328
329
	IF fairingSep = FALSE {			//Prints ATCHD or SPRTD depending on whether the fairings are still on
330
		PRINT "ATCHD" + "   " AT(39,3).
331
	} ELSE {
332
		PRINT "SPRTD" + "   " AT(39,3).
333
	}. //IF-ELSE
334
335
	WAIT (1 / updateRes).		//Update resolution turned into fraction
336
	
337
}. //UNTIL
338
339
CLEARSCREEN.
340
PRINT "Target apoapsis reached. Manual control restored.".
341
WAIT 1.
342
CLEARSCREEN.