Jump to content

MechJeb Autom8 Scripts Megathread


r4m0n

Recommended Posts

I looked at your script, and I noticed that you know commands that I do not - mechjeb.thrustActivate(10), mechjeb.controlRelease(), and mechjeb.stage() are not on the Autom8 wiki page I was using as a reference, much less ils = mechjeb.getModule("ils") ils.glideslope = slope - how did you find them - read the source code for Mechjeb, or some other way?

Most of those undocumented functions/features came straight from me in IRC, I'll try to complete the Autom8 docs ASAP.

Is there any kind of exception handling that can be used to find these exceptions and retry a random but short amount of time later?

Hum, I can try wrapping the internals of the wait() function in a try-catch, that may solve it...

Link to comment
Share on other sites

Anyway to play a wav, mp3 or other sound file from autom8? (long shot, I realise).

I think that's a bad idea for all Kerbalkind. One day, you're going to bouncing around the system, and you're going to hear

"I'm sorry, Dave, I'm afraid I can't do that."

Edited by Nadrek
minor wording change
Link to comment
Share on other sites

I looked at your script, and I noticed that you know commands that I do not - mechjeb.thrustActivate(10), mechjeb.controlRelease(), and mechjeb.stage() are not on the Autom8 wiki page I was using as a reference, much less ils = mechjeb.getModule("ils") ils.glideslope = slope - how did you find them - read the source code for Mechjeb, or some other way?

I found it in olex Landing script.

I modified a litle Space Plane from Muun to KSC script.

Inclination change now working even if start is not near equator.

There is spmunksc1.1

http://pastebin.com/LP5nfn6B

Edited by mager42
Link to comment
Share on other sites

I'd like to suggest a change that should streamline and enhance the capabilities of the staging.

Instead of...

mechjeb.autoStageActivate()

mechjeb.autoStageDeactivate()

mechjeb.Stage()

It should be just...

mechjeb.stage(X)

where if...

X=Nil then proceed to next stage

X=A then activate auto staging

X=D then deactivate auto staging

and if

X=a number, then attempt to stage to the listed number

Also, vessel.stage should exist as a variable, listing the current active stage.

Link to comment
Share on other sites

help me please I copyed and pasted the flymetothemun script named it mun

did dofile"mun"and got this gobledegook. :(

ParserException: Code has syntax errors:

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse 'nil' of NilLiteral.

Line 1, Col 2 '.': Failed to parse Text of BoolLiteral.

Line 1, Col 2 '.': Failed to parse '0'...'9' of Digit.

Line 1, Col 2 '.': Failed to parse Name of VariableArg.

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse firstTerm of OperatorExpr.

Line 1, Col 2 '.': Failed to parse 'nil' of NilLiteral.

Line 1, Col 2 '.': Failed to parse Text of BoolLiteral.

Line 1, Col 2 '.': Failed to parse '0'...'9' of Digit.

Line 1, Col 2 '.': Failed to parse Name of VariableArg.

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse Expr of ExprStmt.

Line 1, Col 2 '.': Failed to parse remaining input.

Link to comment
Share on other sites

help me please I copyed and pasted the flymetothemun script named it mun

did dofile"mun"and got this gobledegook. :(

Start by trying; dofile("mun")

The rest is garbage, ignore it.

After it's FlyMeToTheMun(lat,lon) caps required.

Link to comment
Share on other sites

mechjeb.stage() does not seem to do anything in a function called by coroutine, is this because ksp is not meant to be multi-threaded? if so then is there a work around since the wait function outside of a coroutine (understandably) freezes the game?

Link to comment
Share on other sites

Sorry agan but this happened

> FlyMeToTheMun(0.414,40.830)

Exception: Invoke function call on non function value.

> FlyMeToTheMun(45,45)

Exception: Invoke function call on non function value.

did you get the message "Usage: FlyMeToTheMun(lat, lon)" when you told it run the file?

Link to comment
Share on other sites

no I really don't know why. is my file kaput?

if your using windows, go to the folder where the file is and press alt then under the tools menu select folder options then go to view and make sure that the "Hide extensions for known file types" is unchecked and click ok

then look at your file again and make sure you are using the whole file name

Edited by khmnc
Link to comment
Share on other sites

Seems i'm in a similar boat with a user above, but not having any luck.

Here's the error I get:

Thanks for your help/any time you can spare-

P.s. Mech Jeb has improved the efficiency of my space program 100%!

That is from ZERO to 100% lol

> dofile("something")

ParserException: Code has syntax errors:

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse 'nil' of NilLiteral.

Line 1, Col 2 '.': Failed to parse Text of BoolLiteral.

Line 1, Col 2 '.': Failed to parse '0'...'9' of Digit.

Line 1, Col 2 '.': Failed to parse Name of VariableArg.

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse firstTerm of OperatorExpr.

Line 1, Col 2 '.': Failed to parse 'nil' of NilLiteral.

Line 1, Col 2 '.': Failed to parse Text of BoolLiteral.

Line 1, Col 2 '.': Failed to parse '0'...'9' of Digit.

Line 1, Col 2 '.': Failed to parse Name of VariableArg.

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse Expr of ExprStmt.

Line 1, Col 2 '.': Failed to parse remaining input.

Link to comment
Share on other sites

Seems i'm in a similar boat with a user above, but not having any luck.

Here's the error I get:

Thanks for your help/any time you can spare-

P.s. Mech Jeb has improved the efficiency of my space program 100%!

That is from ZERO to 100% lol

> dofile("something")

ParserException: Code has syntax errors:

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse 'nil' of NilLiteral.

Line 1, Col 2 '.': Failed to parse Text of BoolLiteral.

Line 1, Col 2 '.': Failed to parse '0'...'9' of Digit.

Line 1, Col 2 '.': Failed to parse Name of VariableArg.

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse firstTerm of OperatorExpr.

Line 1, Col 2 '.': Failed to parse 'nil' of NilLiteral.

Line 1, Col 2 '.': Failed to parse Text of BoolLiteral.

Line 1, Col 2 '.': Failed to parse '0'...'9' of Digit.

Line 1, Col 2 '.': Failed to parse Name of VariableArg.

Line 1, Col 2 '.': Failed to parse Letter of Name.

Line 1, Col 2 '.': Failed to parse Name of VarName.

Line 1, Col 2 '.': Failed to parse Expr of ExprStmt.

Line 1, Col 2 '.': Failed to parse remaining input.

post your script, without it your error is meaningless. also you can try to debug it yourself by removing chunks of your code, once you no longer have the error you'll know exactly where the error is in your script.

Link to comment
Share on other sites

pcall seems to cause "Coroutine exception: IndexOutOfRangeException - Array index is out of range."

i was hoping to use it to get around the annoying synchronization error =/

edit: no wait i figured it out, apparently using already locally declared variables to get multiple values from a function throws that error

example:

function FunTest()

return true, "This is fun!"

end

local Done = false

local R = "This is not fun"

Done, R = FunTest() --<---craps out error

but what works is:

function FunTest()

return true, "This is fun!"

end

local Done, R = FunTest() --<---for some reason good to go!

Edited by khmnc
Link to comment
Share on other sites

For any one having problems running Autom8 scripts.

Open folder KSP\plugindata\mumechlib.

Make sure file is yourfilename.lua, it has to be an lua file. If you don't see the extension (default for Windows) change that in Windows "folder options".

From the KSP launch pad type <font color="blue">dofile("yourfilename")</font> and 'Enter' in the Autom8 control line. Quotes and parentheses are required.

Hopefully you will get a usage statement, but it depends on the script. The usage statement "should" show you exactly what to enter.

<font color="Orange">What you enter and the order in which you enter it is </font><font color="Red">critical</font>.

Link to comment
Share on other sites

So how do I do the log function in an autom8 script so I can do some dV maths? I need to do

a * log(b/c)

Thx.

Here's mine so far - they'll be in SimpleOrbitalMechanics 0.002 - 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/

That said, math is math, and is unprotectable, as are the lua calls :).


function calcSomDeltaVFromIspTsmTem(Isp, TotalStartingMass, TotalEndingMass)
-- Isp is the Specific Impulse in seconds
-- TotalStartingMass is the total mass before the burn, including fuel - units must be the same as TotalEndingMass
-- TotalEndingMass is the total mass after the burn, including remaining fuel - units must be the same as TotalStartingMass
-- returns Delta-V in meters per second.
--[[ ex:
print(calcSomDeltaVFromIspTsmTem(390,15,10))
]]
-- reference is Tsiolkovsky rocket equation https://en.wikipedia.org/wiki/Rocket_equation
-- Total Delta-V = Isp * g * ln(TotalMass/DryMass)
return Isp * globalg * math.log(TotalStartingMass/TotalEndingMass)
end


function calcSomIspFromTsmTemDv(TotalStartingMass, TotalEndingMass, DeltaV)
-- TotalStartingMass is the total mass before the burn, including fuel - units must be the same as TotalEndingMass
-- TotalEndingMass is the total mass after the burn, including remaining fuel - units must be the same as TotalStartingMass
-- returns Isp, the Specific Impulse in seconds
--[[ ex:
print(calcSomIspFromTsmTemDv(15,10,1550))
]]
-- reference is Tsiolkovsky rocket equation https://en.wikipedia.org/wiki/Rocket_equation
-- Total Delta-V = Isp * g * ln(TotalMass/DryMass)
return DeltaV/(globalg * math.log(TotalStartingMass/TotalEndingMass))
end

Link to comment
Share on other sites

I had a look a your lua and thught id try a different way. Its not a full solution and not a better solution, just a different solution. Ill post shortly. :)

Edit:

function dvleftdriver(fuelleft, ve)
massstart = vessel.mass
fueldensity = 0.005
fuelmass = fueldensity * fuelleft
massend = massstart - fuelmass
dv = ve * math.log(massstart/massend)
print ("Craft currently has "..dv.." delta V left")
print "autom8 complete"
end

You need to work out fuel left (right click tanks in space, and you need to look up the exhaust velocity of the current engine. It works out the before/after mass by reading vessel.mass and assuming a fuel density of 0.005 units.

Only accurate in space, only for one engine and one rocket. * sad face *

From humble beginnings, great things can grow ...

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...