Jump to content

Release KontrolSystem2 (0.4.2)


Untoldwind

Recommended Posts

14 hours ago, starspy said:

Just want to add that this is amazing -- I can't see myself playing KSP2 without some form of mechjeb replacement, and it looks like this has all the building blocks.

From some field testing everything worked great (for the most part). Was able to successfully plot an intercept with Duna and visit both itself and the moon.

Desperately needed are...

1. Choice of either AP or PE or [in x time] for circularization script
2. Better interception (between two satelites, return from a moon, transfer to a moon, )
3. A "match planes with target" script
4. Docking autopilot

Incidentally, Flight Plan does most those things except for docking, plus more. It's built on top of a core of MJ code that's been adapted to work in KSP2, and has most of what you'd find in the MechJeb Maneuver Planner window.. One major thing Flight Plan doesn't do though is scripting - which obviously KS2 excels at. That said, FP methods can be called as an API, which makes me wonder... Could KS2 call FP and thus bring some of this requested capability into a scripting environment?

Link to comment
Share on other sites

Looking to get into this over the coming months as it is really impressive and I think will allow me to leverage some what automated flights so I can capture better video for my YT channel (gotta get the clean no HUD experience). I have just a couple of questions:

  1. In this vain of making better KSP 2 videos, is there any plans to implement a data streaming API for use outside of the game, say via a controller display or other application to visualize/report the data? Think being able to remove the HUD and recreate it either on a physical piece of hardware or a window outside of the main game one.
  2. I'm not a great programmer, so is there currently any tutorials on coding for this TO2 language?
    1. Sub note, is there a good starting point for this language for those just getting started assuming there are no walk through tutorials?
  3. Is the slow down in KSP 2 patch releases going to help in the KS2 development or hinder it?
  4. What are some hot development items coming soon to the next couple of releases?

Thanks for all that you are doing @Untoldwind

Link to comment
Share on other sites

On 5/4/2023 at 12:55 AM, schlosrat said:

That said, FP methods can be called as an API, which makes me wonder... Could KS2 call FP and thus bring some of this requested capability into a scripting environment?

I release  0.3.6 and 0.4.0.2 (pre-release) which has a binding for FlightPlan
https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.3.6
https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.4.0.2

Short example to test it out:

use { Vessel } from ksp::vessel
use { flight_plan } from ksp::addons
use { CONSOLE } from ksp::console
use { current_time } from ksp::game

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    const fp = flight_plan().ok_or("Flight plan not available")?

    CONSOLE.print_line("FP: Version " + fp.version)

    fp.circularize(current_time() + 300)
}

... probably needs a bit of polish, but this could serve as a template how to add optional dependencies.

Link to comment
Share on other sites

20 hours ago, Beyond_Earth_Orbit said:
  1. In this vain of making better KSP 2 videos, is there any plans to implement a data streaming API for use outside of the game, say via a controller display or other application to visualize/report the data? Think being able to remove the HUD and recreate it either on a physical piece of hardware or a window outside of the main game one.
  2. I'm not a great programmer, so is there currently any tutorials on coding for this TO2 language?
    1. Sub note, is there a good starting point for this language for those just getting started assuming there are no walk through tutorials?
  3. Is the slow down in KSP 2 patch releases going to help in the KS2 development or hinder it?
  4. What are some hot development items coming soon to the next couple of releases?

Ad 1:

I still have to wrap around my head about that one. The technical side mostly straight forward, the problem though is that either the plugin has to open a listening port for that or connect to some other network service and I'm not sure about the policies for mods from the side of the game developers are in this regard. (You may remember that kOS had a lengthy confirmation dialog for this to conform to the policies in KSP1 ... and this kind of thing can mess with the networking for multiplayer big time).

My current plan is to do this in a separate mod that can be installed in addition to KontrolSystem2 ... so if that one gets banded for a breach of policy (or something) it will not jeopardize the entire project. This would also be a nice opportunity to add something of an "official" API for the mod for others to use. 

Ad 2:

I'm currently working on improving the VSCode plugin to give more detailed (and direct) feedback to write scripts, this should help with getting started. As for direct tutorial videos, I'm not aware of any (it's all pretty new after all).

The syntax of TO2 was mostly inspired by Rust and Typescript. The former I can not recommend to get into programming, Rust is a very complex language that requires quiet some experience to get used to ... and some extra time to actually appreciate it. Typescript on the other hand might be a good starting point and its pretty useful a more an more web-projects are using it- There should be plenty of videos around to get started with that one.

If you are entirely new to programming though ... that is still a tough one. I probably would start with something like golang or python, which both have a rather simple syntax. Personally I started with Basic and Pascal ... but that was a long long time ago ;)

Ad 3:

So far we only had 2 patches, the first one had no compatibility issue whatsoever, the second just a minor one that I was able to fix in 5 minutes or so.

It certainly will be different once we get a feature patch.

Ad 4:

The 0.4 pre-release is currently on probation, which allows creating your own UI. I'm still testing that one and probably make it the primary version next week. 

After that it probably will be mostly about expanding and improving on the already existing features for a while. As laid out in my answer to (1) maybe it is not the best idea to pack all the features into a single mod.

Link to comment
Share on other sites

The  Craft is the stock three man K2 Craft.  When I attempt to change the altitude frin say 100KM to 150KM that when I launch the K2, it stages on launch and the second stage takes off leaving the first stage and the four boosters on the pad.

 

Link to comment
Share on other sites

Installed latest Program V0.4.1.1. It seems to have solved the problem about not being able to enter a different Altitude other than 100KM. I was able to enter 120KM and it went to 120KM on launch.  Still see problem with burning to a circular orbit.  Orbit holds at AP (120KM) until PE reaches positive value and then AP starts to increase. Engines shut off when PE reaches 88KM. Orbit now 243KM for AP and 88KM for PE.  Using the Stock KP2 Craft.

Link to comment
Share on other sites

On 3/19/2023 at 5:08 PM, Untoldwind said:

Thank you for the offer, any help is welcome. I added something of a crazy wish-list to the "Contributing" section: https://kontrolsystem2.readthedocs.io/en/latest/contributing/things_to_improve.html ... though even that is probably incomplete ;) 

<<<SNIP>>>

Sorry it took me so long to respond. I was asked to take on a short-term consulting job. Once that is wrapped up, I will see if I can find a way ot make myself useful. 

P.S. I'm still enjoying Kontrol System 2!

Link to comment
Share on other sites

On 5/15/2023 at 10:58 PM, Jhaxxar said:

Installed latest Program V0.4.1.1. It seems to have solved the problem about not being able to enter a different Altitude other than 100KM. I was able to enter 120KM and it went to 120KM on launch.  Still see problem with burning to a circular orbit.  Orbit holds at AP (120KM) until PE reaches positive value and then AP starts to increase. Engines shut off when PE reaches 88KM. Orbit now 243KM for AP and 88KM for PE.  Using the Stock KP2 Craft.

The final circularize/exec_node part after the launch still has issues, mostly because maneuvering node calculation is done slightly different in KSP2 (especially for longer burn times). I am still wrapping around my head around that one.

In the mean time you can try tweaking the "high_turn" value as well. If you lower it to 0.6 or 0.5 the rocket will tilt sooner on ascend so that less delta-v is required for circularization.

Link to comment
Share on other sites

  • 3 weeks later...

Hi Untoldwind,

First, thanks for a fabulous job putting this together!  it's so much more practical to play with fine control of procedures!

I took a look at the to2 code and was playing around with implementing a dock routine as one of the entry points.  I see you've already bult a dock.to2 file.  when i open this in vscode, I see a couple of strange errors that I would not expect.  I'm using your 0.3 vs of to2 parsing, and the latest KSP2 update.  strange to me that .position is not a field...  here's a copy of what i see:

3ydSaFd.jpg

aOZXRA9.jpg

Please let me know if there's something I can do to help debug.

Also, i've created a match_velocities and match_inclination entry point for those functions already in your code.  please let me know if you'd like a copy.

Best,

Ruben

Link to comment
Share on other sites

I set the "high_turn" value to 0.05 and that did the trick. I was able to set an Altitude of 120.000Km and ended up with AP at 120.674Km and PE at 120.056Km. Very close to Circular Orbit.  Thank you for suggesting this.

How do I use the "Telemetry" window?

Link to comment
Share on other sites

On 6/7/2023 at 10:20 PM, Jhaxxar said:

How do I use the "Telemetry" window?

Am I assuming correctly that you too get this error when calling add_time_series() ?

>>>>> ERROR <<<<<<<<<
Module plonk::testgraphs terminated with:
Object reference not set to an instance of an object

And are using version 0.4.1.3 as I am?

If so, I'll file an issue on github. I can't even make the example code from the docs (simple-example) work.

Link to comment
Share on other sites

@Jhaxxar Have you tried to copy, paste and run the example code from the docs? Here's the link again: simple-example

Try running it with a console window opened and the telemetry window opened. If the cosine plot appears in the plot window, all's fine. If not, you'll probably get some error messages either in the console window (as I do), or in case of compiler related error messages in the mod's main window under "reboot errors".

The "telemetry" window is essentially a plotter, providing some convenient features like autoscaling and JSON export of its data. For each plot you'll have to create a TimeSeries Object by callingthe add_time_series function. Once you've got the TimeSeries Object, you provide your datapoints by calling the object's add_data function.

At least that's what the example programs do. But currently it's broken in version 0.4.1.3, at least on my side - for the error message see my last post.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry, I was on vacation for a bit. I will try to catch up over the weekend.

In the meantime I release version 0.4.2 (https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.4.2) which should be compatible with 0.1.3.0

Please note: For the menu item to appear it is also necessary to update SpaceWarp to >= 1.3.0 (which in turn now has a dependency to UitkForKsp2)

Link to comment
Share on other sites

On 6/4/2023 at 6:34 PM, Rubenio said:

Hi Untoldwind,

First, thanks for a fabulous job putting this together!  it's so much more practical to play with fine control of procedures!

I took a look at the to2 code and was playing around with implementing a dock routine as one of the entry points.  I see you've already bult a dock.to2 file.  when i open this in vscode, I see a couple of strange errors that I would not expect.  I'm using your 0.3 vs of to2 parsing, and the latest KSP2 update.  strange to me that .position is not a field...  here's a copy of what i see:

 

Please try out the 0.0.7 (pure coincidence) version of the vscode extension: https://github.com/untoldwind/KontrolSystem2/releases/download/v0.4.2/to2-syntax-0.0.7.vsix
All the versions before that had multiple issues concerning type-inference.

 

On 6/13/2023 at 8:40 PM, Jhaxxar said:

The window comes up but is blank. Is there a module I need to add to my craft to get it to transmit Telemetry?

Initially the window should have two section (both empty). When you collect data in one of your script (e.g. run the simple-example once) some time-series should appear on the right side that you can select.
The general idea is that you should be able to define your own telemetry data you need to solve a specific problem.
... though it actually might be a good idea to have some predefined data collectors (like height, velocity, thrust, weight etc.) that you can just activate in UI. I will put it in the wishlist ;)

Link to comment
Share on other sites

Hi Untoldwind,

First, amazing work with the plugin. It's awesome to have a programmable framework for KSP2. It's when it runs it is very stable and I have a fully automated launch to low Mun orbit working.

That said, at this point I am a little stuck.

My main issue is that more and more frequently KS2 gets stuck on rebooting. The "Rebooting" button is greyed out, no entry points, no errors, indicator light is green. Game works normally, but KS2 can't be used. Restarting KSP2 used to reliably fix the issue. But I now have a 50% chance to land in this frozen state when I start the game and it usually happens again after a few minutes. It's not main memory, I have about 20GB available. Is there any way to root-cause what is causing the reboot to freeze (short of a C# debugger)?

My second issue is that sometimes I get very opaque compiler errors. The error message is something like "invalid stack", with no file or line number given. Any guidance on how to debug those?
Codebase is on GitHub here if it helps. Current checkin (9b26c6f)  will *NOT* boot successfully, but it does trigger freeze bug.

  https://github.com/appenz/kerbal2

And again thanks for making this great mod!

   Guido

Link to comment
Share on other sites

  • 2 weeks later...

There seems to be a conflict with spacewarp versions. Talked with the dev and this is the log and his reply:
[Error : BepInEx] Could not load [KontrolSystem2 0.4.2.1] because it has missing dependencies: com.github.x606.spacewarp (v1.3.0.1 or newer)
 

the chat:  https://ibb.co/1Tc2Px0

this is also downloaded from CKAN

Edited by Gargamel
Fixed illegible formatting
Link to comment
Share on other sites

Hey Untoldwind, 

I think it would be easier to discuss and help improve this mod if we have a discord server where we can discuss changes, bugs, and showcase what we made. 
 

Here is the link: https://discord.gg/wMpSergFKc

Join if you want to showcase your projects/talk about the mod. Hopefully Untoldwind joins so we can more efficiently give suggestions and report bugs.

Link to comment
Share on other sites

I made a new install and put Space_Warp_BepInEx-1.3.0.3 in KSP2 V0.1.3.1.  having problem getting it to fire up.  I did what I also did for a new install. First I ran the new version of KSP2, to make sure it ran. Then I installed current BepInEx and started KSP2. Let it go all the way to VAB and then did a Shutdown. I added my Mods and then refired the KSP2. When it gets to the Title Screen, there is NO MOD folder listing.

Edited by Jhaxxar
Link to comment
Share on other sites

On 6/25/2023 at 5:49 PM, appenz said:

My main issue is that more and more frequently KS2 gets stuck on rebooting. The "Rebooting" button is greyed out, no entry points, no errors, indicator light is green. Game works normally, but KS2 can't be used. Restarting KSP2 used to reliably fix the issue. But I now have a 50% chance to land in this frozen state when I start the game and it usually happens again after a few minutes. It's not main memory, I have about 20GB available. Is there any way to root-cause what is causing the reboot to freeze (short of a C# debugger)?

My second issue is that sometimes I get very opaque compiler errors. The error message is something like "invalid stack", with no file or line number given. Any guidance on how to debug those?
Codebase is on GitHub here if it helps. Current checkin (9b26c6f)  will *NOT* boot successfully, but it does trigger freeze bug.

  https://github.com/appenz/kerbal2

And again thanks for making this great mod!

That error indicates might indicate a stack overflow, which can indeed freeze the game engine. I will take a look if that can reproduce that.
 

On 7/6/2023 at 6:49 AM, Hydranet said:

Here is the link: https://discord.gg/wMpSergFKc

Join if you want to showcase your projects/talk about the mod. Hopefully Untoldwind joins so we can more efficiently give suggestions and report bugs.

I will join, but will not be online that often.
Problem is that I already have to use multiple messenger apps for work and that is only so much that fits on a screen ;)

Link to comment
Share on other sites

On 7/8/2023 at 2:14 AM, Jhaxxar said:

I made a new install and put Space_Warp_BepInEx-1.3.0.3 in KSP2 V0.1.3.1.  having problem getting it to fire up.  I did what I also did for a new install. First I ran the new version of KSP2, to make sure it ran. Then I installed current BepInEx and started KSP2. Let it go all the way to VAB and then did a Shutdown. I added my Mods and then refired the KSP2. When it gets to the Title Screen, there is NO MOD folder listing.

There have been quite some updates to SpaceWarp in the last weeks. I did a reinstall with these versions (from SpaceDock):

SpaceWrap_BepInEx 1.3.1

UITK_for_KSP2 1.4.1 (required by SpaceWrap)

KontrolSystem2 0.4.2.1

This works for me.

Special note for linux players: The zip file of UITK_for_KSP2 has incorrect access flags of its assets folder, so you have to do a "chmod 755 BepInEx/plugins/UitkForKsp2/assets"

Link to comment
Share on other sites

On 6/25/2023 at 5:49 PM, appenz said:

My second issue is that sometimes I get very opaque compiler errors. The error message is something like "invalid stack", with no file or line number given. Any guidance on how to debug those?
Codebase is on GitHub here if it helps. Current checkin (9b26c6f)  will *NOT* boot successfully, but it does trigger freeze bug.

  https://github.com/appenz/kerbal2

This was a tricky one.
The compilation of the to2 scripts is done in a background thread to interfere with the game-loop as little as possible. Turns out  that the BeInEx logger is not thread-safe ... or more specific, the log-console handler of spacewarp might create a dead-lock if logs are created outside the main thread.

Anyway: This should be now fixed with the 0.4.2.2 version.

PS: Flipping these two lines will fix the compilation errors: https://github.com/appenz/kerbal2/blob/9b26c6f49f75098993e32aca6e180aec0a3b53b7/glib/landing.to2#L38-L39

Link to comment
Share on other sites

Hey,

I really enjoyed kOS in KSP 1 and I was all excited to lern that this is the successor for KSP 2. Thank you for all the work and dedication. Since I was new to programming under kOS I´ve learned it a little bit and could do what I needed, that was lots of fun. But for now, this is a - to me complete new language and due to the fact, that english is not my first language it is rather hard for me to find an entrypoint to identify the things I am looking for in the exsisting scripts. I´ve read the comments and I understand that there was a request already but I really would be thankfull to get a starter, so I could do the rest better on my own. I am aware that there are already existing scripts and they are great, but it feels a bit like cheating to me. So far I can turn on the lights on the launchpad... and I really tried weeks in all the free time I could, but like I said I really would appreciate, well a small script to the few things I wanna do. I may give you the steps and if there is somebody to help me out, thanks in advance.

What dependencies do I need to call (use) It tried   use vessel.... and then the stageing line, did not work.

then - simple - STAGE

then wait till speed (this I have figured out)

then steer to east to like 10° for, lets say 5 seconds, then lock to prograde how do I do that?

can I wait for an altitude and it still stears?

then call autostage

then call circularize

The thing is, I have read an article that says it is in real space flight efficient to lock to a curtain degree for a number of seconds, so I want to do a superefficient

ascending profile with that.

May you can help me.

Thank you in advance

 

 

 

 

 

Link to comment
Share on other sites

A good starting point are the scripts in the `BepInEx/plugins/KontrolSystem2/to2` folder.
E.g. the minimal script to launch a rocket is `BepInEx/plugins/KontrolSystem2/to2/launch_rocket.to2` which just looks like this:

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { atmo_launch } from std::atmo
 
pub fn main_flight(vessel: Vessel, target_apoapsis: int = 100000, low_turn: float = 0.007, high_turn: float = 0.7) -> Result<Unit, string> = {
  atmo_launch(vessel, target_apoapsis, 90, low_turn, high_turn)?
}

`atmo_launch` itself is just a function that can be found in the `BepInEx/plugins/KontrolSystem2/to2/std/atmo.to2` file. You can just tweak those in place or copy them over to the to2Local folder to create your own variants.

As long as the `use` does not start with `ksp::` or `core::` it usually refers to another to2-file in the to2 or to2Local folder. The `ksp::` and `core::` packages are build-in and are documented here: https://kontrolsystem2.readthedocs.io/en/latest/reference/index.html

But you are right, there probably should be a more structured getting started guide. 

 

Link to comment
Share on other sites

On 7/13/2023 at 6:22 PM, Untoldwind said:

A good starting point are the scripts in the `BepInEx/plugins/KontrolSystem2/to2` folder.
E.g. the minimal script to launch a rocket is `BepInEx/plugins/KontrolSystem2/to2/launch_rocket.to2` which just looks like this:

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { atmo_launch } from std::atmo
 
pub fn main_flight(vessel: Vessel, target_apoapsis: int = 100000, low_turn: float = 0.007, high_turn: float = 0.7) -> Result<Unit, string> = {
  atmo_launch(vessel, target_apoapsis, 90, low_turn, high_turn)?
}

`atmo_launch` itself is just a function that can be found in the `BepInEx/plugins/KontrolSystem2/to2/std/atmo.to2` file. You can just tweak those in place or copy them over to the to2Local folder to create your own variants.

As long as the `use` does not start with `ksp::` or `core::` it usually refers to another to2-file in the to2 or to2Local folder. The `ksp::` and `core::` packages are build-in and are documented here: https://kontrolsystem2.readthedocs.io/en/latest/reference/index.html

But you are right, there probably should be a more structured getting started guide. 

 

Thank you very much, for your response and your Explenation. And thank you for all the work you have done :-)

Link to comment
Share on other sites

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