Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Ascent Logger
- //Logs ascent stats to aid in programming a vehicle's optimal ascent profile
- //Engage abort action group to finish logging
- @LAZYGLOBAL OFF.
- PARAMETER log_rate. //How many times per second to log parameters
- CLEARSCREEN.
- //Logs to archive. RT connection required throughout ascent
- SWITCH TO 0.
- //Creates ascent log if it doesn't already exist to keep the following delete command
- //from barfing if it didn't exist
- LOG "" TO ascent_log.csv.
- DELETE ascent_log.csv.
- //The header for our data
- LOG "MET, ALT, PIT, HDG, TWR" TO ascent_log.csv.
- //Used to track when to log parameters
- LOCAL log_timer TO TIME:SECONDS.
- //Used to print out how many lines of data have been logged
- LOCAL log_lines TO 0.
- //Time of launch, used to track MET
- LOCAL launch_time TO -1.
- //Mission Elapsed Time
- LOCAL MET TO -1.
- //Thrust to weight ratio
- LOCAL TWR TO SHIP:MAXTHRUST / (SHIP:MASS * 9.82).
- //Pitch from vertical
- LOCAL vertical_pitch TO VANG(SHIP:FACING:FOREVECTOR, SHIP:UP:FOREVECTOR).
- //Compass heading
- LOCAL ship_heading TO 0.
- //Borrowed from KSLib
- function compass_for {
- parameter ves.
- local pointing is ves:facing:forevector.
- local east is vcrs(ves:up:vector, ves:north:vector).
- local trig_x is vdot(ves:north:vector, pointing).
- local trig_y is vdot(east, pointing).
- local result is arctan2(trig_y, trig_x).
- if result < 0 {
- return 360 + result.
- } else {
- return result.
- }
- }
- WAIT UNTIL SHIP:STATUS <> ("PreLaunch").
- SET launch_time TO TIME:SECONDS.
- ABORT OFF.
- UNTIL ABORT {
- SET MET TO TIME:SECONDS - launch_time.
- SET vertical_pitch TO VANG(SHIP:FACING:FOREVECTOR, SHIP:UP:FOREVECTOR).
- SET ship_heading TO compass_for(SHIP).
- SET TWR TO SHIP:MAXTHRUST / (SHIP:MASS * 9.82).
- IF TIME:SECONDS > log_timer {
- LOG
- MET + ", " +
- SHIP:ALTITUDE + ", " +
- vertical_pitch + ", " +
- ship_heading + ", " +
- TWR
- TO ascent_log.csv.
- SET log_lines TO log_lines + 1.
- SET log_timer TO log_timer + (1 / log_rate).
- }.
- //Readout
- PRINT "LOG: " + log_lines + " " AT(0,0).
- PRINT "MET: " + ROUND(MET, 2) + " " AT(0,2).
- PRINT "ALT: " + ROUND(SHIP:ALTITUDE) + " " AT(0,3).
- PRINT "PIT: " + ROUND(vertical_pitch, 2) + " " AT(0,4).
- PRINT "HDG: " + ROUND(ship_heading, 2) + " " AT(0,5).
- PRINT "TWR: " + ROUND(TWR, 2) + " " AT(0,6).
- //Prevents loop from cycling faster than game physics does
- WAIT UNTIL TRUE.
- }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement