Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

6 hours ago, kcs123 said:

What you mean by that ? IIRC, gravity turn mod is plugin and all calculations/loging are done trough plugin. So, I'm not sure what you mean by starting gravity turn mod with kOS. Also, I'm not sure what would be difference, starting gravity turn mod by kOS or by yourself trough available mod GUI.

On the other hand, it is quite possible to write your own kOS scripts that would make same calculations as gravity turn does. Collect some data and write in log files, recalculate / create more optimized ascent slope based on loged data on second launch, etc. More fun and more stuff you will learn trough pure kOS aproach.

What I mean was that I wanted to turn off the gui and have a script hit start for me so I can record

6 hours ago, kcs123 said:

What you mean by that ? IIRC, gravity turn mod is plugin and all calculations/loging are done trough plugin. So, I'm not sure what you mean by starting gravity turn mod with kOS. Also, I'm not sure what would be difference, starting gravity turn mod by kOS or by yourself trough available mod GUI.

On the other hand, it is quite possible to write your own kOS scripts that would make same calculations as gravity turn does. Collect some data and write in log files, recalculate / create more optimized ascent slope based on loged data on second launch, etc. More fun and more stuff you will learn trough pure kOS aproach.

What I mean was that I wanted to turn off the gui and have a script hit start for me so I can record

Link to comment
Share on other sites

3 hours ago, Nerfclasher said:

What I mean was that I wanted to turn off the gui and have a script hit start for me so I can record

I don't think it is possible. kOS allow you to read and set properties of any part that is exposed trough right click on craft part.

Exceptions from those are mods listed on addon reference page. Unless something similar is created for gravity turn mod, I don't think it is possible. Some of mod developer have yet to confirm this, though. I don't think that is within scope of kOS development, but again, people that are active in development have to confirm this.

Link to comment
Share on other sites

2 hours ago, sebseb7 said:

any idea of how to log cumulative resource consumption/production of every part?

I have yet to create some advanced script that watch over resources and do something with it. However, first stop should be Aggregate Resource documentation - how to go trough craft part list and check amount of resources available.

From provided example, should be simple enough to add same type of resource to variable instead of printing. Once you end loop trough all craft parts you got desired cumulative for each resource type.

If you put some kOS tags on craft part, you might not need to loop trough all craft parts, only trough parts with specific kOS tag names - making script much faster and more efficient. Drawback from it is that it will work only with specific craft designs with such tag names.

Link to comment
Share on other sites

1 hour ago, kcs123 said:

I have yet to create some advanced script that watch over resources and do something with it. However, first stop should be Aggregate Resource documentation - how to go trough craft part list and check amount of resources available.

From provided example, should be simple enough to add same type of resource to variable instead of printing. Once you end loop trough all craft parts you got desired cumulative for each resource type.

If you put some kOS tags on craft part, you might not need to loop trough all craft parts, only trough parts with specific kOS tag names - making script much faster and more efficient. Drawback from it is that it will work only with specific craft designs with such tag names.

I know the documentation. I know how the read the resources available. But parts don't show their consumption rate. 

Link to comment
Share on other sites

I'm having some problems with my script, maybe someone can help. Maybe those are bugs in kOS but I might be doing something wrong:

Here's the script: https://gist.github.com/anonymous/332e30e38f09be0d63ad16d43135fb06

4EtjDgP.png

The quadcopter (quadrocket?) picks up an element and places it on the base in the background to build a tower. Each element has docking ports so the whole thing doesn't fall apart.

The first problem occurs right when launching the script at line 197 where the steering vector gets locked:

wdbs6j1.png

The strange thing is that it only happens in every third attempt. In the other cases it launches fine. If I try to launch it again after this error it gives me the following error:

PmnPeGs.png

Which probably makes some sense because assigning the steering vector failed.

---

The other problem happens after the part is docked with the base right after this:

2AgOjMp.png

After docking, the ship unlocks throttle and sets it to 0. It just sits there while the program is still executing. It looks like the problem occurs after line 244 since that's the last thing it prints.

JtKr9ai.png

Could it have to do with the automatic camera adjustment or switch to a different vessel right after docking? Or is it because there are two docking ports?

Let me know if you need some more information, any kind of help is appreciated.

Edited by EmbersArc
Link to comment
Share on other sites

15 hours ago, EmbersArc said:

Let me know if you need some more information, any kind of help is appreciated.

With the kind of error you're getting, the full error log file would be useful.  Usually users shouldn't see the "null reference" kinds of errors.  It might mean something is wrong with kOS itself.

 

Link to comment
Share on other sites

28 minutes ago, Steven Mading said:

With the kind of error you're getting, the full error log file would be useful.  Usually users shouldn't see the "null reference" kinds of errors.  It might mean something is wrong with kOS itself.

Okay here's the log: https://gist.github.com/anonymous/ac4a61dd54b9715519a3f1753b423d2e

The first error (nullref on lauch) is from lines 4461-4696 and the second error (docking) from lines 4236-4458. 0-4235 is KSP launch to vessel load.

Link to comment
Share on other sites

@hvacengi

I get a regular KOS NRE on a highly modded install using KOS version 1.0.3...

EDIT: Well, seems more to be related to the blizzy toolbar. OK. However, would be cool to get it out of the log anyways. :)

EDIT2: Seems to happen on game load, even before selecting a game/career.

 

Spoiler

170109T213123.134 [INFO] [ScienceChecklist.Logger.WriteMessage] [1/9/2017 9:31:23 PM [x] Science!]: <Trace> (ScienceChecklistAddon) - Load
170109T213123.136 [INFO] [ScienceChecklist.Logger.WriteMessage] [1/9/2017 9:31:23 PM [x] Science!]: <Trace> (ScienceChecklistAddon) - Ui is hidden in this scene
170109T213123.140 [INFO] [KSP.UI.Screens.ApplicationLauncher.ScaleModList] ScaleModList: listSize 41 maxListSize 0
170109T213123.143 [INFO] [KSP.UI.Screens.ApplicationLauncher.ScaleModList] ScaleModList: listSize 41 maxListSize 0
170109T213123.145 [INFO] [QuickSearch.QuickSearch.Log] QuickSearch(QStockToolbar)[3.11]: AppLauncherReady
170109T213123.146 [INFO] [QuickGoTo.QuickGoTo.Log] QuickGoTo(QStockToolbar)[1.31]: AppLauncherReady
170109T213123.148 [INFO] [KSP.UI.Screens.ApplicationLauncher.ScaleModList] ScaleModList: listSize 41 maxListSize 0
170109T213123.181 [ERROR] [EventVoid.Fire] Exception handling event onGUIApplicationLauncherReady in class KOSToolbarWindow:System.NullReferenceException: Object reference not set to an instance of an object
  at kOS.Module.kOSCustomParameters.get_Instance () [0x00000] in <filename unknown>:0 
  at kOS.Suffixed.Config.get_UseBlizzyToolbarOnly () [0x00000] in <filename unknown>:0 
  at kOS.Screen.KOSToolbarWindow.AddButton () [0x00000] in <filename unknown>:0 
  at EventVoid.Fire () [0x00000] in <filename unknown>:0 
170109T213123.183 [EXCEPTION] [kOS.Module.kOSCustomParameters.get_Instance] NullReferenceException: Object reference not set to an instance of an object
   at kOS.Module.kOSCustomParameters.get_Instance ()
   at kOS.Suffixed.Config.get_UseBlizzyToolbarOnly ()
   at kOS.Screen.KOSToolbarWindow.AddButton ()
   at EventVoid.Fire ()
   at UnityEngine.Debug:LogException(Exception)
   at EventVoid:Fire()
   at KSP.UI.Screens.ApplicationLauncher:StartupSequence()
   at KSP.UI.Screens.ApplicationLauncher:Awake()
   at UnityEngine.Object:Instantiate(Canvas)
   at KSP.UI.UIMasterController:AddCanvas(Canvas, UICanvasPrefab, Boolean)
   at KSP.UI.Screens.UIAppSpawner:OnLevelLoaded(GameScenes)
   at EventData`1:Fire(GameScenes)
   at <FireLoadedEvent>c__Iterator68:MoveNext()
   at UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
170109T213123.187 [INFO] [KSP.UI.Screens.ApplicationLauncher.ScaleModList] ScaleModList: listSize 41 maxListSize 0
170109T213123.189 [INFO] [KSP.UI.Screens.UIApp.Awake] [UiApp] Awake: MessageSystem
170109T213123.190 [INFO] [KSP.UI.Screens.ApplicationLauncher.OnSceneLoadedGUIReady] [ApplicationLauncher] OnSceneLoadedGUIReady: scene MAINMENU ShouldBeVisible() True ShouldBeOnTop() True iIsPositionedAtTop True
170109T213123.192 [INFO] [ScienceChecklist.Logger.WriteMessage] [1/9/2017 9:31:23 PM [x] Science!]: <Trace> (ScienceChecklistAddon) - Load
170109T213123.192 [INFO] [ScienceChecklist.Logger.WriteMessage] [1/9/2017 9:31:23 PM [x] Science!]: <Trace> (ScienceChecklistAddon) - Ui is hidden in this scene
170109T213123.193 [INFO] [QuickSearch.QuickSearch.Log] QuickSearch(QStockToolbar)[3.11]: AppLauncherReady
170109T213123.194 [INFO] [QuickGoTo.QuickGoTo.Log] QuickGoTo(QStockToolbar)[1.31]: AppLauncherReady
170109T213123.195 [ERROR] [EventVoid.Fire] Exception handling event onGUIApplicationLauncherReady in class KOSToolbarWindow:System.NullReferenceException: Object reference not set to an instance of an object
  at kOS.Module.kOSCustomParameters.get_Instance () [0x00000] in <filename unknown>:0 
  at kOS.Suffixed.Config.get_UseBlizzyToolbarOnly () [0x00000] in <filename unknown>:0 
  at kOS.Screen.KOSToolbarWindow.AddButton () [0x00000] in <filename unknown>:0 
  at EventVoid.Fire () [0x00000] in <filename unknown>:0 
170109T213123.196 [EXCEPTION] [kOS.Module.kOSCustomParameters.get_Instance] NullReferenceException: Object reference not set to an instance of an object
   at kOS.Module.kOSCustomParameters.get_Instance ()
   at kOS.Suffixed.Config.get_UseBlizzyToolbarOnly ()
   at kOS.Screen.KOSToolbarWindow.AddButton ()
   at EventVoid.Fire ()
   at UnityEngine.Debug:LogException(Exception)
   at EventVoid:Fire()
   at KSP.UI.Screens.ApplicationLauncher:StartupSequence()
   at KSP.UI.Screens.ApplicationLauncher:OnSceneLoadedGUIReady(GameScenes)
   at EventData`1:Fire(GameScenes)
   at <FireLoadedEventGUIReady>c__Iterator69:MoveNext()
   at UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
170109T213123.198 [INFO] [QuickSearch.QuickSearch.Log] QuickSearch(QStockToolbar)[3.11]: Destroy
170109T213123.199 [INFO] [QuickSearch.QuickSearch.Log] QuickSearch(QStockToolbar)[3.11]: AppLauncherDestroyed
170109T213123.225 [INFO] [JSI.JUtil.LogInfo] [RPMShaderLoader]: Found 8 RPM shaders and 7 fonts.
170109T213123.226 [INFO] [JSI.JUtil.LogInfo] [RPMShaderLoader]: Adding RPM-included font digital-7 (italic) / 32
170109T213123.227 [INFO] [JSI.JUtil.LogInfo] [RPMShaderLoader]: Adding RPM-included font digital-7 (mono italic) / 32
170109T213123.227 [INFO] [JSI.JUtil.LogInfo] [RPMShaderLoader]: Adding RPM-included font digital-7 (mono) / 32

 

Edited by Jebs_SY
Link to comment
Share on other sites

42 minutes ago, tseitsei89 said:

Noob question as I just started learning this.

How can I get the thrust and mass of the next stage of my vessel?

I need it because I want to calculate my burn time for a node accurately even if I have to stage mid burn...

This is very difficult for multiple reasons.

You can't get the thrust of an engine that isn't running. My workaround is to activate the engine briefly, note the thrust, then shut it down again, which can't be done for SRBs (and is a bad idea in Realism Overhaul where engines have limited activations). A full solution for all engine types would need changes to kOS to make these values available on inactive engines, or we could add a big look-up function to our code that has the thrust and ISP of each engine model... yuk.

Dividing the craft into stages typivally requires walking the parts tree and making assumptions about where the root part is. Each part has an associated "stage number", but from memory this can't be trusted as KSP assigns it when parts are added, but doesn't change it when staging is rearranged. If that did work, it'd make things much easier. To avoid writing something massive, I have a very cut-down version that guesses what the next engine is (assuming there is just one). That's based on checking there is a decoupler attached below each engine, and picking the engine whose decoupler has the lowest total mass, including the mass of child parts (and their children and so on). That total mass can be subtracted from the current MASS to get the wet mass of the next stage. We can also then determine the details of the next engine.

I have a library and some documentation I can link to if you're interested in seeing my approach.

Link to comment
Share on other sites

5 minutes ago, ElWanderer said:

Each part has an associated "stage number", but from memory this can't be trusted as KSP assigns it when parts are added, but doesn't change it when staging is rearranged.

I can verify this memory.  I was recently trying to do “smart staging”, where the code would check to see if there were launch clamps and then activate first-stage engines appropriately.  When I unleashed it on rockets I’d built and rebuilt, everything went insane, for exactly this reason.  I was amazed to discover that the parts shown in the staging UI didn’t actually pick up the stage numbers shown there.

Quote

I have a library and some documentation I can link to if you're interested in seeing my approach.

I certainly am!

Link to comment
Share on other sites

Two more things I noticed:

DockingPort:STATE doesn't return "PreAttached" when it's close to another port. Instead it returns "acquire".

LIST CommandLIST ListKeyword FROM SomeVessel IN YourVariable. It always freaks out about the "from" when I write "LIST DockingPorts FROM Vessel("somevesselname") IN somelist".

Edited by EmbersArc
Link to comment
Share on other sites

using kos 1.0.2gui and 1.0.3:

example:

on ag1 {
   if homeconnection:isconnected update_file_from_archive("file").
   run "file".
}
wait until false.


it always executes a cache version of the first file. Even if I precompile the file and execute the ksm file, it gets cached and the seems to cache stay valid when the file content changes.

Any hints?

Edited by sebseb7
Link to comment
Share on other sites

6 hours ago, meyerweb said:

I can verify this memory.  I was recently trying to do “smart staging”, where the code would check to see if there were launch clamps and then activate first-stage engines appropriately.  When I unleashed it on rockets I’d built and rebuilt, everything went insane, for exactly this reason.  I was amazed to discover that the parts shown in the staging UI didn’t actually pick up the stage numbers shown there.

I certainly am!

Ah thanks for confirming that.

My lib_dv.ks file is here: https://github.com/ElWanderer/kOS_scripts/blob/master/scripts/lib_dv.ks and documented here: https://github.com/ElWanderer/kOS_scripts/blob/master/documentation/lib_dv_readme.md

The documentation is separate to keep the script file size down...

It's for delta-v calculation (of the current stage only) and burn time calculation (current stage + next stage if necessary). It relies on one function from my common library, pOut(), which is a wrapper around PRINT (that adds in Mission Elapsed Time and logs the whole thing to a log file if one has been defined). That's easily replaced and I don't think the library needs anything else from my repository.

That version was written against KSP v1.1.3 / kOS v1.0.1. I've been having "fun" with STAGE:LIQUIDFUEL and STAGE:OXIDIZER since the v1.2.2 / v1.0.3 upgrade, so there is a draft updated version here: https://github.com/ElWanderer/kOS_scripts/blob/v1.1_draft_changes/scripts/lib_dv.ks. It uses STAGE:RESOURCESLEX and if that doesn't find any fuel, tries SHIP:RESOURCESLEX instead.

Edit: except SHIP:RESOURCESLEX doesn't exist. D'oh.

Edited by ElWanderer
Link to comment
Share on other sites

5 hours ago, ElWanderer said:

This is very difficult for multiple reasons.

You can't get the thrust of an engine that isn't running. My workaround is to activate the engine briefly, note the thrust, then shut it down again, which can't be done for SRBs (and is a bad idea in Realism Overhaul where engines have limited activations). A full solution for all engine types would need changes to kOS to make these values available on inactive engines, or we could add a big look-up function to our code that has the thrust and ISP of each engine model... yuk.

Dividing the craft into stages typivally requires walking the parts tree and making assumptions about where the root part is. Each part has an associated "stage number", but from memory this can't be trusted as KSP assigns it when parts are added, but doesn't change it when staging is rearranged. If that did work, it'd make things much easier. To avoid writing something massive, I have a very cut-down version that guesses what the next engine is (assuming there is just one). That's based on checking there is a decoupler attached below each engine, and picking the engine whose decoupler has the lowest total mass, including the mass of child parts (and their children and so on). That total mass can be subtracted from the current MASS to get the wet mass of the next stage. We can also then determine the details of the next engine.

I have a library and some documentation I can link to if you're interested in seeing my approach.

Oh too bad :/ That would have been very useful information. But please do share your library :) I'll definitely see if I can understand any of it (I'm new to kOS and quite inexperienced in coding altogether...).

Link to comment
Share on other sites

30 minutes ago, tseitsei89 said:

Oh too bad :/ That would have been very useful information. But please do share your library :) I'll definitely see if I can understand any of it (I'm new to kOS and quite inexperienced in coding altogether...).

Please see my reply to meyerweb above yours :)

Link to comment
Share on other sites

1 hour ago, sebseb7 said:

using kos 1.0.2gui and 1.0.3:

example:

on ag1 {
   if homeconnection:isconnected update_file_from_archive("file").
   run "file".
}
wait until false.


it always executes a cache version of the first file. Even if I precompile the file and execute the ksm file, it gets cached and the seems to cache stay valid when the file content changes.

Any hints?

Try using the runpath() function instead of the run command and see if it helps.

 

Link to comment
Share on other sites

2 hours ago, sebseb7 said:

it always executes a cache version of the first file. Even if I precompile the file and execute the ksm file, it gets cached and the seems to cache stay valid when the file content changes.

29 minutes ago, Steven Mading said:

Try using the runpath() function instead of the run command and see if it helps.

If you do the same thing from the interpreter it should work.  However programs that have already been run once by the program context are always run as the cached version.  Part of the reason is because calling the same program 100 times would literally load each instruction into memory 100 times.  We do not currently have a solution available for unloading a program.  The only workaround available is to re-run it with a new name (maybe copy it with a `random()` number appended to the name), or to reboot if you have a bootscript that will pick up where you left off.

9 hours ago, EmbersArc said:

The first error (nullref on lauch) is from lines 4461-4696 and the second error (docking) from lines 4236-4458. 0-4235 is KSP launch to vessel load.

On 1/9/2017 at 3:00 PM, EmbersArc said:

Let me know if you need some more information, any kind of help is appreciated.

Does this reliably happen to you every time?  I had a similar error one time (but only once) in a convoluted set of steps (dock with station in orbit, transfer to the mun, undock, try to land, crash into the surface destroying the entire lander, revert to launch) so I wasn't able to reproduce it.  The method itself that throws the error is actually pretty simple, and I thought it was already null safe.  I suspect that it is somehow related to docking (since both of our instances involved docking) but I'm not really sure how that's possible.  I only see one error in the log you linked, did I miss the first one somewhere, or are you referring to the AGExt error?  The AGExt error is in a set of error fixes that are pending for the next release (and I really need to finish making the review edits).

8 hours ago, Jebs_SY said:

EDIT: Well, seems more to be related to the blizzy toolbar. OK. However, would be cool to get it out of the log anyways. :)

That error has a fix pending to be merged: https://github.com/KSP-KOS/KOS/pull/1902

Link to comment
Share on other sites

2 minutes ago, hvacengi said:

 The only workaround available is to re-run it with a new name (maybe copy it with a `random()` number appended to the name), or to reboot if you have a bootscript that will pick up where you left off.

could not write access to a file (tocopypath, delete, etc) invalidate the compiled cache for that file?

 

Link to comment
Share on other sites

On 1/8/2017 at 9:09 AM, tseitsei89 said:

Okay I just downloaded the mod and run into a problem. Sorry if this is a noobish/already answered question

http://imgur.com/eAshqMN

As you can see from the screenshot I created a new file to test how this works.

But the problem was when I tried to write PRINT "HELLO" I noticed that my R and E keys weren't working. So just to elaborate what my problem is I tried to wrote QWERTYASD after that. And as you can see R E and S keys are not registered.

Coincidentally those happen to be the letters used for (R)eload, (S)ave and (E)xit (the buttons at the top right corner of that window. So that is somehow blocking them I believe... But I couldn't quickly find a way to make it work so I thought I would ask here if anyone has faced the same problem and/or knows how to fix it...

Are you by chance using Linux or Mac?  The game for some reason handles key presses differently between platforms.  I tested on my Windows computer because the built in editor is not often used, and it appears to work for me on the current release.  I highly recommend using an external editor instead, personally I prefer Atom.io with the kerboscript language plugin installed.

On 1/7/2017 at 10:23 AM, Nerfclasher said:

can mods like gravity turn be started using kos

On 1/8/2017 at 9:17 AM, danielboro said:

i play a lot AFK.

i plot the nav points then let my kids have the computer.

and i use mekjeb and kos as pilots. and KAC to not miss ship jumps.

i expect Nerfclasher has a similar play stile.

i cold use an option to start mods like GT from kos

no reason to reinvent the weal if i dont have to

Support for gravity turn would need to be built using an Addon.  kOS now supports 3rd party addons however, so you're welcome to write an addon to allow for controlling gravity turn.  Unfortunately we already have a pretty decent backlog of features and bugs to work on, so I wouldn't expect kOS to get built in support for this mod for a while.

Link to comment
Share on other sites

21 minutes ago, sebseb7 said:

could not write access to a file (tocopypath, delete, etc) invalidate the compiled cache for that file?

 

The issue isn't the strategy for recognizing that the cache should be invalidated, but rather the implications to the internal program structure.  When you run a program it is turned into a list of opcodes, which are then added to the existing list of "program" opcodes.  That means ever time a program is compiled and run a second time, it adds more instructions to the list.  And if we remove the old opcodes, the instruction pointers (essentially index references for the list) have to also get dynamically updated.  It's just a situation that the virtual machine was not designed to handle, and changing that would be a major undertaking.

On a more direct note, I'm not really sure what you're trying to do with section of code, but if that code were put into a boot script like below, it would work:

run "file".
on ag1 {
   if homeconnection:isconnected update_file_from_archive("file").
   reboot.
}
wait until false.

But if all you want to do is change the behavior depending on changes to that file, why couldn't you set up the script to watch for parameters in that same file (using json, or readln or the like).  That way you don't need to write a whole new file, but can instead just dictate what to do next.  In my own scripts, if I want to change "logic" (switch from a station building script to a transfer to Duna) I change the boot file for the core and reboot.  But when I'm waiting to change the behavior of an existing script, I just write the script to understand what to do based on messages, or changes in orbital parameters, or file changes.

Link to comment
Share on other sites

1 minute ago, hvacengi said:

I'm not really sure what you're trying to do with section of code

to update parts of the program while it is running. 

reboot or change filename, understood.
no free() for compiled code due to linear allocation, understood.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...