Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.86 KB | None | 0 0
  1.  
  2. //////////
  3. //////////
  4. ////////// THE ONLY THINGS THAT NEED TO BE CHANGED
  5.  
  6. set isp to 287. //VACUUM Specific Impulse of the engine.
  7. set minthrot to 0.29. //set to the minimum thrust of your engine(s). For stock, this is just 0.
  8. set shipheight to 2.8. //height of ship so engines know when to cut off.
  9. set throttleupbuffer to 0. //set this to 1 if your engines take time to throttle up. it just adds an extra kilometer of bufferzone. set to 0 if not.
  10. set la to 57.66. //latitude of desired coordinates
  11. set lo to 9.13. //longitude of desired coordinates
  12.  
  13. ////////// THE ONLY THINGS THAT NEED TO BE CHANGED
  14. //////////
  15. //////////
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. set angleb to 0.
  23.  
  24. until round(angleb) = 91{
  25. set coorpos to latlng(la,lo):position.
  26. SET anArrow TO VECDRAW(
  27. V(0,0,0),
  28. //ship:body:position,
  29. coorpos,
  30. RGB(1,0,0),
  31. "This is where you should be landing",
  32. 1.0,
  33. TRUE,
  34. 0.2
  35. ).
  36. set uv to v(0,1,0).
  37. set ev to vcrs(ship:body:position,uv).
  38. set nv to vcrs(ev,ship:body:position).
  39. set vec1 to vcrs(ship:body:position,ship:velocity:surface).
  40. set dot1 to vdot(nv,vec1).
  41. set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
  42. set dot2 to vdot(ev,vec1).
  43. set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
  44. if angleeast>0 and anglenorth<0 {
  45. set anglenorth to 360+anglenorth.
  46. }. else if angleeast<0 and anglenorth<0 {
  47. set anglenorth to 180-anglenorth.
  48. }. else if angleeast<0 and anglenorth>0 {
  49. set anglenorth to 180-anglenorth.
  50. }.
  51.  
  52. set srfprohdg to anglenorth.
  53.  
  54. set uv to v(0,1,0).
  55. set ev to vcrs(ship:body:position,uv).
  56. set nv to vcrs(ev,ship:body:position).
  57. set vec1 to vcrs(ship:body:position,latlng(la,lo):position).
  58. set dot1 to vdot(nv,vec1).
  59. set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
  60. set dot2 to vdot(ev,vec1).
  61. set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
  62. if angleeast>0 and anglenorth<0 {
  63. set anglenorth to 360+anglenorth.
  64. }. else if angleeast<0 and anglenorth<0 {
  65. set anglenorth to 180-anglenorth.
  66. }. else if angleeast<0 and anglenorth>0 {
  67. set anglenorth to 180-anglenorth.
  68. }.
  69.  
  70. set tgthead to anglenorth.
  71.  
  72. set neg to 0.
  73.  
  74. if tgthead<srfprohdg {
  75. set neg to -1.
  76. }. else if tgthead>srfprohdg {
  77. set neg to 1.
  78. }.
  79. set targpos to -1*ship:body:position+latlng(la,lo):position.
  80. set angleb to vang(targpos,-ship:body:position).
  81. set normal to neg*vcrs(ship:velocity:surface,ship:body:position).
  82. lock steering to normal.
  83. clearscreen.
  84. print "The current angle is: "+round(angleb)+" Degrees".
  85. wait 0.1.
  86. }.
  87.  
  88.  
  89. set ship:control:fore to 1.
  90. print " ".
  91. print "Firing RCS for Ullage".
  92. wait 2.
  93. lock throttle to 1.
  94. set ship:control:neutralize to true.
  95.  
  96.  
  97.  
  98. until 5=4 {
  99. set normal to neg*vcrs(ship:velocity:surface,ship:body:position).
  100. lock steering to normal.
  101. set targpos to -ship:body:position+latlng(la,lo):position.
  102. set angleb to vang(targpos,-ship:body:position).
  103. set futureshippos to (-1*ship:body:position)+positionat(ship,time:seconds+(ship:orbit:period*(angleb/360))).
  104. set futuretargpos to targpos+(latlng(la,lo):velocity:orbit*ship:orbit:period*(angleb/360)).
  105. set futureangle to vang(futuretargpos,futureshippos).
  106. clearscreen.
  107. print " ".
  108. print "Predicted angle: "+futureangle.
  109. print "Current angle: "+angleb.
  110. wait 0.1.
  111. set targpos to -ship:body:position+latlng(la,lo):position.
  112. set angleb to vang(targpos,-ship:body:position).
  113. set futureshippos to (-1*ship:body:position)+positionat(ship,time:seconds+(ship:orbit:period*(angleb/360))).
  114. set secondangle to vang(futuretargpos,futureshippos).
  115. if secondangle>futureangle {
  116. break.
  117. }.
  118. }.
  119. lock throttle to 0.
  120. clearvecdraws().
  121. clearscreen.
  122. lock steering to -ship:velocity:surface.
  123. set m0 to ship:mass*1000. //ships mass in kg
  124. set localacc to body:mass*constant:g/ship:body:position:mag^2. //surface level acceleration on whatever body. The change in acceleration over altitude should be negligible
  125. set T to ship:maxthrust*1000. //Thrust of the engine
  126. set W to (m0*localacc). //Weight of the spacecraft pre-burn on whatever body
  127. set g to 9.81. //1 earth/kerbin g
  128. set e to 2.7182818284590452353602874713527. //I know i probably don't have to set e, but whatever
  129. set pi to 3.141592654.
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. set massflow to (T/(isp*g)). //massflow of engine in terms of thrust and isp
  138. set veq to isp*g.
  139.  
  140.  
  141.  
  142. set a0 to ship:maxthrust/ship:mass.
  143. set s to ship:velocity:surface:mag^2/(2*a0).
  144.  
  145.  
  146. until 5=4 {
  147. set a0 to ship:maxthrust/ship:mass.
  148. set s to ship:velocity:surface:mag^2/(2*a0).
  149. set coorpos to latlng(la,lo):position.
  150. SET anArrow TO VECDRAW(
  151. V(0,0,0),
  152. //ship:body:position,
  153. coorpos,
  154. RGB(1,0,0),
  155. "This is where you should be landing",
  156. 1.0,
  157. TRUE,
  158. 0.2
  159. ).
  160. clearscreen.
  161. set targpos to -ship:body:position+latlng(la,lo):position.
  162. set angleb to vang(targpos,-ship:body:position).
  163. set radians to (pi/180)*angleb.
  164. set distance to ship:body:position:mag*radians.
  165. print " ".
  166. print "The burn distance is: " + round(s) + " meters".
  167. print "The current distance is: " + round(distance) + " meters".
  168. if distance-s < ship:velocity:surface:mag*0.25 {
  169. set ship:control:fore to 1.
  170. print " ".
  171. print "Firing RCS for Ullage".
  172. }.
  173. wait 0.1.
  174. if abs(distance-s) < ship:velocity:surface:mag*0.15 {
  175. break.
  176. }.
  177.  
  178. }.
  179. clearvecdraws().
  180. sas off.
  181. rcs on.
  182. lock steering to -ship:velocity:surface.
  183. lock throttle to 1.
  184. set ship:control:neutralize to true.
  185. set T to ship:maxthrust.
  186. set a0 to ship:maxthrust/ship:mass.
  187. set throt to 1.
  188.  
  189. until ship:velocity:surface:mag < 15 {
  190. set currentthrust to ((T-(minthrot*T))*throt)+(minthrot*T).
  191. set a1 to ship:velocity:orbit:mag^2/ship:body:position:mag.
  192. set a2 to body:mass*constant:g/ship:body:position:mag^2.
  193. set adiff to a2-a1.
  194. set aup to arcsin(adiff/(currentthrust/ship:mass)).
  195. if ship:verticalspeed > 0.1 {
  196. set aup to aup-0.1.
  197. }. else if ship:verticalspeed < 0.1 {
  198. set aup to aup+0.1.
  199. }. else {
  200. set aup to aup.
  201. }.
  202. set uv to v(0,1,0).
  203. set ev to vcrs(ship:body:position,uv).
  204. set nv to vcrs(ev,ship:body:position).
  205. set vec1 to vcrs(ship:body:position,ship:velocity:surface).
  206. set dot1 to vdot(nv,vec1).
  207. set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
  208. set dot2 to vdot(ev,vec1).
  209. set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
  210. if angleeast>0 and anglenorth<0 {
  211. set anglenorth to 360+anglenorth.
  212. }. else if angleeast<0 and anglenorth<0 {
  213. set anglenorth to 180-anglenorth.
  214. }. else if angleeast<0 and anglenorth>0 {
  215. set anglenorth to 180-anglenorth.
  216. }.
  217.  
  218. set srfretrohdg to anglenorth-180.
  219.  
  220. lock steering to heading(srfretrohdg,aup).
  221. set laterala to currentthrust*cos(aup)/ship:mass.
  222. clearscreen.
  223. print " ".
  224. print "Lateral Deceleration: "+laterala+" m/s^2".
  225. print "Desired Deceleration: "+a0+" m/s^2".
  226. print "Up angle: "+aup+" degrees".
  227.  
  228. set tdesired to a0*ship:mass/cos(aup).
  229. set throt to (tdesired-(minthrot*T))/(T*(1-minthrot)).
  230. lock throttle to throt.
  231.  
  232.  
  233. wait 0.1.
  234.  
  235. }.
  236.  
  237. lock steering to -ship:velocity:surface.
  238. wait until ship:groundspeed<0.2.
  239.  
  240.  
  241. lock throttle to 0.
  242. clearscreen.
  243. set ship:control:pilotmainthrottle to 0.
  244. sas off.
  245. print " ".
  246. print "Preparing for Suicide Burn".
  247. print "May God have mercy on your soul".
  248. lock steering to heading(0,90).
  249. set m0 to ship:mass*1000. //ships mass in kg
  250. set localacc to body:mass*constant:g/(body:radius^2). //surface level acceleration on whatever body. The change in acceleration over altitude should be negligible
  251. set T to ship:maxthrust*1000*0.95. //Thrust of the engine
  252. set W to (m0*localacc). //Weight of the spacecraft pre-burn on whatever body
  253.  
  254.  
  255. set g to 9.81. //1 earth/kerbin g
  256. set e to 2.7182818284590452353602874713527. //I know i probably don't have to set e, but whatever
  257. set throttleupbuffer to 1000*throttleupbuffer.
  258.  
  259. set r to body:radius+ship:altitude.
  260. set gm to body:mass*constant:G.
  261.  
  262.  
  263.  
  264. set massflow to (T/(isp*g)). //massflow of engine in terms of thrust and isp
  265. set twmc to ((T-W)/massflow). //a constant I found in calculations. I did this to avoid writing it over and over again
  266. set t2 to 2.
  267. set t1 to 1.
  268.  
  269.  
  270.  
  271.  
  272. set burnalt to 0.
  273. //set decel to (T/m0)-localacc.
  274.  
  275. set altdiff to 0.
  276. set difference to 1.
  277. set radaralt to ship:altitude.
  278. wait 5.
  279. until difference < altdiff {
  280. wait 0.1.
  281.  
  282. set r to body:radius+ship:altitude.
  283. set gm to body:mass*constant:G.
  284. set localacc to (gm/((body:radius+ship:altitude)-(body:radius+ship:geoposition:terrainheight)))*((1/(body:radius+ship:geoposition:terrainheight))-(1/(body:radius+ship:altitude))).
  285. set m0 to ship:mass*1000.
  286. set W to m0*localacc.
  287. set T to ship:maxthrust.
  288. set twmc to ((T-W)/massflow).
  289.  
  290. set radaralt to ship:altitude-ship:geoposition:terrainheight.
  291. set tb to ((m0 - e^((ln(m0))-((massflow*ship:verticalspeed*-1)/(T-W))))/massflow).
  292. set mf to (m0-(massflow*tb)).
  293. set burnalt to twmc*((tb*ln(m0))-(((mf*ln(mf))-mf-(m0*ln(m0))+m0)/-massflow)).
  294. set difference to (-burnalt+radaralt).
  295.  
  296. clearscreen.
  297. print " ".
  298. print "Burn Altitude: "+round(burnalt)+" meters".
  299. print "Radar Altitude: "+round(radaralt)+" meters".
  300. print "Difference: "+round(difference)+" meters".
  301. if difference < ship:verticalspeed*10*-1 {
  302. set ship:control:fore to 1.
  303. print " ".
  304. print "Firing RCS for Ullage".
  305. }.
  306.  
  307. set altdiff to (ship:verticalspeed*-1)*0.15+throttleupbuffer.
  308.  
  309. }.
  310.  
  311. set ship:control:neutralize to true.
  312. lock throttle to 0.95.
  313.  
  314.  
  315. set W to m0*localacc.
  316. set twmc to ((T-W)/massflow).
  317.  
  318.  
  319.  
  320. set throt to 0.95.
  321. set zer to 0.
  322.  
  323. until ship:verticalspeed>-2 {
  324.  
  325. wait 0.1.
  326.  
  327.  
  328. set radaralt to ship:altitude-ship:geoposition:terrainheight.
  329.  
  330. set uv to v(0,1,0).
  331. set ev to vcrs(ship:body:position,uv).
  332. set nv to vcrs(ev,ship:body:position).
  333. set vec1 to vcrs(ship:body:position,ship:velocity:surface).
  334. set dot1 to vdot(nv,vec1).
  335. set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
  336. set dot2 to vdot(ev,vec1).
  337. set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
  338. if angleeast>0 and anglenorth<0 {
  339. set anglenorth to 360+anglenorth.
  340. }. else if angleeast<0 and anglenorth<0 {
  341. set anglenorth to 180-anglenorth.
  342. }. else if angleeast<0 and anglenorth>0 {
  343. set anglenorth to 180-anglenorth.
  344. }.
  345.  
  346. set srfretrohdg to anglenorth-180.
  347.  
  348. set aup to 90.
  349. if ship:groundspeed>0.5 {
  350. set aup to 87.
  351. }. else {
  352. set srfretrohdg to 0.
  353. }.
  354.  
  355. lock steering to heading(srfretrohdg,aup).
  356.  
  357. set localacc to (gm/((body:radius+ship:altitude)-(body:radius+ship:geoposition:terrainheight)))*((1/(body:radius+ship:geoposition:terrainheight))-(1/(body:radius+ship:altitude))).
  358. set m0 to ship:mass*1000.
  359. set W to m0*localacc.
  360. set T to ship:maxthrust.
  361. set twmc to ((T-W)/massflow).
  362.  
  363. set radaralt to ship:altitude-ship:geoposition:terrainheight.
  364. set tb to ((m0 - e^((ln(m0))-((massflow*ship:verticalspeed*-1)/(T-W))))/massflow).
  365. set mf to (m0-(massflow*tb)).
  366. set updatedburnalt to twmc*((tb*ln(m0))-(((mf*ln(mf))-mf-(m0*ln(m0))+m0)/-massflow)).
  367. set difference to (-burnalt+radaralt).
  368. set newdif to (radaralt-updatedburnalt).
  369.  
  370. clearscreen.
  371. print " ".
  372. print "Burnalt: "+round(updatedburnalt)+" meters".
  373. print "Radar Altitude: "+round(radaralt)+" meters".
  374. print "Updated Diff: "+round(newdif)+" meters".
  375.  
  376.  
  377.  
  378.  
  379. if newdif>(shipheight+2) and newdif < 100 {
  380. set throt to 0.90.
  381. print " ".
  382. print "Throttle at "+round(throt*100)+"%".
  383. }. else if newdif >100 {
  384. set throt to .85.
  385. print " ".
  386. print "Throttle at "+round(throt*100)+"%".
  387. }. else if newdif < (shipheight+1) {
  388. set throt to 1.
  389. print " ".
  390. print "Throttle at "+round(throt*100)+"%".
  391. }. else {
  392. set throt to 0.95.
  393. print " ".
  394. print "Throttle at "+round(throt*100)+"%".
  395. }.
  396.  
  397. lock throttle to throt.
  398.  
  399. when radaralt-zer < 100 then {
  400. toggle gear.
  401. set zer to -100000.
  402. }.
  403.  
  404.  
  405. }.
  406.  
  407. //toggle gear.
  408.  
  409. if ship:maxthrust*minthrot > ship:mass*localacc {
  410. toggle ag1.
  411. }.
  412.  
  413.  
  414. until ship:verticalspeed > - 1 {
  415. lock throttle to throt+0.1.
  416. wait 0.1.
  417. }.
  418.  
  419. until alt:radar < shipheight+0.2 {
  420. set r to body:radius+ship:altitude.
  421. set gm to body:mass*constant:G.
  422. set localacc to gm/r^2.
  423. set w to localacc*ship:mass.
  424. set T to ship:maxthrust.
  425. set throt to (w-(minthrot*T))/(T*(1-minthrot)).
  426. if ship:verticalspeed < -0.75 {
  427. set throt to throt+0.05.
  428. }. else if ship:verticalspeed > -0.5 {
  429. set throt to throt-0.05.
  430. }. else {
  431. set throt to throt.
  432. }.
  433. lock throttle to throt.
  434. wait 0.1.
  435. }.
  436. lock throttle to 0.
  437. rcs off.
  438. unlock steering.
  439. set ship:control:pilotmainthrottle to 0.
  440.  
  441.  
  442. set coorpos to latlng(la,lo):position.
  443. clearscreen.
  444. print " ".
  445. print "You landed "+round(coorpos:mag)+" meters".
  446. print "from the intended landinge site".
  447.  
  448. wait until alt:radar<shipheight+0.1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement