Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. list engines in englist.
  2. set g0 to 9.80665.
  3.  
  4. function getthrust{
  5. parameter englist.
  6. set sumthrust to 0.
  7. for eng in englist
  8. set sumthrust to sumthrust + eng:thrust.
  9.  
  10. return sumthrust.
  11. }
  12.  
  13. //not tested with multiple engines.
  14. function getweightedisp{
  15. parameter englist.
  16. local liquid_density is .005. //tonne/unit
  17. local solid_density is .0075.
  18. local mono_density is .004.
  19.  
  20. set summf to 0.
  21. set ispmf to 0.
  22.  
  23. for eng in englist{
  24. set massflow to 0.
  25. if eng:allowshutdown{
  26. if eng:name = "omsengine"
  27. set massflow to eng:fuelflow*mono_density.
  28. else if eng:name = "ionengine"
  29. . //ignoring ion engines right now. electricity is part of flow
  30. else set massflow to eng:fuelflow*liquid_density.
  31. }
  32. else{//srb
  33. set massflow to eng:fuelflow*solid_density.
  34. }
  35. set ispmf to ispmf + eng:isp * massflow.
  36. set summf to summf + massflow.
  37. }
  38. if summf
  39. return ispmf/summf.
  40. else
  41. return 0.
  42. }
  43.  
  44. function getdensity{
  45. parameter alti.
  46. return 1.
  47. }
  48.  
  49. function shipvec{
  50. parameter vector, veccolor, text, vscale is .5, data is vector:mag, precision is 2.
  51.  
  52. VECDRAWARGS(ship:POSITION, vector*vscale, veccolor, text+round(vector:mag,precision), 1, TRUE).
  53. }
  54.  
  55. function forcetest{
  56. parameter freq.
  57. //get initial data
  58. set t1 to time:seconds.
  59. set m1 to ship:mass.
  60. set v1 to ship:velocity:orbit.
  61. set thrust1 to ship:facing:forevector * getthrust(englist).
  62.  
  63. wait freq.
  64.  
  65. set t2 to time:seconds.
  66. set m2 to ship:mass.
  67. set v2 to ship:velocity:orbit.
  68. set thrust2 to ship:facing:forevector * getthrust(englist).
  69.  
  70. //perform all calculations
  71. set wisp to getweightedisp(englist).
  72. set ev to -ship:facing:forevector * (wisp*g0).
  73. set accel to (v2-v1)/(t2-t1).
  74. set massflow to (m2-m1)/(t2-t1).
  75. set totalforce to m1*accel + ev*massflow - thrust2.
  76. set gravity to ship:BODY:POSITION:normalized *(body:mu/(altitude+body:radius)^2).
  77. set weight to m2*gravity.
  78. set drag to totalforce - thrust2 - weight.//set drag to the total force that is not weight or thrust. (assuming non changing thrust, inc gimbal...)
  79. set cdA to 0.
  80. if altitude < body:atm:height
  81. set CdA to (2*drag:mag)/(getdensity(altitude)*v2:mag^2).
  82.  
  83. //print and draw stuff
  84. clearvecdraws().
  85. clearscreen.
  86. print "Isp: " + round(wisp,2).
  87. print "Drag: "+round(drag:mag,2).
  88. print " CdA: "+round(CdA,5).
  89. print "dynp: "+round(ship:dynamicpressure,3).
  90. shipvec(v2,red,"v2: ",.02).
  91. shipvec(accel,yellow, "Accel: ",3).
  92. shipvec(totalforce, green, "#Force: ").
  93. shipvec(weight, red, "Weight: ").
  94. shipvec(drag,yellow,"Drag: ").
  95. if abs(thrust2:mag) > .1
  96. shipvec(thrust2, blue, "Thrust: ").
  97. if abs(ev:mag) > .1
  98. shipvec(ev,white,"ExhVel: ",.01).
  99. }
  100.  
  101. function main{
  102. until false
  103. forcetest(.25).
  104. }
  105. main().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement