Jump to content

MechJeb Autom8 Scripts Megathread


r4m0n

Recommended Posts

is it possible to make a script to automatically change the inclination of an orbit while in that orbit? or does mechjeb already have a way i can do this and i'm just too dense?

it is possible to make a script to automatically do it. i have actually been working on one for over a week now but i have a problem in my equations somewhere >_<

Link to comment
Share on other sites

it is possible to make a script to automatically do it. i have actually been working on one for over a week now but i have a problem in my equations somewhere >_<

If I may ask, I was waiting to even try this until I can warp to the ascending or descending node - have you actually worked out the amount of time from apoapsis/periapsis to the ascending/descending node for elliptical orbits, or are you using a different technique?

My plan would have been to try and figure out the delta-V required, then do a burn anticipated to reach it, possibly with some fudge factor and touch-up afterwards for the highest accuracy, and possibly multi-orbit based if the thrust available isn't high enough.

Link to comment
Share on other sites

OK I am currently using the FlyMeToTheMun(45,45) script.

I launched and reached 125km orbit successfully. Now I have been warping to SOI for 4 (edit: now 7) kerbal days. How long will I need to wait for the SOI? Do I need to abort and retry? This is my first shot at getting to the Mun and have no clue if I am doing it right.

I also have tried some forum searches and found nothing. Thanks!

Edit- And after I post this, now I have transitioned to warping to Periapsis. Of course the Pe keeps moving slightly, so it is taking a while as well. Hopefully I am doing this right!

Edit - And now it just tried to land on Kerbin without ever transferring to the Mun. Not sure what I did wrong.

Edited by calhoun1
Link to comment
Share on other sites

If I may ask, I was waiting to even try this until I can warp to the ascending or descending node - have you actually worked out the amount of time from apoapsis/periapsis to the ascending/descending node for elliptical orbits, or are you using a different technique?

My plan would have been to try and figure out the delta-V required, then do a burn anticipated to reach it, possibly with some fudge factor and touch-up afterwards for the highest accuracy, and possibly multi-orbit based if the thrust available isn't high enough.

my plan was to calculate the position of the burn nodes, calculate the time until the craft reached the nearest one, warp to it, calculate the amount of time and the amount of thrust needed, make the burn until the amount of time needed has elapsed or it is too far from the burn point, then redo the calculations to see if another burn is needed

so far my equations get within 12% of the target position, which is unacceptable

Link to comment
Share on other sites

my plan was to calculate the position of the burn nodes, calculate the time until the craft reached the nearest one, warp to it, calculate the amount of time and the amount of thrust needed, make the burn until the amount of time needed has elapsed or it is too far from the burn point, then redo the calculations to see if another burn is needed

so far my equations get within 12% of the target position, which is unacceptable

Hmm; I'd have to wonder if you redid all your calculations after the warp (and noted the differences), and if you accounted for thrust ramp-up and ramp-down time and the change in attitude required during the burn.

When you say within 12%, are you always under, always over, or sometimes some of each?

May I also ask how you warped to the nearest burn node?

Link to comment
Share on other sites

SimpleKSPOrbitalMechanics upgraded to 0.003 and SimpleKSPOrbitalOperations upgraded to 0.002; see post #53 in this thread for more details (now includes function listings!).

http://kerbalspaceprogram.com/forum/showthread.php/16503-MechJeb-Autom8-Scripts-Megathread?p=238962&viewfull=1#post238962

Togfox, there's code to calculate actual measured Isp (at whatever throttle setting you like) from any rocket you can get into stable orbit. You could then calculate exhaust velocity from this and feed it into your delta-V calculator if you still don't like mine :). Try it on every stage for fun and profit :).

Added KSP based isOrbitStable, reporting on orbital and mass variables instantaneously and over time(!), and operational testing of actual Isp at various thrust settings. Skoo now has functional code to detect when mechjeb.attitudeTo() has finished pointing.

New Skom functions:

isSkomCurrentOrbitStable()

reportSkomCurrentMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTm()

reportSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)

printSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwnDriver(TimeBeforeInitial, TimeBetween)

coprintSkomCurrentChangeOverTimeMsiMsfMsMsdApPeSopTmapTmpeLanAopIncEccAOvSvVvHvHdPiRlAltaslAlttruAltbotLatLngRfcbGAtmdTmFromTmbiTmbtwn(TimeBeforeInitial, TimeBetween)

New Skoo functions:

measureSkooIspFromTmbiTmbtwnNsDriver(TimeBeforeInitial, TimeBetweenEach, NumberSlices)

testSkooIspFromTmbiTmbtwnNsMpcsDriver(TimeBeforeInitial, TimeBetweenEach, NumberSlices, MaxPointingChangeStable)

cotestSkooIspFromTmbiTmbtwnNs(TimeBeforeInitial, TimeBetweenEach, NumberSlices)

cotestSkooIspFromTmbiTmbtwnNsMpcs(TimeBeforeInitial, TimeBetweenEach, NumberSlices, MaxPointingChangeStable)

Link to comment
Share on other sites

Togfox, there's code to calculate actual measured Isp (at whatever throttle setting you like) from any rocket you can get into stable orbit. You could then calculate exhaust velocity from this and feed it into your delta-V calculator if you still don't like mine . Try it on every stage for fun and profit .

I had considered doing that - that will remove one of my parameters - a pretty important one mind you. That means "fuel left" would be the only manually entered input - and that's available in-game with a right-mouse-click. :)

Link to comment
Share on other sites

I had considered doing that - that will remove one of my parameters - a pretty important one mind you. That means "fuel left" would be the only manually entered input - and that's available in-game with a right-mouse-click. :)

There's a userecho request for it to be in-game, per stage, to the lua code.

Alternately, at the design stage, write down the amount of fuel per stage in mass units, and then feed your code one parameter - the dry mass of the rocket, and then it can calculate fuel from the wet mass... as long as you don't use more than one fuel type (i.e. RCS).

Link to comment
Share on other sites

Has anyone written a program to travel to a given lat, lon? For example, I'm trying to circumnavigate the globe, and now that you cannot accelerate time while in the atmosphere, I'd like to automate some of the longer crossings without worrying about over-shooting and crashing into land. Has anyone written such a program?

Link to comment
Share on other sites

Hopefulyl this is what you were looking for to help ( A HUGE thank yuo to you and the rest of this community, you guys are awesome!) This is from the webpage directly, copied, and put in thru notepad++

1.
--

2.
-- Mun to Kerbin Return Script by olex

3.
-- Version 1.0

4.
--

5.
-- for MechJeb 1.9.1

6.
--

7.
--------------------------------------------------------

8.
-- Usage: * save to KSP/PluginData/mumechlib/GoHome.lua

9.
-- * in game, open autom8

10.
-- * enter: dofile("GoHome.lua")

11.
-- * and follow the instructions.

12.
--

13.
-- Quicksave before using.

14.
-- If an "coroutine out of sync" error pops up, load the save and try again.

15.
--

16.
-- No guarantees, but it should work Have fun!

17.
--------------------------------------------------------

18.


19.
function KerbinReturnDriver(pe)

20.
if pe == nil then

21.
pe = 20.0

22.
end

23.
if pe > 70 then

24.
print "Final periapsis not in atmosphere, no automatic landing."

25.
end

26.


27.
print "Lifting off..."

28.
mechjeb.attitudeTo("up", "SURFACE_NORTH") -- vertical ascent

29.
mechjeb.thrustActivate(100)

30.
while vessel.altitudeTrue < 300 do

31.
wait(0.25)

32.
end

33.


34.
print "Escaping the Mun..."

35.
-- this needs to be optimized. figure out an escape vector

36.
-- that is as close as possible to the opposite of Mun's orbital velocity

37.
-- but not lower than 0° to the surface

38.
mechjeb.attitudeTo("right", "SURFACE_NORTH") -- heading east

39.
while vessel.orbitEccentricity < 1 do

40.
wait(0.25)

41.
end

42.
mechjeb.thrustDeactivate()

43.


44.
print "Coasting to Mun escape, hang on."

45.
mechjeb.warpToEvent("soi")

46.
wait(mechjeb.free)

47.


48.
print("Lowering Kerbin periapsis to "..pe.."km...")

49.
mechjeb.changePe(pe * 1000)

50.
wait(mechjeb.free)

51.


52.
print "Coasting to Kerbin, stand by."

53.
mechjeb.warpToEvent("pe")

54.
while vessel.atmosphericDensity <= 0 and (not mechjeb.free()) do

55.
wait(0.25)

56.
end

57.
mechjeb.controlRelease()

58.


59.
if vessel.atmosphericDensity > 0 then

60.
print "Re-entry... hold onto something."

61.
mechjeb.attitudeTo("back", "ORBIT")

62.
while vessel.speedSurface > 250 do

63.
wait(0.1)

64.
end

65.
print "Landing."

66.
mechjeb.autoStageActivate()

67.
mechjeb.land()

68.
wait(mechjeb.free)

69.
mechjeb.autoStageDeactivate()

70.
print "Welcome home!"

71.
else

72.
print "Not in atmosphere at periapsis. We're done here."

73.
end

74.
end

75.


76.
function GoHome(pe)

77.
local co = coroutine.create(KerbinReturnDriver)

78.
coroutine.resume(co, pe)

79.
end

80.


81.
print "Usage: GoHome(<desired Kerbin periapsis in km, default 20>)"

Link to comment
Share on other sites

Again, thanks to the KSP and Mechjeb teams for providing us with such an exciting toolbox to play with in an easily written and scripted interpreted language. With little more than KSP, Mechjeb, a text editor, and some typing we can land on the Mun, get into a Molniya orbit, or perform most other manuevers.

I think I may be running into either mechjeb.* data limit, or a limit in my vocabulary, as I'm rapidly approaching a stalling point where I have almost, but not quite, all the orbital elements. to do more math and then more operations with.

I'm asking for help in gathering the following information, either directly or by pointing out the elements I have that I can use to derive the following:

A. Mean Anomaly at Epoch and units (or any of the related anomalies - Mean Anomaly, True Anomaly, perhaps the Eccentric Anomaly)

EDIT: A.1 in Kerbin Orbital Parameters V2 (https://docs.google.com/document/d/1fmTW6P91OVFj5Tuj0JzKcnfpcw79RqveQTAywrPIIrI/edit?pli=1#heading=h.ktf15rmlbwy8) I see a formula that says it's for Mean Anomaly at Epoch based solely on semi-major axis, the standard gravitational parameter, and time since periapsis. My questions now becomes: is that correct, Epoch is strictly arbitrary (i.e. the first step in any set of formulas that use Epoch is to synchronize Epochs, and/or set them all to a reference value, like - arbitrarily - vessel.time = 0)? I'm still seeking the formulas and elements for circles, equatorial circles, parabolas, and hyperbolas, though.

B. True longitude (is it the same as vessel.longitude) and units

C. True latitude (is it the same as vessel.latitude) and units

Or, alternately:

D. Position Vector and units

E. Velocity Vector and units

F. Frame of reference and units

G. Any recommended pure lua library for matrix and vector math to code the conversions with :).

Some references on equations I'd like to be able to use (True Anomaly or other values required): http://kerbalspaceprogram.com/forum/showthread.php/10037-Getting-Absolute-Longitude-%28in-same-reference-system-as-LAN%29?p=216289&viewfull=1#post216289

Edited by Nadrek
Learned more, amended A
Link to comment
Share on other sites

Chance question- can mechjeb's autom8 fire off events from other modules, such as the orbital construction mod's transfer cargo feature?

Was thinking about making a script that would launch an unmanned cargo vessel, approach spacedock, transfer cargo, and then deorbit to crash land. Or if I felt up to it, return to KSP after delivering the cargo.

Link to comment
Share on other sites

From the UserEcho, I found 'access the C# class with mechjeb.core.targetVessel"

1) What's the companion way of getting to a body, like the Mun, Minmus (Eve), etc.?

2) Is there one of the C# files from the svn repository I can ready to see what options I have for mechjeb.core.*, or mechjeb.core.targetVessel? Or a way in lua to enumerate all the possible options? I hate asking silly questions like these.

In MechJeb 1.9.1, I popped up the Rendevous module, selected a Vessel from the Spacecraft exchange at 1200km distance, and tried:

> print(mechjeb.core.targetVessel.speedOrbital)

receiving:

Exception: Cannot get speedOrbital from Talos-MKII Debris (unloaded) (Vessel)

So it's reading the target correctly, but I don't know how to use it :). I then selected the Mun, and tried again - still pointed at the Talos debris (unsurprisingly)

Link to comment
Share on other sites

From the UserEcho, I found 'access the C# class with mechjeb.core.targetVessel"

1) What's the companion way of getting to a body, like the Mun, Minmus (Eve), etc.?

2) Is there one of the C# files from the svn repository I can ready to see what options I have for mechjeb.core.*, or mechjeb.core.targetVessel? Or a way in lua to enumerate all the possible options? I hate asking silly questions like these.

In MechJeb 1.9.1, I popped up the Rendevous module, selected a Vessel from the Spacecraft exchange at 1200km distance, and tried:

> print(mechjeb.core.targetVessel.speedOrbital)

receiving:

Exception: Cannot get speedOrbital from Talos-MKII Debris (unloaded) (Vessel)

So it's reading the target correctly, but I don't know how to use it :). I then selected the Mun, and tried again - still pointed at the Talos debris (unsurprisingly)

1 - mechjeb.core.targetBody

2 - http://svn.mumech.com/KSP/trunk/MuMechLib/MechJebCore.cs

Note that targetVessel is a C# Vessel object, not a VesselState like the Lua "vessel" variable. What you wanted would be mechjeb.core.targetVessel.orbit.orbitalSpeed.

Link to comment
Share on other sites

Excellent - thank you, r4m0n! I was able to determine many of the relevant values by guesswork.

Unfortunately, in any of the .cs files, looking for even "orbitalSpeed" did not turn up anything other than part.vessel.orbit.getOrbitalSpeedAt(timeLeft), which I couldn't figure out in Lua by guesswork.

Is there another place to look for the contents of the C# Vessel (and Body) object? I'm sorry for the basic questions.

If anyone else can use it, here's a list of the additional functionality I've read on the forums/userecho, or found based on r4m0n's help so far:


Undocumented commands:
mechjeb.stage()
increments stage, just like hitting space bar
mechjeb.controlRelease()
deactivates the .attitudeTo(), .thrustActivate() and perhaps other commands
mechjeb.thrustActivate(Percentage)
sets engines to that level
mechjeb.thrustDeactivate()
turns off engines
mechjeb.warpIncrease()
increases warp factor by 1
Returns True if the warp increase succeeded, False if it failed
mechjeb.warpDecrease()
decreases warp factor by 1
Safe to re-run when at 0
Always returns nil
mechjeb.warpPhysics()
0.16 - sets warp to 1x
mechjeb.warpMinimum()
0.16 - sets warp to 1x
mechjeb.getAttitudeActive()
returns boolean - apparently whether Smart A.S.S. or a similar attitude hold is in effect
mechjeb.attitudeDeactivate()
disables .attitudeTo() and/or Smart A.S.S. without changing thrust.

var = mechjeb.getModule(ModuleName)
??
mechjeb.attitudeGetReferenceRotation(??)
??
mechjeb.attitudeWorldToReference(??)
??
mechjeb.attitudeReferenceToWorld(??)
??
mechjeb.attitudeAngleFromTarget(??)
??
mechjeb.distanceFromTarget(??)
??
mechjeb.relativeVelocityToTarget(??)
??
mechjeb.targetName(??)
??
mechjeb.landActivate(??)
??
mechjeb.landDeactivate(??)
??
mechjeb.launch(??)
??
mechjeb.mechjeb.getControlClaimed()
?? - returns False even with both Smart A.S.S./.attitudeTo() and .thrustActivate() active

EITHER mechjeb.core.targetVessel (select target Vessel or Debris, NOT Bodies, in Rendevous Module GUI)
OR mechjeb.core.targetBody (select target Celestial Body in Rendevous Module GUI)
.orbit.orbitalSpeed
Example: print(mechjeb.core.targetBody.orbit.orbitalSpeed)
returnsTarget orbital speed in m/s

mechjeb.core.targetBody.orbit.orbitalSpeed
returns Target orbital speed in m/s
.latitude (targetVessel ONLY!!!)
returns Target latitude in ??
.longitude (targetVessel ONLY!!!)
returns Target longitude in ??
.orbit.semiMajorAxis
returns Target semi-major axis in meters
.orbit.LAN
returns Target LAN in degrees
.orbit.eccentricity
returns Target
.orbit.argumentOfPeriapsis
returns target Argument of Periapsis in degrees
.orbit.altitude
returns target ??(ASL? Bottom? True? Other?) altitude in meters
.orbit.ApA
returns target Apoapsis in meters
.orbit.PeA
returns target Periapsis in meters
.orbit.inclination
returns target Inclination in degrees
.orbit.period
returns target Period in seconds
.orbit.timeToPe
returns target time to Periapsis in seconds
.orbit.timeToAp
returns target time to Apoapsis in seconds
.orbit.radius
returns orbital radius (from center of body being orbited) in meters
.CoM[1] (targetVessel ONLY!!!)
returns ??
.CoM[2] (targetVessel ONLY!!!)
returns ??
.CoM[3] (targetVessel ONLY!!!)
returns ??

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...