Advertisement
KSA_MissionCtrl

TelemLog.ks

Oct 17th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. // from the KSLib
  2. // https://github.com/KSP-KOS/KSLib/blob/master/library/lib_navball.ks
  3. function east_for {
  4. parameter ves.
  5.  
  6. return vcrs(ves:up:vector, ves:north:vector).
  7. }
  8.  
  9. function compass_for {
  10. parameter ves.
  11.  
  12. local pointing is ves:facing:forevector.
  13. local east is east_for(ves).
  14.  
  15. local trig_x is vdot(ves:north:vector, pointing).
  16. local trig_y is vdot(east, pointing).
  17.  
  18. local result is arctan2(trig_y, trig_x).
  19.  
  20. if result < 0 {
  21. return 360 + result.
  22. } else {
  23. return result.
  24. }
  25. }
  26.  
  27. function pitch_for {
  28. parameter ves.
  29.  
  30. return 90 - vang(ves:up:vector, ves:facing:forevector).
  31. }
  32.  
  33. function roll_for {
  34. parameter ves.
  35.  
  36. if vang(ship:facing:vector,ship:up:vector) < 0.2 { //this is the dead zone for roll when the ship is vertical
  37. return 0.
  38. } else {
  39. local raw is vang(vxcl(ship:facing:vector,ship:up:vector), ves:facing:starvector).
  40. if vang(ves:up:vector, ves:facing:topvector) > 90 {
  41. if raw > 90 {
  42. return 270 - raw.
  43. } else {
  44. return -90 - raw.
  45. }
  46. } else {
  47. return raw - 90.
  48. }
  49. }
  50. }.
  51.  
  52. on AG13 {
  53. set running to false.
  54. }.
  55.  
  56. when stage:number < 2 then { set fuelOffset to 180. }
  57.  
  58. set TotalFuel to 1.
  59. set StageFuel to 2.
  60. set dstTraveled to 0.
  61. set fuelOffset to 0.
  62. set running to true.
  63.  
  64. // print out the initial information for us to update as we go along
  65. clearscreen.
  66. print "Compass: " + round(compass_for(ship), 1) + "°".
  67. print "Pitch: " + round(pitch_for(ship), 1) + "°".
  68. print "Roll: " + round(roll_for(ship), 1) + "°".
  69. print "StageFuel: 100%".
  70. print "TotalFuel: 100%".
  71. print "Distance Traveled: 0m".
  72.  
  73. // create the CSV header
  74. log "UT,Heading,Pitch,Roll,DstTraveled,StageFuel,TotalFuel" to TelemetryLog.
  75.  
  76. // loop until program exit is triggered by action group
  77. until not running {
  78.  
  79. // only log the data when staged
  80. if stage:number < 4 {
  81.  
  82. // update information text with new data
  83. print "Compass: " + round(compass_for(ship), 1) + "°" + " " at (0,0).
  84. print "Pitch: " + round(pitch_for(ship), 1) + "°" + " " at (0,1).
  85. print "Roll: " + round(roll_for(ship), 1) + "°" + " " at (0,2).
  86. print "TotalFuel: " + 100*(ship:resources[TotalFuel]:amount/(ship:resources[TotalFuel]:capacity - 180)) + "% " at (0,3).
  87. print "StageFuel: " + 100*(stage:resources[StageFuel]:amount/(stage:resources[StageFuel]:capacity - fuelOffset)) + "% " at (0,4).
  88. print "Distance Traveled: " + dstTraveled + "m " at (0,5).
  89.  
  90. if stage:number < 3 {
  91. // update our distance traveled every second based on our speed (which is in m/s)
  92. set dstTraveled to dstTraveled + ship:velocity:orbit:mag.
  93. }
  94.  
  95. // log all the data
  96. log round(time:seconds) + "," + compass_for(ship) + "," + pitch_for(ship) + "," + roll_for(ship) + "," + dstTraveled + "," +
  97. stage:resources[StageFuel]:amount/(stage:resources[StageFuel]:capacity - fuelOffset) + "," +
  98. ship:resources[TotalFuel]:amount/(ship:resources[TotalFuel]:capacity - 180)
  99. to TelemetryLog.
  100. copy TelemetryLog to 0.
  101. }.
  102.  
  103. // update once per second
  104. wait 1.
  105. }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement