Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////
- //////////
- ////////// THE ONLY THINGS THAT NEED TO BE CHANGED
- set isp to 287. //VACUUM Specific Impulse of the engine.
- set minthrot to 0.29. //set to the minimum thrust of your engine(s). For stock, this is just 0.
- set shipheight to 2.8. //height of ship so engines know when to cut off.
- 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.
- set la to 57.66. //latitude of desired coordinates
- set lo to 9.13. //longitude of desired coordinates
- ////////// THE ONLY THINGS THAT NEED TO BE CHANGED
- //////////
- //////////
- set angleb to 0.
- until round(angleb) = 91{
- set coorpos to latlng(la,lo):position.
- SET anArrow TO VECDRAW(
- V(0,0,0),
- //ship:body:position,
- coorpos,
- RGB(1,0,0),
- "This is where you should be landing",
- 1.0,
- TRUE,
- 0.2
- ).
- set uv to v(0,1,0).
- set ev to vcrs(ship:body:position,uv).
- set nv to vcrs(ev,ship:body:position).
- set vec1 to vcrs(ship:body:position,ship:velocity:surface).
- set dot1 to vdot(nv,vec1).
- set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
- set dot2 to vdot(ev,vec1).
- set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
- if angleeast>0 and anglenorth<0 {
- set anglenorth to 360+anglenorth.
- }. else if angleeast<0 and anglenorth<0 {
- set anglenorth to 180-anglenorth.
- }. else if angleeast<0 and anglenorth>0 {
- set anglenorth to 180-anglenorth.
- }.
- set srfprohdg to anglenorth.
- set uv to v(0,1,0).
- set ev to vcrs(ship:body:position,uv).
- set nv to vcrs(ev,ship:body:position).
- set vec1 to vcrs(ship:body:position,latlng(la,lo):position).
- set dot1 to vdot(nv,vec1).
- set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
- set dot2 to vdot(ev,vec1).
- set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
- if angleeast>0 and anglenorth<0 {
- set anglenorth to 360+anglenorth.
- }. else if angleeast<0 and anglenorth<0 {
- set anglenorth to 180-anglenorth.
- }. else if angleeast<0 and anglenorth>0 {
- set anglenorth to 180-anglenorth.
- }.
- set tgthead to anglenorth.
- set neg to 0.
- if tgthead<srfprohdg {
- set neg to -1.
- }. else if tgthead>srfprohdg {
- set neg to 1.
- }.
- set targpos to -1*ship:body:position+latlng(la,lo):position.
- set angleb to vang(targpos,-ship:body:position).
- set normal to neg*vcrs(ship:velocity:surface,ship:body:position).
- lock steering to normal.
- clearscreen.
- print "The current angle is: "+round(angleb)+" Degrees".
- wait 0.1.
- }.
- set ship:control:fore to 1.
- print " ".
- print "Firing RCS for Ullage".
- wait 2.
- lock throttle to 1.
- set ship:control:neutralize to true.
- until 5=4 {
- set normal to neg*vcrs(ship:velocity:surface,ship:body:position).
- lock steering to normal.
- set targpos to -ship:body:position+latlng(la,lo):position.
- set angleb to vang(targpos,-ship:body:position).
- set futureshippos to (-1*ship:body:position)+positionat(ship,time:seconds+(ship:orbit:period*(angleb/360))).
- set futuretargpos to targpos+(latlng(la,lo):velocity:orbit*ship:orbit:period*(angleb/360)).
- set futureangle to vang(futuretargpos,futureshippos).
- clearscreen.
- print " ".
- print "Predicted angle: "+futureangle.
- print "Current angle: "+angleb.
- wait 0.1.
- set targpos to -ship:body:position+latlng(la,lo):position.
- set angleb to vang(targpos,-ship:body:position).
- set futureshippos to (-1*ship:body:position)+positionat(ship,time:seconds+(ship:orbit:period*(angleb/360))).
- set secondangle to vang(futuretargpos,futureshippos).
- if secondangle>futureangle {
- break.
- }.
- }.
- lock throttle to 0.
- clearvecdraws().
- clearscreen.
- lock steering to -ship:velocity:surface.
- set m0 to ship:mass*1000. //ships mass in kg
- 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
- set T to ship:maxthrust*1000. //Thrust of the engine
- set W to (m0*localacc). //Weight of the spacecraft pre-burn on whatever body
- set g to 9.81. //1 earth/kerbin g
- set e to 2.7182818284590452353602874713527. //I know i probably don't have to set e, but whatever
- set pi to 3.141592654.
- set massflow to (T/(isp*g)). //massflow of engine in terms of thrust and isp
- set veq to isp*g.
- set a0 to ship:maxthrust/ship:mass.
- set s to ship:velocity:surface:mag^2/(2*a0).
- until 5=4 {
- set a0 to ship:maxthrust/ship:mass.
- set s to ship:velocity:surface:mag^2/(2*a0).
- set coorpos to latlng(la,lo):position.
- SET anArrow TO VECDRAW(
- V(0,0,0),
- //ship:body:position,
- coorpos,
- RGB(1,0,0),
- "This is where you should be landing",
- 1.0,
- TRUE,
- 0.2
- ).
- clearscreen.
- set targpos to -ship:body:position+latlng(la,lo):position.
- set angleb to vang(targpos,-ship:body:position).
- set radians to (pi/180)*angleb.
- set distance to ship:body:position:mag*radians.
- print " ".
- print "The burn distance is: " + round(s) + " meters".
- print "The current distance is: " + round(distance) + " meters".
- if distance-s < ship:velocity:surface:mag*0.25 {
- set ship:control:fore to 1.
- print " ".
- print "Firing RCS for Ullage".
- }.
- wait 0.1.
- if abs(distance-s) < ship:velocity:surface:mag*0.15 {
- break.
- }.
- }.
- clearvecdraws().
- sas off.
- rcs on.
- lock steering to -ship:velocity:surface.
- lock throttle to 1.
- set ship:control:neutralize to true.
- set T to ship:maxthrust.
- set a0 to ship:maxthrust/ship:mass.
- set throt to 1.
- until ship:velocity:surface:mag < 15 {
- set currentthrust to ((T-(minthrot*T))*throt)+(minthrot*T).
- set a1 to ship:velocity:orbit:mag^2/ship:body:position:mag.
- set a2 to body:mass*constant:g/ship:body:position:mag^2.
- set adiff to a2-a1.
- set aup to arcsin(adiff/(currentthrust/ship:mass)).
- if ship:verticalspeed > 0.1 {
- set aup to aup-0.1.
- }. else if ship:verticalspeed < 0.1 {
- set aup to aup+0.1.
- }. else {
- set aup to aup.
- }.
- set uv to v(0,1,0).
- set ev to vcrs(ship:body:position,uv).
- set nv to vcrs(ev,ship:body:position).
- set vec1 to vcrs(ship:body:position,ship:velocity:surface).
- set dot1 to vdot(nv,vec1).
- set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
- set dot2 to vdot(ev,vec1).
- set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
- if angleeast>0 and anglenorth<0 {
- set anglenorth to 360+anglenorth.
- }. else if angleeast<0 and anglenorth<0 {
- set anglenorth to 180-anglenorth.
- }. else if angleeast<0 and anglenorth>0 {
- set anglenorth to 180-anglenorth.
- }.
- set srfretrohdg to anglenorth-180.
- lock steering to heading(srfretrohdg,aup).
- set laterala to currentthrust*cos(aup)/ship:mass.
- clearscreen.
- print " ".
- print "Lateral Deceleration: "+laterala+" m/s^2".
- print "Desired Deceleration: "+a0+" m/s^2".
- print "Up angle: "+aup+" degrees".
- set tdesired to a0*ship:mass/cos(aup).
- set throt to (tdesired-(minthrot*T))/(T*(1-minthrot)).
- lock throttle to throt.
- wait 0.1.
- }.
- lock steering to -ship:velocity:surface.
- wait until ship:groundspeed<0.2.
- lock throttle to 0.
- clearscreen.
- set ship:control:pilotmainthrottle to 0.
- sas off.
- print " ".
- print "Preparing for Suicide Burn".
- print "May God have mercy on your soul".
- lock steering to heading(0,90).
- set m0 to ship:mass*1000. //ships mass in kg
- 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
- set T to ship:maxthrust*1000*0.95. //Thrust of the engine
- set W to (m0*localacc). //Weight of the spacecraft pre-burn on whatever body
- set g to 9.81. //1 earth/kerbin g
- set e to 2.7182818284590452353602874713527. //I know i probably don't have to set e, but whatever
- set throttleupbuffer to 1000*throttleupbuffer.
- set r to body:radius+ship:altitude.
- set gm to body:mass*constant:G.
- set massflow to (T/(isp*g)). //massflow of engine in terms of thrust and isp
- set twmc to ((T-W)/massflow). //a constant I found in calculations. I did this to avoid writing it over and over again
- set t2 to 2.
- set t1 to 1.
- set burnalt to 0.
- //set decel to (T/m0)-localacc.
- set altdiff to 0.
- set difference to 1.
- set radaralt to ship:altitude.
- wait 5.
- until difference < altdiff {
- wait 0.1.
- set r to body:radius+ship:altitude.
- set gm to body:mass*constant:G.
- set localacc to (gm/((body:radius+ship:altitude)-(body:radius+ship:geoposition:terrainheight)))*((1/(body:radius+ship:geoposition:terrainheight))-(1/(body:radius+ship:altitude))).
- set m0 to ship:mass*1000.
- set W to m0*localacc.
- set T to ship:maxthrust.
- set twmc to ((T-W)/massflow).
- set radaralt to ship:altitude-ship:geoposition:terrainheight.
- set tb to ((m0 - e^((ln(m0))-((massflow*ship:verticalspeed*-1)/(T-W))))/massflow).
- set mf to (m0-(massflow*tb)).
- set burnalt to twmc*((tb*ln(m0))-(((mf*ln(mf))-mf-(m0*ln(m0))+m0)/-massflow)).
- set difference to (-burnalt+radaralt).
- clearscreen.
- print " ".
- print "Burn Altitude: "+round(burnalt)+" meters".
- print "Radar Altitude: "+round(radaralt)+" meters".
- print "Difference: "+round(difference)+" meters".
- if difference < ship:verticalspeed*10*-1 {
- set ship:control:fore to 1.
- print " ".
- print "Firing RCS for Ullage".
- }.
- set altdiff to (ship:verticalspeed*-1)*0.15+throttleupbuffer.
- }.
- set ship:control:neutralize to true.
- lock throttle to 0.95.
- set W to m0*localacc.
- set twmc to ((T-W)/massflow).
- set throt to 0.95.
- set zer to 0.
- until ship:verticalspeed>-2 {
- wait 0.1.
- set radaralt to ship:altitude-ship:geoposition:terrainheight.
- set uv to v(0,1,0).
- set ev to vcrs(ship:body:position,uv).
- set nv to vcrs(ev,ship:body:position).
- set vec1 to vcrs(ship:body:position,ship:velocity:surface).
- set dot1 to vdot(nv,vec1).
- set anglenorth to -1*(arccos(dot1/(nv:mag*vec1:mag))-90).
- set dot2 to vdot(ev,vec1).
- set angleeast to -1*(arccos(dot2/(ev:mag*vec1:mag))-90).
- if angleeast>0 and anglenorth<0 {
- set anglenorth to 360+anglenorth.
- }. else if angleeast<0 and anglenorth<0 {
- set anglenorth to 180-anglenorth.
- }. else if angleeast<0 and anglenorth>0 {
- set anglenorth to 180-anglenorth.
- }.
- set srfretrohdg to anglenorth-180.
- set aup to 90.
- if ship:groundspeed>0.5 {
- set aup to 87.
- }. else {
- set srfretrohdg to 0.
- }.
- lock steering to heading(srfretrohdg,aup).
- set localacc to (gm/((body:radius+ship:altitude)-(body:radius+ship:geoposition:terrainheight)))*((1/(body:radius+ship:geoposition:terrainheight))-(1/(body:radius+ship:altitude))).
- set m0 to ship:mass*1000.
- set W to m0*localacc.
- set T to ship:maxthrust.
- set twmc to ((T-W)/massflow).
- set radaralt to ship:altitude-ship:geoposition:terrainheight.
- set tb to ((m0 - e^((ln(m0))-((massflow*ship:verticalspeed*-1)/(T-W))))/massflow).
- set mf to (m0-(massflow*tb)).
- set updatedburnalt to twmc*((tb*ln(m0))-(((mf*ln(mf))-mf-(m0*ln(m0))+m0)/-massflow)).
- set difference to (-burnalt+radaralt).
- set newdif to (radaralt-updatedburnalt).
- clearscreen.
- print " ".
- print "Burnalt: "+round(updatedburnalt)+" meters".
- print "Radar Altitude: "+round(radaralt)+" meters".
- print "Updated Diff: "+round(newdif)+" meters".
- if newdif>(shipheight+2) and newdif < 100 {
- set throt to 0.90.
- print " ".
- print "Throttle at "+round(throt*100)+"%".
- }. else if newdif >100 {
- set throt to .85.
- print " ".
- print "Throttle at "+round(throt*100)+"%".
- }. else if newdif < (shipheight+1) {
- set throt to 1.
- print " ".
- print "Throttle at "+round(throt*100)+"%".
- }. else {
- set throt to 0.95.
- print " ".
- print "Throttle at "+round(throt*100)+"%".
- }.
- lock throttle to throt.
- when radaralt-zer < 100 then {
- toggle gear.
- set zer to -100000.
- }.
- }.
- //toggle gear.
- if ship:maxthrust*minthrot > ship:mass*localacc {
- toggle ag1.
- }.
- until ship:verticalspeed > - 1 {
- lock throttle to throt+0.1.
- wait 0.1.
- }.
- until alt:radar < shipheight+0.2 {
- set r to body:radius+ship:altitude.
- set gm to body:mass*constant:G.
- set localacc to gm/r^2.
- set w to localacc*ship:mass.
- set T to ship:maxthrust.
- set throt to (w-(minthrot*T))/(T*(1-minthrot)).
- if ship:verticalspeed < -0.75 {
- set throt to throt+0.05.
- }. else if ship:verticalspeed > -0.5 {
- set throt to throt-0.05.
- }. else {
- set throt to throt.
- }.
- lock throttle to throt.
- wait 0.1.
- }.
- lock throttle to 0.
- rcs off.
- unlock steering.
- set ship:control:pilotmainthrottle to 0.
- set coorpos to latlng(la,lo):position.
- clearscreen.
- print " ".
- print "You landed "+round(coorpos:mag)+" meters".
- print "from the intended landinge site".
- wait until alt:radar<shipheight+0.1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement