Jump to content

MechJeb Autom8 Scripts Megathread


r4m0n

Recommended Posts

With the release of MechJeb 1.9, the Autom8 module was finally released to the public (although in an early beta fashion).

Now with the 1.9.1 release, things have got stable enough that a few scripts started popping up, and I've decided to create this new thread to focus on Autom8 script discussion and release.

I'll try to keep the OP updated with links to any scripts posted here, and any documentation related to it.

Documentation Links

Scripts

Using Scripts

  1. Click on the script link (I'll try to keep all scripts in pastebin for now);
  2. Click on Download;
  3. Save the script as something.lua in KSP/PluginData/mumechlib/
  4. In the Autom8 console, type: dofile("something")
  5. ???
  6. Profit!

Sending Scripts

Create and test your script. Reading other people scripts is a good way to see how it works in general, and the Autom8 manual should help with what you need for your specific ideas. If you can't find it on the manual, post in this thread and I'll try to clear it up, or add new functions when needed.

With your script done, send a copy to pastebin (bonus points for using Lua coloring :P). Optionally, you could also upload a video of your script running so people can see what it does.

With that in hand, just post a name for the script, the link to the pastebin copy and optionally a link to the video, and I'll add it to the script list.

This thread is for Autom8 scripting discussion only, please direct any other MechJeb related discussion to the main MechJeb thread.

Edited by r4m0n
Link to comment
Share on other sites

Very nice. Can you add a 'mechjeb.api' command to 'stage', like mechjeb.stage.

The theory is that I don't want to activate/deactivate the autostage but I want to fly to a certain point, foce a stage just once (or twice) to discard a booster that still has fuel or to 'eject' a satalite into orbit, then continue on with the script?

Nice work. I hope you're enjoying this process. :)

Edit: Can you also expose the craft weight and thrust or TWR or all of it. :) It's available in the information screens. I'm thinking of a script that will auto-abort if a pilot tries a maneuvor that is beyond the craft capabilities. Is there a way to abort a script mid way if a disaster is detected? Lots of questions and lots of opportunities bouncing around my head. :)

Edited by togfox
Link to comment
Share on other sites

The technology should be craft independent. A 'circularise' operation on one craft will be exactly the same for another craft, unless it is so bizarrely designed it requires odd instructions.

I expect to see a library of common scripts accumulate in this thread so even amateurs can copy/paste the operations they need into a sequence to complete their mission profile. :)

Link to comment
Share on other sites

Very nice. Can you add a 'mechjeb.api' command to 'stage', like mechjeb.stage.

Edit: Can you also expose the craft weight and thrust or TWR or all of it. :) It's available in the information screens.

Is there a way to abort a script mid way if a disaster is detected?

mechjeb.stage() works since 1.9.1, just not documented yet.

Check the vessel.* variables in the docu: vessel.mass and vessel.thrustAvailable are what you want, they're in there.

mechjeb.controlRelease() should stop any running Mechjeb sequence.

The technology should be craft independent. A 'circularise' operation on one craft will be exactly the same for another craft, unless it is so bizarrely designed it requires odd instructions.

I think both generic and craft-specific scripts are a good thing. Craft-specific scripts could help with ships that are hard to control, say, a heavy spaceplane that requires precise input to lift off without striking the runway or the ground - just provide a liftoff script with the plane in Spacecraft Exchange, and you don't have to teach people to fly it.

Scripts posted in this thread should remain ship-independent, within reason of course. E.g. I'm currently working on a Buran-like space shuttle deorbit and landing program, that would obviously only work on spaceplanes that are good enough in atmospheric flight to actually make the runway.

Edited by olex
Link to comment
Share on other sites

The technology should be craft independent. A 'circularise' operation on one craft will be exactly the same for another craft, unless it is so bizarrely designed it requires odd instructions.

I know it is, but it's the crafts that have weird instructions that I'm talking about. You could have a craft where you fire one set of engines a few seconds before another set, but another person trying out your ship might not know that. You could use a script specially designed for that ship as a way to give instructions on how to fly it.

Link to comment
Share on other sites

Cool feature. Is there a way (or will there be a way) to actually control RCS thrusters, SAS modules, etc, from the autom8 program? Then we could develop our own control algorithms for attitude control and things like that.

Link to comment
Share on other sites

I know it is, but it's the crafts that have weird instructions that I'm talking about. You could have a craft where you fire one set of engines a few seconds before another set, but another person trying out your ship might not know that. You could use a script specially designed for that ship as a way to give instructions on how to fly it.

But... why would you need to do that in any sane case? Mechjeb can fly almost any ship perfectly already.

Link to comment
Share on other sites

What am I doing wrong?

> dofile("flymetothemun")

Usage: FlyMeToTheMun(lat, lon)

> flymetothemun (45,45)

Exception: Invoke function call on non function value.

I have the lua file in place - you can see it's loaded. My lua script is copy/pasted from wiki. ??

Link to comment
Share on other sites

I dont even get that far. Mine says it cant find the file. I followed the instructions, as simple as they are and still cant seem to get this to work for me.

Downloaded the script to ksp_win/plugindata/mumechlib/. Named the file mun.lua. When I type: dofile("mun") it just brings up the search string and says its not there. where am I going wrong?

Link to comment
Share on other sites

I know its a extremely long shot, but is there any chance of access to the Windows calibrated Joystick data? Or at least access to the raw data that Unity has access to (can do calibration in the autom8 script). Access to that data without having to map in KSP's control settings would be essential.

Oooh, oooh! While I'm at it I would also like to request a GFX output window with some BASICesque drawing commands (line, circle, colour, cls, etc) :)

Link to comment
Share on other sites

Could you make it load Autorun.lua? I downloaded the source and modified it myself to do it, but I'd rather not do it every update.


public void LoadAutorun()
{
try
{
LuaRuntime.GlobalEnvironment = luaEnv;
LuaRuntime.RunFile("Autorun.lua", luaEnv);
}
catch(Exception e)
{
log += "Autorun Failed.\n";
log += e.GetType().Name + ": " + e.Message + "\n";
}
}

Easy peasy

Link to comment
Share on other sites

I dont even get that far. Mine says it cant find the file. I followed the instructions, as simple as they are and still cant seem to get this to work for me.

Downloaded the script to ksp_win/plugindata/mumechlib/. Named the file mun.lua. When I type: dofile("mun") it just brings up the search string and says its not there. where am I going wrong?

Try doing

dofile("mun.lua")

I've found stuff can act weird if you don't append the .lua, somehow.

Link to comment
Share on other sites

this is what I get

> dofile("mun.lua")

IsolatedStorageException: Could not find file "C:\Users\not yours\Documents\KSP_win\PluginData\mumechlib\mun.lua".

same if I do

> dofile("mun")

IsolatedStorageException: Could not find file "C:\Users\not yours\Documents\KSP_win\PluginData\mumechlib\mun".

Link to comment
Share on other sites

A new script is finished and ready for release: Spaceplane Orbit-to-Runway automatic landing program.

You're in orbit with your spaceplane, want to land on the runway, but don't know how to get there? No problem - use the Orbit-to-Runway autopilot and you're all set! Just make sure you're in a stable orbit above 80km that's not too strongly inclined and that your spaceplane glides stable-ish (equatorial orbit works best, polar will require a very maneuverable spaceplane).

Call "dofile("Shuttle")" and then "Land()". You can also specify a glideslope angle and glide distance from runway, defaults are 3° and 40km.

Script available at http://pastebin.com/t6FrTCQC

Link to comment
Share on other sites

Could you make it load Autorun.lua? I downloaded the source and modified it myself to do it, but I'd rather not do it every update.

I'll add it here, I've actually forgotten to include it in 1.9.1.

this is what I get

> dofile("mun.lua")

IsolatedStorageException: Could not find file "C:\Users\not yours\Documents\KSP_win\PluginData\mumechlib\mun.lua".

same if I do

> dofile("mun")

IsolatedStorageException: Could not find file "C:\Users\not yours\Documents\KSP_win\PluginData\mumechlib\mun".

Sounds like the file isn't there. Most likely, windows is hiding your extensions, and it's a .txt else than .lua. try dofile("mun.lua.txt")

Link to comment
Share on other sites

I have scripts working and will post a few when they are polished. Am I able to do

print vessel.altitudeASL

and 'report' to the window the vessel's current height? How would I do this (assuming it's even possible).

Link to comment
Share on other sites

Here's my beginning efforts. A simple orbit script that could be used by anyone.

Type this into autom8

> dofile("launchtoorbit")

Usage: launchtoparkingorbit() (puts craft in 125km orbit)

Usage: launchtogeoorbit() (puts craft in geostationary orbit)

I can't attach files so copy/paste this into a file called launchtoorbit.lua


--
-- script written by togfox
-- scirpt based off FlyMeToTheMun.lua
--

function launchtoorbitDriver(alt)
if (alt == 125000) then
print "Launching to parking orbit"
else
print "Launching to geostationary orbit"
end
mechjeb.autoStageActivate()
mechjeb.launchTo(alt, 0)
mechjeb.autoStageDeactivate()
wait(mechjeb.free)
print "autom8 complete"
end

function launchtoparkingorbit()
local co = coroutine.create(launchtoorbitDriver)
coroutine.resume(co,125000)
end

function launchtogeoorbit()
local co = coroutine.create(launchtoorbitDriver)
coroutine.resume(co,2868400)
end

print "Usage: launchtoparkingorbit() (puts craft in 125km orbit)"
print "Usage: launchtogeoorbit() (puts craft in geostationary orbit)"

I'll offer more sophisticated scripts as I get better at this. :)

Link to comment
Share on other sites

Oh, and here is my template for all to share


--
-- script written by ...
-- script based off ...
-- credits to ...

function abcmain(xyz)
...
end

function abc(xyz)
local co = coroutine.create(abcmain)
coroutine.resume(co,xyz)
end

function usage()
print "Usage:abc(xyz) (description)"
end

usage()

This template means you can type usage() anytime you like and get a list of functions within the file. I already have four functions and I'm already forgetting the exact syntax. I can type usage() and get an instant reminder. :)

Edited by togfox
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...