Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. list engines in englist.
  2. local liquid_density is .005. //tonne/unit
  3. local solid_density is .0075.
  4. local mono_density is .004.
  5. set g0 to 9.80665.
  6.  
  7. function getthrust{
  8. parameter englist.
  9. set sumthrust to 0.
  10. for eng in englist
  11. set sumthrust to sumthrust + eng:thrust.
  12.  
  13. return sumthrust.
  14. }
  15.  
  16. //not tested with multiple engines.
  17. function getweightedisp{
  18. parameter englist.
  19. set summf to 0.
  20. set ispmf to 0.
  21.  
  22. for eng in englist{
  23. set massflow to 0.
  24. if eng:allowshutdown{
  25. if eng:name = "omsengine"
  26. set massflow to eng:fuelflow*mono_density.
  27. else if eng:name = "ionengine"
  28. . //ignoring ion engines right now. electricity is part of flow
  29. else set massflow to eng:fuelflow*liquid_density.
  30. }
  31. else{//srb
  32. set massflow to eng:fuelflow*solid_density.
  33. }
  34. set ispmf to ispmf + eng:isp * massflow.
  35. set summf to summf + massflow.
  36. }
  37. if summf
  38. return ispmf/summf.
  39. else
  40. return 0.
  41. }
  42.  
  43. function getdensity{
  44. parameter alti.
  45. return 1.
  46. }
  47.  
  48. function shipvec{
  49. parameter vector, veccolor, text, vscale is .5, data is vector:mag, precision is 2.
  50.  
  51. VECDRAWARGS(ship:POSITION, vector*vscale, veccolor, text+round(vector:mag,precision), 1, TRUE).
  52. }
  53.  
  54.  
  55.  
  56. clearvecdraws().
  57. set throttle to .1.
  58. wait .1.
  59. set t1 to time:seconds.
  60. set m1 to ship:mass.
  61. set v1 to ship:velocity:orbit.
  62. set thrust1 to ship:facing:forevector * getthrust(englist).
  63. //shipvec(thrust1,blue,"Ti: ",.4). //checked to see if thrust1 = thrust2,yes
  64.  
  65. wait 1.
  66.  
  67. set t2 to time:seconds.
  68. set m2 to ship:mass.
  69. set v2 to ship:velocity:orbit.
  70. set thrust2 to ship:facing:forevector * getthrust(englist).
  71. set throttle to 0.
  72.  
  73. //the part that actually does the calculation:
  74. set wisp to getweightedisp(englist).
  75. set ev to -ship:facing:forevector * (wisp*g0).
  76. set accel to (v2-v1)/(t2-t1).
  77. set massflow to (m2-m1)/(t2-t1).
  78. set totalforce to m1*accel + ev*massflow.
  79. set gravity to ship:BODY:POSITION:normalized *(body:mu/(altitude+body:radius)^2).
  80. set weight to m2*gravity.
  81.  
  82. print "Weighted isp: " + wisp.
  83. shipvec(ev,white,"ExhVel: ",.01).
  84. shipvec(v2,red,"v2: ",.02).
  85. shipvec(accel,yellow, "Accel: ",3).
  86. shipvec(totalforce, green, "#Force: ").
  87. shipvec(thrust2, blue, "Thrust: ").
  88. shipvec(weight, red, "Weight: ").
  89. shipvec(thrust2+weight,white,"expectedF: ").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement