Jump to content

Release KontrolSystem2 (0.4.2)


Untoldwind

Recommended Posts

1 hour ago, Soda Popinski said:

        let lat = vessel.geocoordinates.latitude

I get an error with the last line: "Type vessel does not have a field "geocoordinates"

That would be "geo_coordinates" instead of "geocoordinates".

There is some rudimentary documentation for this: https://kontrolsystem2.readthedocs.io/en/latest/reference/ksp/vessel.html#vessel (which lists all the fields on vessel) and https://kontrolsystem2.readthedocs.io/en/latest/reference/ksp/orbit.html#geocoordinates (the fields on the GeoCoordinate object) 

Obviously a lot of descriptions are missing (... and it looks like there internal links got broken when I migrated the docs to sphinx).

And the bindings to the API are certainly not complete yet. If you are missing some vital information, please let me know.

 

Link to comment
Share on other sites

6 hours ago, Untoldwind said:

That would be "geo_coordinates" instead of "geocoordinates".

There is some rudimentary documentation for this: https://kontrolsystem2.readthedocs.io/en/latest/reference/ksp/vessel.html#vessel (which lists all the fields on vessel) and https://kontrolsystem2.readthedocs.io/en/latest/reference/ksp/orbit.html#geocoordinates (the fields on the GeoCoordinate object) 

Obviously a lot of descriptions are missing (... and it looks like there internal links got broken when I migrated the docs to sphinx).

And the bindings to the API are certainly not complete yet. If you are missing some vital information, please let me know.

 

Thanks!  That did the trick.  

As I'm terrible at manually landing (without a joystick), I plan to start adapting my kOS landing script.
Here's an old version of it running

Edit:  Can we get a subreddit for this, so I don't clutter this official thread with all my dumb questions?  I'm not stumped at truncating a string.  I can't iterate through a string like any array, like I do in Python.  Ultimately, I'm trying to truncate a float converted to a string.  I suppose I can write a work around to multiply and truncate to get the significant digits I want to display, then print it with the original float truncated, but that seems a bit clunky.

Edited by Soda Popinski
Link to comment
Share on other sites

I admit that string operations where not very high on the priority list so far ... and that few and indeed not documented (I'll take care of that on the next free minute).

In short:

float, vec2, vec3 have a ".to_string()" and ".to_fixed(decimals)" method. I.e. `a = 1.234567    a.to_fixed(2)` should result in the string "1.23".

Also strings have a ".pad_right(number)" and ".pad_left(number)" 

But I agree that this is still pretty clunky to write ... probably the easiest way would be make the C# string.Format available. I'll give that a try.

As for the subreddit. I have not been on that platform for years and actually do not really know what to look out for. But I'll gladly join and answer questions if you would provide me with a link.
As an alternative: Feel free to create issues on github. To me a misunderstand feels like a bug in the documentation ;)

Edited by Untoldwind
Link to comment
Share on other sites

On that note: 0.1.5

  • Minor adjustments to the language to make the range operators ".." a "..." more consistent
  • Null-Checks for the AutopilotAdatper (which let to a null pointer exception in some cases)
  • Added core::std package with string join and format functions

The later is based on C# String.Format, so

use { format } from core::str

format("First: {0,7:F3}, Second: {1,7:F2}, Third: {2}", (1.1234567, 12.345678, "Hallo")))

Gives: "First:   1.123, Second:   12.35, Third: Hallo"

Link to comment
Share on other sites

18 hours ago, Dunbaratu said:

It's wonderful that someone is doing this.  As the person maintaining kOS for KSP1, I felt bad that my computer is not up to being able to do KSP2 so I'm not part of the KSP2 hype so kOS for KSP2 isn't really a thing I can be working on.

(Also, I am in a job search where until I land a job it would be irresponsible for me to be shelling out the cash and free time it would take to be doing a kOS for KSP2 right now.)

There's things I'd want to do differently if I did do a kOS for KSP2 and it looks like some of those things are in the mind of the person doing this.  For one thing I didn't start the kerboscript language so when I enhanced it with lots more stuff like scoping, function calls, and delegates, it was always piecemeal one new feature at a time and therefore I sided with "keep it looking similar" rather than "do it like normal languages would do it" a lot of the time.  That led to, well, the weirdness that is kerboscript.

OP, do Kerboscript scripts generally work with your mod?

Link to comment
Share on other sites

5 hours ago, Untoldwind said:

As for the subreddit. I have not been on that platform for years and actually do not really know what to look out for. But I'll gladly join and answer questions if you would provide me with a link.

As an alternative: Feel free to create issues on github. To me a misunderstand feels like a bug in the documentation ;)

I'll go ahead and put relevant questions on GitHub, but for later, I still think reddit or maybe a dedicated help topic here, would be a good place for general programming help in KSP2 context.  I started learning kOS decades since I learned Pascal in high school, so I pretty much had to relearn how to program.  I'd since learned Python for work reasons, and kOS really helped get my programming skills up.

Anyway, doing a project involving ChatGPT, so here its answer on how to start a subreddit.

To create a new subreddit, you need to follow these steps:

  1. Sign in to your Reddit account. If you don't have an account, you can create one for free.

  2. Click on the "Create Community" button on the Reddit homepage or visit the following link: https://www.reddit.com/subreddits/create

  3. Choose a name for your subreddit. Make sure it's a name that's relevant to the topic of your subreddit and is easy to remember.

  4. Choose a topic for your subreddit. This will help people find your subreddit when they're searching for topics related to your subreddit.

  5. Choose whether your subreddit should be public or private. Public subreddits are visible to everyone on Reddit, while private subreddits are only visible to members.

 

Link to comment
Share on other sites

On 3/11/2023 at 9:13 AM, Soda Popinski said:

This is great news!  That said, I'm at a loss.  My programming "skills" are some basic Python and kOS.

I'm pretty much at a loss.  I've been trying to figure out how to display latitude and longitude.

From the Hello World example, I see how you get fields (and methods) under vessel.orbit
Using that, I tried with other fields under orbit, such as radius, and apoapsis.  I saw in vessel, in addition to orbit, there's also geocoordinates.  So I figure, I can substitute orbit with geocoordinates, and use the fields under that. 

        let pos = vessel.orbit.relative_position(ut)
        let vel = vessel.orbit.orbital_velocity(ut)
        let rad = vessel.orbit.radius(ut)
        let ap = vessel.orbit.apoapsis
        let lat = vessel.geocoordinates.latitude

I get an error with the last line: "Type vessel does not have a field "geocoordinates"

It's geo_coordinates.  In my opinion, types are especially confusing in this language. You can't declare them, you should use let and const, but you are expected to specify them in parameters/results. Also, if you use return floatValue, the compiler thinks is a Unit type, so you need to omit the return keyword.
Other than that, I think is less tedious than kerboscript.

On 3/11/2023 at 3:33 AM, Dunbaratu said:

It's wonderful that someone is doing this.  As the person maintaining kOS for KSP1, I felt bad that my computer is not up to being able to do KSP2 so I'm not part of the KSP2 hype so kOS for KSP2 isn't really a thing I can be working on.

(Also, I am in a job search where until I land a job it would be irresponsible for me to be shelling out the cash and free time it would take to be doing a kOS for KSP2 right now.)

There's things I'd want to do differently if I did do a kOS for KSP2 and it looks like some of those things are in the mind of the person doing this.  For one thing I didn't start the kerboscript language so when I enhanced it with lots more stuff like scoping, function calls, and delegates, it was always piecemeal one new feature at a time and therefore I sided with "keep it looking similar" rather than "do it like normal languages would do it" a lot of the time.  That led to, well, the weirdness that is kerboscript.

Thanks for maintaining it, my favorite mod by far. I guess I'm irresponsible hehe.

Edited by Elox
Link to comment
Share on other sites

Good news, after it still seems to work after the patch, i.e. the 0.1.8 version should be good for 0.1.1.0 as well.

I made an update nevertheless to 0.1.9:

  • Thanks to ThunderousEcho there is now an in-game script editor
    • ... there is an issue with focus of IMGUI elements and game input though (which can be temporary toggled of)
  • Thanks to kbleeke scripts can now have additional arguments (e.g. the target_apoapsis fo the launch_rocket script can be now tweaked via the UI)
Link to comment
Share on other sites

I've finally done it: A fully scripted Mun-mission, from launch to landing with a single button click.

Here the raw video footage (apart the initial button click and adjusting the camera from time to time there was no input)

Quote

The Martian troops, moreover, had no control over where their ships were to land. Their ships were controlled by fully automatic pilot-navigators, and these electronic devices were set by technicians on Mars so as to make the ships land at particular points on Earth, regardless of how awful the military situation might be down there. The only controls available to those on board were two push-buttons on the center post of the cabin—one labeled on and one labeled off. The on button simply started a flight from Mars. The off button was connected to nothing. It was installed at the insistence of Martian mental-health experts, who said that human beings were always happier with machinery they thought they could turn off.
   Kurt Vonnegut, The Sirens of Titan

Sources can be found here: https://github.com/untoldwind/KontrolSystem2/tree/master/examples

Link to comment
Share on other sites

@UntoldwindI just started using Kontrol System. So far, I like it a lot. I've been using KOS in KSP 1 for a long time now. KontrolSystem looks like it is shaping up to be very impressive.

I'm a retired software developer / software architect with experience in a lot of languages. Let me know if there is anything I can do to help.

 

Edited by AlwaysBeBatman
fixed typos
Link to comment
Share on other sites

22 hours ago, AlwaysBeBatman said:

I'm a retired software developer / software architect with experience in a lot of languages. Let me know if there is anything I can do to help.

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 ;) 

As for upcoming features: I just uploaded a "0.2.0" pre-release to github, with two major extensions: "Coordinate system independent vectors" and "Debug vectors"

The latter is probably the more important one as it allows you to draw arrows like this:

 debug_vectors.png

More details here: https://github.com/untoldwind/KontrolSystem2/blob/master/02_additions.md

I really hope I did not messed this up :)

Link to comment
Share on other sites

@Untoldwind Firstly, thanks you so much for all your hard work on this! I love it! For some reason the circularization part of the launch script is giving me issues, but otherwise there's just so much to love! And now it's got vacuum landing with prediction and desired points a la MechJeb?! Even better! I love that! I am for sure updating this mod right now and gonna go try that part out for myself.

As for the "issues" I've seen with circularization on a launch - I'll see if I can supply more details so that the problem can be better understood. I think it might have somethign to do with the rocket I was using required a staging during the circularization burn, and the LV stage was way more powerful than the upper stage. Perhaps the circularization part of the code is assuming that whatever motors you're using have similar thrust, or simply that you'll do all of the circularization with a single motor?

FYI the fun little robot Kerbal in the portraits view is what you get where there's a drone core aboard. I'm guessing your craft has one of those somewhere inside it just so that you can maintain control even if all the Kerbal passengers disembark. This portrait is a new feature in KSP2 0.1.1, and personally I love it too! If you send out a CommSat deployer with multiple autonomous payloads aboard, you wind up with one portrait like that for each drone core.

UPDATE: So, I downloaded 0.2.0.2 and I don't see a landing module. Where should I be looking for that?

Available Entry Points are as follows.

  • circularize
  • exec_node
  • flightinput_example
  • intercept
  • launch_rocket

When I browsed through the  Modules I didn't see anything that jumped out as a likely candidate.  Your video shows a debug_it, do_it, and test_it module, but I don't see any of those. Is there something else users need to do besides downloading the zip from SpaceDock and installing in the usual way for BepInEx. My KontrolSystem main windows shows that it's 0.2.0.2.

Edited by schlosrat
Link to comment
Share on other sites

23 hours ago, schlosrat said:

UPDATE: So, I downloaded 0.2.0.2 and I don't see a landing module. Where should I be looking for that?

Oh sorry, there is no entrypoint for that, it is just in the lib, so you have to create one of your own.
Which is pretty simple:
 

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { vac_land } from std::land::vac

pub fn main_flight(vessel: Vessel, lat: float = 0, lon: float = 37) -> Result<Unit, string> = {
    CONSOLE.clear()
    vac_land(vessel, vessel.main_body.geo_coordinates(lat, lon), 10)?
}

(the lat=0, lon=37 is something I use for the Mun, its a nice flat area)

I am not really sure how many entrypoints I should ship with the mod itself. There should be some room left for your own stuff after all ;)

Maybe there should be no bundled scripts at all and everything goes to a community repo?

Link to comment
Share on other sites

10 minutes ago, Untoldwind said:

Oh sorry, there is no entrypoint for that, it is just in the lib, so you have to create one of your own.
Which is pretty simple:
 

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { vac_land } from std::land::vac

pub fn main_flight(vessel: Vessel, lat: float = 0, lon: float = 37) -> Result<Unit, string> = {
    CONSOLE.clear()
    vac_land(vessel, vessel.main_body.geo_coordinates(lat, lon), 10)?
}

(the lat=0, lon=37 is something I use for the Mun, its a nice flat area)

I am not really sure how many entrypoints I should ship with the mod itself. There should be some room left for your own stuff after all ;)

Maybe there should be no bundled scripts at all and everything goes to a community repo?

LOL, I didn't realize it would be as simple as that! Thanks for sharing this. I like the idea of a community repo for scripts. Where would that be? How can we make contributions to it?

As an aside, I love that you can feed the function lat/lon to define your desired landing point. Is the expectation that a player edits their landing script each time they want to go some place different and so the script always has a hard coded value like this, or is there some way to have a general script that prompts the user for input, perhaps offering default values? It might be nice to have one landing script that can be used for any point you want to land at rather than cluttering up your space with many specific scripts to go various places.

Link to comment
Share on other sites

1 hour ago, schlosrat said:

Is the expectation that a player edits their landing script each time they want to go some place different and so the script always has a hard coded value like this, or is there some way to have a general script that prompts the user for input, perhaps offering default values? It might be nice to have one landing script that can be used for any point you want to land at rather than cluttering up your space with many specific scripts to go various places.

If you write add extra parameters to the `main_flight` function they can be tweaked in the UI already (thanks @kbleeke for the contribution). I.e. there should be a "2" next to the start button, indicating that the entrypoint has two parameters. When you click on that you get a little dialog to tweak the lat,lon (or whatever other parameters the entrypoint has).

Link to comment
Share on other sites

1 hour ago, Untoldwind said:

If you write add extra parameters to the `main_flight` function they can be tweaked in the UI already (thanks @kbleeke for the contribution). I.e. there should be a "2" next to the start button, indicating that the entrypoint has two parameters. When you click on that you get a little dialog to tweak the lat,lon (or whatever other parameters the entrypoint has).

Oh my gosh! I did not realize that's what those numbers mean! That totally solves my need for on the fly configurability! Thank you for pointing it out, and Thanks to kbleeke for contributing it!

BTW, you need a circularize_pe function. The way that circularize makes a choice for you and sticks you with the ap if e < 1 is no beuno. That will work only if you happen to want to circularize at the ap. Suppose you're returning from the Mun. You've got a spiffy pe of 100km-ish at Kerbin, and you'd like to circularize there before performing your re-entry burn...Yeah, the existing circularize.to2 is not gonna cut it. I hacked up a circularize_pe.to2 like this

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { circularize_orbit_at } from std::maneuvers
use { estimate_burn_time } from std::vac
use { remove_all_nodes } from std::utils
use { Vec3 } from ksp::math
use { Orbit } from ksp::orbit

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    let (delta_v, UT) = circularize_orbit_pe(vessel.orbit)?

    CONSOLE.print_line("Circle: " + delta_v.to_string() + " " + UT.to_string())

    let (burn_time, half_burn_time) = estimate_burn_time(vessel, delta_v.magnitude, 0.5, 1.0)

    CONSOLE.print_line("Burntime: " + burn_time.to_string() + " " + half_burn_time.to_string())

    remove_all_nodes(vessel)
    
    vessel.maneuver.add_burn_vector(UT - half_burn_time, delta_v)?
}

/// Calculate the required delta-v and time to change the given `orbit`
/// to a (mostly) circular orbit at the next periapsis
pub sync fn circularize_orbit_pe(orbit : Orbit) -> Result<(delta_v: Vec3, UT: float), string> = {
    const UT = orbit.next_periapsis_time()

    (delta_v: circularize_orbit_at(orbit, UT), UT: UT)
}

But to be honest, the circularize_orbit_pe function probably belongs in maneuvers.to2. I didn't put it there since any update to the mod will just stomp on it there. I also made a similar circularize_ap.to2, but got a weird compile error complaining about the return values until I modified the const UT line to be this

    const UT = if(orbit.eccentricity < 1) orbit.next_apoapsis_time()? else 0

 

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