Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // from the KSLib
- // https://github.com/KSP-KOS/KSLib/blob/master/library/lib_navball.ks
- function east_for {
- parameter ves.
- return vcrs(ves:up:vector, ves:north:vector).
- }
- function compass_for {
- parameter ves.
- local pointing is ves:facing:forevector.
- local east is east_for(ves).
- 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.
- }
- }
- function pitch_for {
- parameter ves.
- return 90 - vang(ves:up:vector, ves:facing:forevector).
- }
- function roll_for {
- parameter ves.
- if vang(ship:facing:vector,ship:up:vector) < 0.2 { //this is the dead zone for roll when the ship is vertical
- return 0.
- } else {
- local raw is vang(vxcl(ship:facing:vector,ship:up:vector), ves:facing:starvector).
- if vang(ves:up:vector, ves:facing:topvector) > 90 {
- if raw > 90 {
- return 270 - raw.
- } else {
- return -90 - raw.
- }
- } else {
- return raw - 90.
- }
- }
- }.
- on AG13 {
- set running to false.
- }.
- when stage:number < 2 then { set fuelOffset to 180. }
- set TotalFuel to 1.
- set StageFuel to 2.
- set dstTraveled to 0.
- set fuelOffset to 0.
- set running to true.
- // print out the initial information for us to update as we go along
- clearscreen.
- print "Compass: " + round(compass_for(ship), 1) + "°".
- print "Pitch: " + round(pitch_for(ship), 1) + "°".
- print "Roll: " + round(roll_for(ship), 1) + "°".
- print "StageFuel: 100%".
- print "TotalFuel: 100%".
- print "Distance Traveled: 0m".
- // create the CSV header
- log "UT,Heading,Pitch,Roll,DstTraveled,StageFuel,TotalFuel" to TelemetryLog.
- // loop until program exit is triggered by action group
- until not running {
- // only log the data when staged
- if stage:number < 4 {
- // update information text with new data
- print "Compass: " + round(compass_for(ship), 1) + "°" + " " at (0,0).
- print "Pitch: " + round(pitch_for(ship), 1) + "°" + " " at (0,1).
- print "Roll: " + round(roll_for(ship), 1) + "°" + " " at (0,2).
- print "TotalFuel: " + 100*(ship:resources[TotalFuel]:amount/(ship:resources[TotalFuel]:capacity - 180)) + "% " at (0,3).
- print "StageFuel: " + 100*(stage:resources[StageFuel]:amount/(stage:resources[StageFuel]:capacity - fuelOffset)) + "% " at (0,4).
- print "Distance Traveled: " + dstTraveled + "m " at (0,5).
- if stage:number < 3 {
- // update our distance traveled every second based on our speed (which is in m/s)
- set dstTraveled to dstTraveled + ship:velocity:orbit:mag.
- }
- // log all the data
- log round(time:seconds) + "," + compass_for(ship) + "," + pitch_for(ship) + "," + roll_for(ship) + "," + dstTraveled + "," +
- stage:resources[StageFuel]:amount/(stage:resources[StageFuel]:capacity - fuelOffset) + "," +
- ship:resources[TotalFuel]:amount/(ship:resources[TotalFuel]:capacity - 180)
- to TelemetryLog.
- copy TelemetryLog to 0.
- }.
- // update once per second
- wait 1.
- }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement