Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SimpleKSPOrbitalMechanics is a purely calculation based lua library, with some constants hardcoded for Kerbal Space Program
- -- v0.003
- -- v0.002 changes: added printSkomKSPCurrentVesselInfo, added elements to printSkomKSPCurrentOrbitalElements
- -- v0.003 changes: added reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm(), reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween), printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween), coprintSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwn(TimeBeforeInitial, TimeBetween), and isSkomCurrentOrbitStable()
- --[[ to use, put
- require "SimpleKSPOrbitalMechanics"
- ]]
- --[[ in your lua script, or run it with
- dofile("SimpleKSPOrbitalMechanics")
- ]]
- -- Original Work Copyright 2012, Nadrek, insofar as any elements that aren't obvious, trivial, or mathematics are concerned (none of which are copyrightable)
- -- licensed under your choice of GPLv2, GPLv3, or Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://www.gnu.org/licenses/gpl-2.0.html or http://www.gnu.org/licenses/gpl.html or http://creativecommons.org/licenses/by-sa/3.0/
- -- KSP specific functions will have KSP in the name; other functions will not, and can be used for real life calculations as well.
- -- This script requires SimpleOrbitalMechanics to do the heavy mathematical lifting.
- -- This script contains KSP specific functions and calls useful to and reliant on Kerbal Space Program, MechJeb, and MechJeb's Autom8 module.
- require "SimpleOrbitalMechanics"
- function globalSkomKSPMainBodyResetBasedOnGuessing()
- -- prints body it guessed
- -- also sets the globalMainBody... variables to that body (or all to -1
- -- if the body is UNKNOWN)
- -- Essentially, this function, if called while in orbit around a given body (like the Mun, or Kerbin)
- -- sets some "background" variables so the rest of the functions know how to act based on what
- -- you're orbiting; you use different values for the Min and for Kerbin, because Kerbin is bigger,
- -- has more gravity, has an atmosphere, and has a much larger Hill sphere of influence.
- -- NOTE: Landed, on the launchpad, in ascent, in descent all count as being "in orbit"!
- -- no return value
- local GuessedMainBody = guessSkomKSPWhatBodyIsTheMainBodyCurrentlyBeingOrbited()
- globalSomMainBodyReset(GuessedMainBody)
- print GuessedMainBody
- end
- function guessSkomKSPWhatBodyIsTheMainBodyCurrentlyBeingOrbited()
- -- returns the SimpleOrbitalMechanics name of the body we think we're orbiting.
- -- suitable to pass to globalSomMainBodyReset, or returns UNKNOWN if it cannot tell
- --[[ Ex:
- print(guessSkomKSPWhatBodyIsTheMainBodyCurrentlyBeingOrbited())
- ]]
- -- NOTE: All warnings and notes for guessSomWhatBodyIsTheMainBodyFromaOvAltaslMoe apply.
- return guessSomWhatBodyIsTheMainBodyFromaOvAltaslMoe(vessel.orbitSemiMajorAxis, vessel.speedOrbital, vessel.altitudeASL, 0.01)
- end
- function calcSkomMolniyaApPeFromMainBodyCurrentlyBeingOrbitedFromMoe(MarginOfError)
- -- MarginOfError 0.001 means allow 0.1% for a "safety zone" above the minimum stable altitude, or below the Hill sphere of influence.
- -- Do this if you want to just barely scrape by!
- -- 2 means allow a 200% "safety zone" above the minimum stable altitude, or below the Hill sphere of influence.
- -- Do this if you want to have a much less eccentric orbit - perhaps you want to keep certain orbits clear for other uses!
- -- If in doubt, try setting MarginOfError to 0.1
- -- Returns Ap and Pe of the best possible Molniya orbit for a given body
- -- Returns -1, -1 if no stable Molniya orbit is possible
- -- REQUIRES globalSomMainBodyReset to have been called properly
- -- the simple way is to run globalSkomKSPMainBodyResetBasedOnGuessing() first!
- --[[ Ex:
- do
- local localAp, localPe = calcSkomMolniyaApPeFromMainBodyCurrentlyBeingOrbitedFromMoe(0.1)
- print("Your Apoapsis should be " .. localAp .. " meters and your Periapsis should be " .. localPe .. " meters")
- print(" For a classical Molniya orbit, use an inclination of 63.4, 116.6, -63.4, or -116.6")
- print(" These values are chosen because oblate planets (like the Earth's fat equatorial bulge")
- print(" would change your orbit with other inclinations, since the planet isn't a sphere")
- end
- ]]
- -- For oblate celestial bodies, of course, the inclination of the actual orbit must be 63.4 or 116.6 degrees, so the effect of the oblate equitorial belt is nullified.
- -- Now we call our standard Molniya calculator, and pass in numbers based on the celestial body we claim we're currently in orbit of!
- return calcSomMolniyaApPeFromHsoiMsaMbrGmSrpMoe(globalSomMainBodyHillSphereOfInfluence, globalSomMainBodyMinStableAltitude, globalSomMainBodyEquatorialRadius, globalSomMainBodyGM, globalSomMainBodySiderealRotationalPeriod, MarginOfError)
- end
- function printSkomKSPCurrentOrbitalElements()
- print("orbitApA " .. vessel.orbitApA)
- print("orbitPeA " .. vessel.orbitPeA)
- print("orbitPeriod " .. vessel.orbitPeriod)
- print("orbitTimeToAp " .. vessel.orbitTimeToAp)
- print("orbitTimeToPe " .. vessel.orbitTimeToPe)
- print("orbitLAN (RA/Long of Ascending Node) " .. vessel.orbitLAN)
- print("orbitArgumentOfPeriapsis " .. vessel.orbitArgumentOfPeriapsis)
- print("orbitInclination " .. vessel.orbitInclination)
- print("orbitEccentricity " .. vessel.orbitEccentricity)
- print("orbitSemiMajorAxis (a) " .. vessel.orbitSemiMajorAxis)
- print("speedOrbital " .. vessel.speedOrbital)
- print("speedSurface " .. vessel.speedSurface)
- print("speedVertical " .. vessel.speedVertical)
- print("speedHorizontal " .. vessel.speedHorizontal)
- print("vesselHeading " .. vessel.vesselHeading)
- print("vesselPitch " .. vessel.vesselPitch)
- print("vesselRoll " .. vessel.vesselRoll)
- print("altitudeASL " .. vessel.altitudeASL)
- print("altitudeTrue " .. vessel.altitudeTrue)
- print("altitudeBottom " .. vessel.altitudeBottom)
- print("latitude " .. vessel.latitude)
- print("longitude " .. vessel.longitude)
- print("radius " .. vessel.radius)
- print("localg " .. vessel.localg)
- print("atmosphericDensity " .. vessel.atmosphericDensity)
- print("time " .. vessel.time)
- end
- function reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()
- -- added in v0.003
- -- Simply returns a set of variables for other use.
- -- Ms is the vessel mass in kg
- -- Msd is the vessel mass drag in ???
- -- Ap is the Apoapsis in meters
- -- Pe is the Periapsis in meters
- -- Sop is the sidereal orbital period in seconds
- -- Tmap is the time to Apoapsis in seconds
- -- Tmpe is the time to Periapsis in seconds
- -- Lan is the Longitude of the Ascending Node in degrees
- -- Aop is the Argument of Periapsis in ???
- -- Inc is the Inclination of the orbit in degrees
- -- Ecc is the eccentricity of the orbit in ???
- -- a is the semi-major axis in meters
- -- Ov is the orbital velocity in m/s
- -- Sv is the surface velocity in m/s
- -- Hv is the horizontal velocity in m/s
- -- Vv is the vertical velocity in m/s
- -- Hd is the heading in degrees
- -- Pi is the pitch in degrees
- -- Rl is the roll in degrees
- -- Altasl is the altitude above sea level in meters
- -- Alttru is the true altitude in meters
- -- Altbot is the altitude from the bottom of the vessel in meters ???
- -- Lat is the latitude in degrees
- -- Lng is the longitude in degrees
- -- Rfcb is the Radius From Central Body in meters, the distance in meters from the orbiting
- -- object to the center of gravity it's orbiting (i.e. the center of the planet)
- -- G is the local gravity in m/s
- -- Atmd is the atmospheric denisty in ???
- -- Tm is the time from ??? in seconds
- --[[ example:
- do
- local localMs, localMsd, localAp, localPe, localSop, localTmap, localTmpe, localLan, localAop, localInc, localEcc, locala, localOv, localSv, localVv, localHv, localHd, localPi, localRl, localAltasl, localAlttru, localAltbot, localLat, localLng, localRfcb, localG, localAtmd, localTm = reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()
- print("mass " .. localMs)
- print("massDrag " .. localMsd)
- print("Ap " .. localAp)
- print("Pe " .. localPe)
- print("Sop " .. localSop)
- print("Tmap " .. localTmap)
- print("Tmpe " .. localTmpe)
- print("Lan " .. localLan)
- print("Aop " .. localAop)
- print("Inc " .. localInc)
- print("Ecc " .. localEcc)
- print("a " .. locala)
- print("Ov " .. localOv)
- print("Sv " .. localSv)
- print("Vv " .. localVv)
- print("Hv " .. localHv)
- print("Hd " .. localHd)
- print("Pi " .. localPi)
- print("Rl " .. localRl)
- print("Altasl " .. localAltasl)
- print("Alttru " .. localAlttru)
- print("Altbot " .. localAltbot)
- print("Lat " .. localLat)
- print("Lng " .. localLng)
- print("Rfcb " .. localRfcb)
- print("G " .. localG)
- print("Atmd " .. localAtmd)
- print("Tm " .. localTm)
- end
- ]]
- return vessel.mass, vessel.massDrag, vessel.orbitApA, vessel.orbitPeA, vessel.orbitPeriod, vessel.orbitTimeToAp, vessel.orbitTimeToPe, vessel.orbitLAN, vessel.orbitArgumentOfPeriapsis, vessel.orbitInclination, vessel.orbitEccentricity, vessel.orbitSemiMajorAxis, vessel.speedOrbital, vessel.speedSurface, vessel.speedVertical, vessel.speedHorizontal, vessel.vesselHeading, vessel.vesselPitch, vessel.vesselRoll, vessel.altitudeASL, vessel.altitudeTrue, vessel.altitudeBottom, vessel.latitude, vessel.longitude, vessel.radius, vessel.localg, vessel.atmosphericDensity, vessel.time
- end
- function reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)
- -- added in v0.003
- -- NOTE: Because this has wait() statements, it must be run synchronously with whatever uses the data it returns
- -- NOTE: Because this has wait() statements, it must be run asynchronously with the main game and any control processes!
- -- NOTE: Good luck. It is possible to have the async process update global variables, which will be available to other processes
- -- after the async process finishes. There is likely a much better way to handle this, however.
- -- USED BY: printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)
- -- TimeBeforeInitial is the time to wait prior to the initial measurement in seconds
- -- enter 0 if you're unsure; this is typically to allow engines to come to full throttle
- -- TimeBetweenMeasurements is the time between initial and final measurements in seconds
- -- Returns the same variables as reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm(),
- -- but instead of being instantaneous values, they're the difference between the final value and the initial value (the delta)
- --[[ example:
- do
- local localInitialMs, localFinalMs, localDiffMs, localDiffMsd, localDiffAp, localDiffPe, localDiffSop, localDiffTmap, localDiffTmpe, localDiffLan, localDiffAop, localDiffInc, localDiffEcc, localDiffa, localDiffOv, localDiffSv, localDiffVv, localDiffHv, localDiffHd, localDiffPi, localDiffRl, localDiffAltasl, localDiffAlttru, localDiffAltbot, localDiffLat, localDiffLng, localDiffRfcb, localDiffG, localDiffAtmd, localDiffTm = reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(0.5, 2)
- print("Initial mass " .. localInitialMs)
- print("Final mass " .. localFinalMs)
- print("mass " .. localDiffMs)
- print("massDrag " .. localDiffMsd)
- print("Ap " .. localDiffAp)
- print("Pe " .. localDiffPe)
- print("Sop " .. localDiffSop)
- print("Tmap " .. localDiffTmap)
- print("Tmpe " .. localDiffTmpe)
- print("Lan " .. localDiffLan)
- print("Aop " .. localDiffAop)
- print("Inc " .. localDiffInc)
- print("Ecc " .. localDiffEcc)
- print("a " .. localDiffa)
- print("Ov " .. localDiffOv)
- print("Sv " .. localDiffSv)
- print("Vv " .. localDiffVv)
- print("Hv " .. localDiffHv)
- print("Hd " .. localDiffHd)
- print("Pi " .. localDiffPi)
- print("Rl " .. localDiffRl)
- print("Altasl " .. localDiffAltasl)
- print("Alttru " .. localDiffAlttru)
- print("Altbot " .. localDiffAltbot)
- print("Lat " .. localDiffLat)
- print("Lng " .. localDiffLng)
- print("Rfcb " .. localDiffRfcb)
- print("G " .. localDiffG)
- print("Atmd " .. localDiffAtmd)
- print("Tm " .. localDiffTm)
- end
- ]]
- wait(TimeBeforeInitial)
- local localInitialMs, localInitialMsd, localInitialAp, localInitialPe, localInitialSop, localInitialTmap, localInitialTmpe, localInitialLan, localInitialAop, localInitialInc, localInitialEcc, localInitiala, localInitialOv, localInitialSv, localInitialVv, localInitialHv, localInitialHd, localInitialPi, localInitialRl, localInitialAltasl, localInitialAlttru, localInitialAltbot, localInitialLat, localInitialLng, localInitialRfcb, localInitialG, localInitialAtmd, localInitialTm = reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()
- wait(TimeBetween)
- local localFinalMs, localFinalMsd, localFinalAp, localFinalPe, localFinalSop, localFinalTmap, localFinalTmpe, localFinalLan, localFinalAop, localFinalInc, localFinalEcc, localFinala, localFinalOv, localFinalSv, localFinalVv, localFinalHv, localFinalHd, localFinalPi, localFinalRl, localFinalAltasl, localFinalAlttru, localFinalAltbot, localFinalLat, localFinalLng, localFinalRfcb, localFinalG, localFinalAtmd, localFinalTm = reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()
- return localInitialMs, localFinalMs, localFinalMs - localInitialMs, localFinalMsd - localInitialMsd, localFinalAp - localInitialAp, localFinalPe - localInitialPe, localFinalSop - localInitialSop, localFinalTmap - localInitialTmap, localFinalTmpe - localInitialTmpe, localFinalLan - localInitialLan, localFinalAop - localInitialAop, localFinalInc - localInitialInc, localFinalEcc - localInitialEcc, localFinala - localInitiala, localFinalOv - localInitialOv, localFinalSv - localInitialSv, localFinalVv - localInitialVv, localFinalHv - localInitialHv, localFinalHd - localInitialHd, localFinalPi - localInitialPi, localFinalRl - localInitialRl, localFinalAltasl - localInitialAltasl, localFinalAlttru - localInitialAlttru, localFinalAltbot - localInitialAltbot, localFinalLat - localInitialLat, localFinalLng - localInitialLng, localFinalRfcb - localInitialRfcb, localFinalG - localInitialG, localFinalAtmd - localInitialAtmd, localFinalTm - localInitialTm
- end
- function printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)
- -- added in v0.003
- -- see the core function reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)
- -- This function is designed to be called by a coroutine.
- -- First, a synchronous call to the differencing test.
- local localInitialMs, localFinalMs, localDiffMs, localDiffMsd, localDiffAp, localDiffPe, localDiffSop, localDiffTmap, localDiffTmpe, localDiffLan, localDiffAop, localDiffInc, localDiffEcc, localDiffa, localDiffOv, localDiffSv, localDiffVv, localDiffHv, localDiffHd, localDiffPi, localDiffRl, localDiffAltasl, localDiffAlttru, localDiffAltbot, localDiffLat, localDiffLng, localDiffRfcb, localDiffG, localDiffAtmd, localDiffTm = reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)
- -- Now, report the results
- print("Msi " .. localInitialMs)
- print("Msf " .. localFinalMs)
- print("Ms " .. localDiffMs)
- print("Msd " .. localDiffMsd)
- print("Ap " .. localDiffAp)
- print("Pe " .. localDiffPe)
- print("Sop " .. localDiffSop)
- print("Tmap " .. localDiffTmap)
- print("Tmpe " .. localDiffTmpe)
- print("Lan " .. localDiffLan)
- print("Aop " .. localDiffAop)
- print("Inc " .. localDiffInc)
- print("Ecc " .. localDiffEcc)
- print("a " .. localDiffa)
- print("Ov " .. localDiffOv)
- print("Sv " .. localDiffSv)
- print("Vv " .. localDiffVv)
- print("Hv " .. localDiffHv)
- print("Hd " .. localDiffHd)
- print("Pi " .. localDiffPi)
- print("Rl " .. localDiffRl)
- print("Altasl " .. localDiffAltasl)
- print("Alttru " .. localDiffAlttru)
- print("Altbot " .. localDiffAltbot)
- print("Lat " .. localDiffLat)
- print("Lng " .. localDiffLng)
- print("Rfcb " .. localDiffRfcb)
- print("G " .. localDiffG)
- print("Atmd " .. localDiffAtmd)
- print("Tm " .. localDiffTm)
- end
- function coprintSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwn(TimeBeforeInitial, TimeBetween)
- -- added in v0.003
- -- see the core function printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver
- --[[ ex.
- coprintSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwn(0,1)
- ]]
- local coPrintChangeOverTime = coroutine.create(printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver)
- coroutine.resume(coPrintChangeOverTime, TimeBeforeInitial, TimeBetween)
- end
- function isSkomCurrentOrbitStable()
- -- added in v0.003
- -- returns, technically, simple bit flags:
- -- 0 = stable
- -- 1 = burn up in atmosphere
- -- 2 = escape SOI
- -- 3 = both burn up and escape SOI (whichever comes first)
- -- 4 = your Apoapsis is greater than your Periapsis, which is just wrong.
- -- REQUIRES globalSomMainBodyReset to have been called properly
- -- the simple way is to run globalSkomKSPMainBodyResetBasedOnGuessing() first!
- -- First, let's reset our main body; perhaps we've switch orbits recently!
- globalSkomKSPMainBodyResetBasedOnGuessing()
- return isSomOrbitStableFromApPeHsoiMsa(vessel.orbitApA, vessel.orbitPeA, globalSomMainBodyHillSphereOfInfluence, globalSomMainBodyMinStableAltitude)
- end
- function printSkomKSPCurrentVesselInfo()
- print("CoM[1] " .. vessel.CoM[1])
- print("CoM[2] " .. vessel.CoM[2])
- print("CoM[3] " .. vessel.CoM[3])
- print("up[1] " .. vessel.up[1])
- print("up[2] " .. vessel.up[2])
- print("up[3] " .. vessel.up[3])
- print("north[1] " .. vessel.north[1])
- print("north[2] " .. vessel.north[2])
- print("north[3] " .. vessel.north[3])
- print("east[1] " .. vessel.east[1])
- print("east[2] " .. vessel.east[2])
- print("east[3] " .. vessel.east[3])
- print("forward[1] " .. vessel.forward[1])
- print("forward[2] " .. vessel.forward[2])
- print("forward[3] " .. vessel.forward[3])
- print("rotationSurface[1] " .. vessel.rotationSurface[1])
- print("rotationSurface[2] " .. vessel.rotationSurface[2])
- print("rotationSurface[3] " .. vessel.rotationSurface[3])
- print("rotationSurface[4] " .. vessel.rotationSurface[4])
- print("rotationVesselSurface[1] " .. vessel.rotationVesselSurface[1])
- print("rotationVesselSurface[2] " .. vessel.rotationVesselSurface[2])
- print("rotationVesselSurface[3] " .. vessel.rotationVesselSurface[3])
- print("rotationVesselSurface[4] " .. vessel.rotationVesselSurface[4])
- print("velocityMainBodySurface[1] " .. vessel.velocityMainBodySurface[1])
- print("velocityMainBodySurface[2] " .. vessel.velocityMainBodySurface[2])
- print("velocityMainBodySurface[3] " .. vessel.velocityMainBodySurface[3])
- print("velocityVesselSurface[1] " .. vessel.velocityVesselSurface[1])
- print("velocityVesselSurface[2] " .. vessel.velocityVesselSurface[2])
- print("velocityVesselSurface[3] " .. vessel.velocityVesselSurface[3])
- print("velocityVesselSurfaceUnit[1] " .. vessel.velocityVesselSurfaceUnit[1])
- print("velocityVesselSurfaceUnit[2] " .. vessel.velocityVesselSurfaceUnit[2])
- print("velocityVesselSurfaceUnit[3] " .. vessel.velocityVesselSurfaceUnit[3])
- print("velocityVesselOrbit[1] " .. vessel.velocityVesselOrbit[1])
- print("velocityVesselOrbit[2] " .. vessel.velocityVesselOrbit[2])
- print("velocityVesselOrbit[3] " .. vessel.velocityVesselOrbit[3])
- print("velocityVesselOrbitUnit[1] " .. vessel.velocityVesselOrbitUnit[1])
- print("velocityVesselOrbitUnit[2] " .. vessel.velocityVesselOrbitUnit[2])
- print("velocityVesselOrbitUnit[3] " .. vessel.velocityVesselOrbitUnit[3])
- print("angularVelocity[1] " .. vessel.angularVelocity[1])
- print("angularVelocity[2] " .. vessel.angularVelocity[2])
- print("angularVelocity[3] " .. vessel.angularVelocity[3])
- print("angularMomentum[1] " .. vessel.angularMomentum[1])
- print("angularMomentum[2] " .. vessel.angularMomentum[2])
- print("angularMomentum[3] " .. vessel.angularMomentum[3])
- print("upNormalToVelSurface[1] " .. vessel.upNormalToVelSurface[1])
- print("upNormalToVelSurface[2] " .. vessel.upNormalToVelSurface[2])
- print("upNormalToVelSurface[3] " .. vessel.upNormalToVelSurface[3])
- print("leftSurface[1] " .. vessel.leftSurface[1])
- print("leftSurface[2] " .. vessel.leftSurface[2])
- print("leftSurface[3] " .. vessel.leftSurface[3])
- print("leftOrbit[1] " .. vessel.leftOrbit[1])
- print("leftOrbit[2] " .. vessel.leftOrbit[2])
- print("leftOrbit[3] " .. vessel.leftOrbit[3])
- print("gravityForce[1] " .. vessel.gravityForce[1])
- print("gravityForce[2] " .. vessel.gravityForce[2])
- print("gravityForce[3] " .. vessel.gravityForce[3])
- print("mass " .. vessel.mass)
- print("thrustAvailable " .. vessel.thrustAvailable)
- print("thrustMinimum " .. vessel.thrustMinimum)
- print("maxThrustAccel " .. vessel.maxThrustAccel )
- print("minThrustAccel " .. vessel.minThrustAccel)
- print("torqueRAvailable " .. vessel.torqueRAvailable)
- print("torquePYAvailable " .. vessel.torquePYAvailable)
- print("torqueThrustPYAvailable " .. vessel.torqueThrustPYAvailable)
- print("massDrag " .. vessel.massDrag)
- end
- function helpSkomSimpleKSPOrbitalMechanics1()
- print "Usage: globalSkomKSPMainBodyResetBasedOnGuessing()"
- print " prints body it guessed"
- print " also sets the globalMainBody... variables to that body (or all to -1"
- print " if the body is UNKNOWN)"
- print " Essentially, this function, if called while in orbit around a given body (like the Mun, or Kerbin)"
- print " sets some \"background\" variables so the rest of the functions know how to act based on what"
- print " you're orbiting; you use different values for the Min and for Kerbin, because Kerbin is bigger,"
- print " has more gravity, has an atmosphere, and has a much larger Hill sphere of influence."
- print " NOTE: Landed, on the launchpad, in ascent, in descent, and crashing all count as being \"in orbit\"!"
- print " no return value"
- print "Usage: guessSkomKSPWhatBodyIsTheMainBodyCurrentlyBeingOrbited()"
- print " returns the SimpleOrbitalMechanics name of the body we think we're orbiting."
- print " suitable to pass to globalSomMainBodyReset, or returns UNKNOWN if it cannot tell."
- print " Ex:"
- print " print(guessSkomKSPWhatBodyIsTheMainBodyCurrentlyBeingOrbited())"
- print "Usage: calcSkomMolniyaApPeFromMainBodyCurrentlyBeingOrbitedFromMoe(MarginOfError)"
- print " MarginOfError 0.001 means allow 0.1% for a \"safety zone\" above the minimum stable altitude, or below the Hill sphere of influence."
- print " Do this if you want to just barely scrape by!"
- print " 2 means allow a 200% \"safety zone\" above the minimum stable altitude, or below the Hill sphere of influence."
- print " Do this if you want to have a much less eccentric orbit - perhaps you want to keep certain orbits clear for other uses!"
- print " If in doubt, try setting MarginOfError to 0.1"
- print " Returns Ap and Pe of the best possible Molniya orbit for a given body"
- print " Returns -1, -1 if no stable Molniya orbit is possible"
- print " REQUIRES globalSomMainBodyReset to have been called properly"
- print " the simple way is to run globalSkomKSPMainBodyResetBasedOnGuessing() first!"
- print " Ex:"
- print " do"
- print " local localAp, localPe = calcSkomMolniyaApPeFromMainBodyCurrentlyBeingOrbitedFromMoe(0.1)"
- print " print(\"Your Apoapsis should be \" .. localAp .. \" meters and your Periapsis should be \" .. localPe .. \" meters\")"
- print " print(\" For a classical Molniya orbit, use an inclination of 63.4, 116.6, -63.4, or -116.6\")"
- print " print(\" These values are chosen because oblate planets (like the Earth's fat equatorial bulge\")"
- print " print(\" would change your orbit with other inclinations, since the planet isn't a sphere\")"
- print " end"
- print " For oblate celestial bodies, of course, the inclination of the actual orbit must be 63.4 or 116.6 degrees, so the effect of the oblate equitorial belt is nullified."
- print "Usage: printSkomKSPCurrentOrbitalElements()"
- print " Prints important KSP elements for human use or records"
- print "Usage: printSkomKSPCurrentVesselInfo()"
- print " Prints important KSP vessel information for human use or records"
- end
- function helpSkomSimpleKSPOrbitalMechanics2()
- print "Usage: reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()"
- print " Simply returns a set of variables for other use."
- print " Ms is the vessel mass in kg"
- print " Msd is the vessel mass drag in ???"
- print " Ap is the Apoapsis in meters"
- print " Pe is the Periapsis in meters"
- print " Sop is the sidereal orbital period in seconds"
- print " Tmap is the time to Apoapsis in seconds"
- print " Tmpe is the time to Periapsis in seconds"
- print " Lan is the Longitude of the Ascending Node in degrees"
- print " Aop is the Argument of Periapsis in ???"
- print " Inc is the Inclination of the orbit in degrees"
- print " Ecc is the eccentricity of the orbit in ???"
- print " a is the semi-major axis in meters"
- print " Ov is the orbital velocity in m/s"
- print " Sv is the surface velocity in m/s"
- print " Hv is the horizontal velocity in m/s"
- print " Vv is the vertical velocity in m/s"
- print " Hd is the heading in degrees"
- print " Pi is the pitch in degrees"
- print " Rl is the roll in degrees"
- print " Altasl is the altitude above sea level in meters"
- print " Alttru is the true altitude in meters"
- print " Altbot is the altitude from the bottom of the vessel in meters ???"
- print " Lat is the latitude in degrees"
- print " Lng is the longitude in degrees"
- print " Rfcb is the Radius From Central Body, the distance in meters from the orbiting object to"
- print " the center of gravity it's orbiting (i.e. the center of the planet)"
- print " G is the local gravity in m/s"
- print " Atmd is the atmospheric denisty in ???"
- print " Tm is the time from ??? in seconds"
- end
- function helpSkomSimpleKSPOrbitalMechanics3()
- print "Ex of reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm():"
- print "do"
- print " local localMs, localMsd, localAp, localPe, localSop, localTmap, localTmpe, localLan, localAop, localInc, localEcc, locala, localOv, localSv, localVv, localHv, localHd, localPi, localRl, localAltasl, localAlttru, localAltbot, localLat, localLng, localRfcb, localG, localAtmd, localTm = reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()"
- print " print(\"Ms is the vessel mass in kg \" .. localMs)"
- print " print(\"Msd is the vessel mass drag in ??? \" .. localMsd)"
- print " print(\"Ap is the Apoapsis in meters \" .. localAp)"
- print " print(\"Pe is the Periapsis in meters \" .. localPe)"
- print " print(\"Sop is the sidereal orbital period in seconds \" .. localSop)"
- print " print(\"Tmap is the time to Apoapsis in seconds \" .. localTmap)"
- print " print(\"Tmpe is the time to Periapsis in seconds \" .. localTmpe)"
- print " print(\"Lan is the Longitude of the Ascending Node in degrees \" .. localLan)"
- print " print(\"Aop is the Argument of Periapsis in ??? \" .. localAop)"
- print " print(\"Inc is the Inclination of the orbit in degrees \" .. localInc)"
- print " print(\"Ecc is the eccentricity of the orbit in ??? \" .. localEcc)"
- print " print(\"a is the semi-major axis in meters \" .. locala)"
- print " print(\"Ov is the orbital velocity in m/s \" .. localOv)"
- print " print(\"Sv is the surface velocity in m/s \" .. localSv)"
- print " print(\"Vv is the vertical velocity in m/s \" .. localVv)"
- print " print(\"Hv is the horizontal velocity in m/s \" .. localHv)"
- print " print(\"Hd is the heading in degrees \" .. localHd)"
- print " print(\"Pi is the pitch in degrees \" .. localPi)"
- print " print(\"Rl is the roll in degrees \" .. localRl)"
- print " print(\"Altasl is the altitude above sea level in meters \" .. localAltasl)"
- print " print(\"Alttru is the true altitude in meters \" .. localAlttru)"
- print " print(\"Altbot is the altitude from the bottom of the vessel in meters ??? \" .. localAltbot)"
- print " print(\"Lat is the latitude in degrees \" .. localLat)"
- print " print(\"Lng is the longitude in degrees \" .. localLng)"
- print " print(\"Rfcb is the Radius From Central Body in meters \" .. localRfcb)"
- print " print(\"G is the local gravity in m/s \" .. localG)"
- print " print(\"Atmd is the atmospheric denisty in ??? \" .. localAtmd)"
- print " print(\"Tm is the time from ??? in seconds \" .. localTm)"
- print "end"
- end
- function helpSkomSimpleKSPOrbitalMechanics4()
- print "Usage: isSkomCurrentOrbitStable()"
- print " Returns 0 for stable, 1 for burn up in atmosphere, 2 for escape"
- print " sphere of influence (SOI), and 3 for burn up AND escape SOI"
- print "Usage: reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)"
- print " Call by synchronous function which is in turn called by coroutine only. Returns Initial Mass, Final Mass, then the normal"
- print " reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm() variables as differences over time."
- print "Usage: printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)"
- print " TimeBeforeInitial is the \"spool up\" delay in seconds we're going to use"
- print " this is how much time we think it takes our engines to come to stable thrust"
- print " i.e. 0.5 means set thrust to the desired value, then wait half a second, then start the measurement for this \"slice\""
- print " For the bell rocket engines in 0.16, 0.25 is a reasonable minimum for TimeBeforeInitial"
- print " TimeBetween is the time in seconds between initial and final measurements"
- print " For the bell rocket engines in 0.16, 0.25 is a reasonable minimum for TimeBetween"
- print " CALL VIA COROUTINE ONLY; returns the variables from reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm"
- print " as differences (EXCEPT the first two return variables are Msi and Msf, the Initial mass and Final mass, followed by"
- print " the differences in the reportSkom... variables) instead of instantaneously as the reportSkom... does."
- print "Usage: coprintSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwn(TimeBeforeInitial, TimeBetween)"
- print " This is the coroutine that calls printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)"print " and prints the values to the console."
- print " ex. coprintSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwn(0.25,1)"
- end
- globalSkomKSPMainBodyResetBasedOnGuessing() -- initalize main body dependent variables based on guessing what body we're orbiting.
- print "Usage: helpSkomSimpleKSPOrbitalMechanics1() through helpSkomSimpleKSPOrbitalMechanics4()"
- print " gives detailed help on all Skom functions."
- print " Skom functions relate to Kerbal Space Program (KSP) mathematical functionality."
- print("If it helps, I'm guessing you are currently orbiting " .. globalSomMainBodyName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement