Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

Are there any plans for how to handle the case where a part has more than one instance of the same PartModule? E.g. I've seen solar panels with multiple ModuleDeployableSolarPanel to handle all of their animations.

My hope is that since the purpose here is to let you only access those fields that are showing up on the menu, that nobody writing a PartModule would design a system in which a repeated field ends up showing up repeatedly on the context menu pane. (if the field has no gui component to it, it's going to be inaccessable from kOS - I'm only trying to expose the menu, under the principle that the kOS autopilot should be able to see what the human pilot can see, and should be able to click buttons the human pilot can click. That's why I'd really like to find a good way to abstract away the PartModule step - because the context menu doesn't show the partmodules to the user - it makes it look *as if* the part just natively has those fields, without explaining which ones came from which mod.

Perhaps the solution is to allow both:

Make it so you can say:

somePart:someModule:someField

OR you can equivalently say:

somePart:someField

and it will search for you to figure out which module has a field called someField that is gui-exposed.

That way you'd only *have* to use the module name when there is a name clash and two mods ended up putting fields on the menu with the exact same gui label on them, which if the writers of mods are doing things well, they probably shouldn't be doing anyway as that makes for a messy user interface.

Edited by Steven Mading
Link to comment
Share on other sites

Perhaps the solution is to allow both

I was just about to post exactly this, and you beat me to it.

Are there any plans for how to handle the case where a part has more than one instance of the same PartModule? E.g. I've seen solar panels with multiple ModuleDeployableSolarPanel to handle all of their animations.

If we ever find a mod that does this in a way that is exposed to the ui i think we should:

1. slap said mod author because their mod will be hard to use

2. back up and allow yet another way to get the raw collection of modules.

I dont think we will have to for the reasons steven has already talked about.

BTW, apparently my subscription to this thread broke so i am reading through quite a few pages of discussion :P if i feel the need to necro something form awhile ago i apologize in advance

Link to comment
Share on other sites

OMG this is so awesome. I'm dropping a science probe through Duna's atmosphere and being able to automate the triggering of experiments and discharge of capacitors while playing with signal delay is going to be sick (this is a ways off in my game, a month or two at least in real time even, so I'm not saying this to rush you guys)

Link to comment
Share on other sites

OMG this is so awesome. I'm dropping a science probe through Duna's atmosphere and being able to automate the triggering of experiments

Sadly, the problem with that is that you cannot automate the little popup dialogs that show you the science results (where you click the trash or keep button for the data). Therefore although you should be able to use this new feature to take science readings, you'd still have to manually click away those windows that pop up in the center of the screen in your way, so it wouldn't feel *quite* automated.

Link to comment
Share on other sites

yes true, I did think of that :) But at the same time none of that is affected by signal delay (other than the actual transmission) so there's no need for it to be automated. I'm not automating for the sake of automating because it's "cool", simply because RT2 signal delay requires it. I was originally planning to fly the mission with signal delay to the point of probe release, then restart the game with signal delay disabled so I could "manually automate" the probe's collection of science. Glad I won't have to "cheat" now ;)

Edited by Gaiiden
Link to comment
Share on other sites

how do you use boot files? If I right-click on a part in the VAB I don't see any way to select a boot file. I've done this to an AIES probe core:

@PART[novapod] {
MODULE
{
name = kOSProcessor
diskSpace = 50000
}

@MODULE[ModuleCommand]
{
@RESOURCE[ElectricCharge]
{
@rate = 0.05
}
}
}

And looking at the actual kOS parts I didn't see anything else I should be adding

Edit: disabled the MM patch above, for now as it brought back the bug whereupon returning to my rocket on the launchpad only the novapod remained and things were all screwy with the game. I had this issue when developing my Rover Driver program but it seemed to go away once the rover left the runway, so I will re-apply this patch once my ship is in orbit and see if it still screws things up.

Edited by Gaiiden
Link to comment
Share on other sites

Boot files are just normal scripts, but you'll need to name them starting with "boot", you can then select them in the VAB. Right-click on your kOS core, and you'll be able to toggle a boot file.

Basically, all my boot files are like this:


toggle ag10.//"Toggle Terminal" is binded to action group 10
switch to 0.
clearscreen.
run ***.//run whatever program you want

You get used very fast to not having to type those commands before every launch...

Link to comment
Share on other sites

Ok, this is probably a very very very basis question, but I'm new to programming as a whole and was hoping this would be a fun way to learn, so bear with me...

How do I start the next line of test???!

Whenever I hit enter it tries to run the program. I seriously can't even get through the tutorial because I can't type the next line! O.o

Link to comment
Share on other sites

Ok, this is probably a very very very basis question, but I'm new to programming as a whole and was hoping this would be a fun way to learn, so bear with me...

How do I start the next line of test???!

Whenever I hit enter it tries to run the program. I seriously can't even get through the tutorial because I can't type the next line! O.o

There's two modes - interactive and program.

When you type something in the terminal, it just runs the thing you typed right away. This is interactive mode.

To write a program consisting of multiple commands - you do one of two things:

1 - At the interactive terminal, Enter the command EDIT MYFILE. This makes a text editor window appear under the terminal. Use it to type multiple commands, then click "save" and in the interactive terminal type RUN MYFILE.

Or, for a more permanent, and better long-term solution:

2 - Edit a text file with some external text editor program (notepad on windows, textedit on mac, for example). Type commands in the text file like you would at the interactive terminal. Save the text file in the Plugins/PluginData/Archive folder, with a filename like "MYFILE.txt". At the interactive terminal type these three commands: SWITCH TO 1. COPY MYFILE FROM ARCHIVE. RUN MYFILE.

It's important to know that any program you store on the "local" volume (which is the default when you don't use the SWITCH TO command), is actually stored inside that one ship. If this ship crashes, or if you revert the flight to erase what you did to the ship, that copy of the program is gone. If it was your only copy of the program it's gone for good. So don't use that method except as a quick and dirty test. Instead edit your files in the archive (volume 0) and copy them from there to the ship to run them.

Link to comment
Share on other sites

How do I check whether there is a node on the flight plan?

I can try to do anything with NEXTNODE and if there is none, the script will terminate with an error. This is a test of sorts; but if I want my script to continue even if there is no node present, how do I do that?

@Lilleman: that's a great idea for a boot file. Copied.

Link to comment
Share on other sites

How do I check whether there is a node on the flight plan?

I can try to do anything with NEXTNODE and if there is none, the script will terminate with an error. This is a test of sorts; but if I want my script to continue even if there is no node present, how do I do that?

I agree with you that this is a large problem. And no, you haven't missed anything. You are correct that there's nothing you can do to get around this problem currently in a kos script. If you post the problem as an issue to the github page, it's more likely to get fixed sooner rather than later. An actual complaint by an actual user encountering this as a real problem makes it more serious than me posting about it myself as a "potential" problem.

Link to comment
Share on other sites

I am reluctant to sign up with Yet Another Site, but if it's necessary for me to show up on github... alright, I'll do.

BTW: I have on occasion seen that kOS Scripts can take command-line parameters. But whenever I wanted to to use this I couldn't quite remember how and my searches came up empty. Would you be willing to add this to kos_doc?

Link to comment
Share on other sites

@Laie

I was trying to cope with similiar problem and I figured a temporary fix would be to add a node like 100 years ahead and then check if nextnode:eta is lower than 95 years. If it is, there was another node. But I couldn't figure out manual node adding (especially time of added node, which I needed for that) and just gave up. I didn't try too hard tho.

Link to comment
Share on other sites

I think this is the most up to date documentation: https://github.com/Nivekk/KOS/blob/master/README.md

A quick example for arguments, let's made a testArg.txt file:

declare parameter X.
print X.

And that's it, you can call this with "run testArg(something)."

Where X can be a string, an integer (or a double), a condition, etc...

The only thing missing in the doc here (as far as I noticed) is the WARPMODE thing:

set warpmode to "RAILS".//only if the ship's altitude allows it
set warp to 7.

set warpmode to "PHYSICS".//physics time warp
set warp to 3.

Useful stuff too...

Edit: @dzikakulka: That would be:


set bNodeExist to false.
set iNodeETA to (time:seconds + 920340000).//a kerbal year is 2556.5 hours, *100
set tempNode to node(iNodeETA,0,0,0).
add tempNode.
if nextnode:eta < tempNode:eta {
set bNodeExist to true.
}.
remove tempNode.

I have to try this. Thanks for the idea!

Edited by Lilleman
Link to comment
Share on other sites

I am reluctant to sign up with Yet Another Site, but if it's necessary for me to show up on github... alright, I'll do.

BTW: I have on occasion seen that kOS Scripts can take command-line parameters. But whenever I wanted to to use this I couldn't quite remember how and my searches came up empty. Would you be willing to add this to kos_doc?

http://ksp-kos.github.io/KOS_DOC/command/file/index.html#run-1---comma-separated-args--

Link to comment
Share on other sites

That is the old documentation from the original author, who abandoned kOS about 10 months ago and hasn't been heard from since.

This page is more up to date:

http://ksp-kos.github.io/KOS_DOC/

Well, this is embarrassing, sorry...

Anyway, thanks to dzikakulka, I now have a workaround to test if there is a next node, confirmed to work:

set iETA to 2147483646.//0x7FFFFFFE
set nNode to node(iETA,0,0,0).
add nNode.
if nextnode:eta < iETA { print "Nextnode exist!". } else { print "Nextnode does not exist!". }.
remove nNode.

2147483646 is 0X7FFFFFFE in hexadecimal, and it seems like the maximal value for a date in KSP is 0X7FFFFFFF.

This create a node just a second before the end of times, then it check if there is a node before that.

Link to comment
Share on other sites

There's two modes - interactive and program.

When you type something in the terminal, it just runs the thing you typed right away. This is interactive mode.

To write a program consisting of multiple commands - you do one of two things:

1 - At the interactive terminal, Enter the command EDIT MYFILE. This makes a text editor window appear under the terminal. Use it to type multiple commands, then click "save" and in the interactive terminal type RUN MYFILE.

Or, for a more permanent, and better long-term solution:

2 - Edit a text file with some external text editor program (notepad on windows, textedit on mac, for example). Type commands in the text file like you would at the interactive terminal. Save the text file in the Plugins/PluginData/Archive folder, with a filename like "MYFILE.txt". At the interactive terminal type these three commands: SWITCH TO 1. COPY MYFILE FROM ARCHIVE. RUN MYFILE.

It's important to know that any program you store on the "local" volume (which is the default when you don't use the SWITCH TO command), is actually stored inside that one ship. If this ship crashes, or if you revert the flight to erase what you did to the ship, that copy of the program is gone. If it was your only copy of the program it's gone for good. So don't use that method except as a quick and dirty test. Instead edit your files in the archive (volume 0) and copy them from there to the ship to run them.

Hmm, interesting. So to be clear, switch to 1 means put it on the ship, switch to 0 means put it in the archive? And is this the same as those "load from/save to archive" commands I see some people use?

Link to comment
Share on other sites

"switch to 1." means that subsequent references to files will be using the files that are local to the ship.

"switch to 0." means that subsequent references to files will be using the files that are in the archive.

"load from/save to archive." copies files from the currently active volume from and to the archive volume. If preceded by a "switch to 1." command, the files will be copied from the archive volume to the ship's volume and from the ship's volume to the archive volume.

skips

Link to comment
Share on other sites

Is anyone willing to lead a challenge post for kOS?

A long time ago there was a pending challenge post in the challenge thread. It was designed for kOS missions. That challenge seems to be mostly dead. I'd consider starting one up but I'd rather not add the extra work as I fear it would detract from my working on kOS itself to help erendrake get bug fixes and features out.

Is there anyone willing to come up with an interesting challenge and post it? The reason I ask is that I remember the last one was actually quite a boon for kOS as it sort of forced the discovery of limitations in the language once people started trying to use it to do more complex things. It increased the visibility of, and interest in, the new mod and helped test it at the same time. I think it would be great if the next release (real soon now??? dunno) were to be accompanied by such a new challenge post.

Things I can think of that might make interesting challenge contests off the top of my head:

The docking tests:

* Build the biggest space station, taking as many launches as you feel like to complete the task. Score based on total mass and variety of parts (i.e. count unique part names that come back from LIST PARTS, so a station made of solar panels, habitats, fuel tanks, labs, etc is worth more than one made of just 10 boring fuel tanks lined up.)

* Perform an apollo-style mission including the docking and undocking rendezvous in munar orbit between command module and lander. Better score for landing at the actual Apollo 11 site (or, well, the Munar equivalent - the shorter the distance to the Armstrong Memorial, the higher the score). Allow lesser points for partial completion of some of the parts (i.e, you landed and came back, but didn't do it with a docking rendezvous).

Bot vs Bot ideas. These would involve the contest host setting up a campaign save ready for the contest start, and inserting people's crafts into the save game and running their code on the host's computer to see how it performs.

* Rover obstacle course and vision test: Contestants are told only what Body the contest occurs on so they know what gravity level to design for, the names of the waypoints and the rough distance they'll cover, and that there will be some debris in the way. They must design a rover and autopilot that will allow them to run the course to the waypoints (which will be short one-part debris vessels named ahead of time so they know how to write them in the script, as in "I know I need to write a program that heads for a vessel called "point 1", then one called "point 2", even though I don't know where those points will be yet in the actual test.". I'm envisioning having to use the laserdist mod to "read" the obstacles in the way of the rover.

* Rover vs Rover soccer match: Using the soccer ball mod that SQUAD put out during the world cup, each contestant makes 2 rovers for their "team", to face off against 2 rovers from an opposing team, trying to shove the ball into the other's goal. No grabbing the ball with a robot arm or asteroid grabber- it must be shoved and pushed. The goalposts would be inserted into the game save ahead of time, and the two bots from each team would be artificially inserted into the field at pre-advertised starting points. For fairness, in this one everyone has to drive the same rover (so you don't just make a goalie rover that's wide and fills the whole goal) that the contest host designs - it's a contest of the software, not the hardware, so the host would provide everyone with a copy of the savegame that has the starting conditions ahead of time for them to test with. Bots would have known names ahead of time - if you are team A then your bots are called "A1" and "A2" and if you're team B then you bots are called "B1" and "B2". Each player would provide a packet of programs to load onto the 10000byte module, and the host will load the exact same software on both their team bots.). Each bot would have to have one program called with RUN GAMESTART(whistletime), where whistletime is the TIME:SECONDS in the near future when the game is actually supposed to start (the bot better not move before then). This gives the hosting person time to run around and type that into all the bots and get them ready and waiting to go at the same time as each other. Each bot can query its own SHIP:NAME to find out if it's name is A1,A2,B1,or B2, which tells it which team it's on, and perhaps the player might program them to change their behavior accordingly (i.e. make the '1' bot go on offense and the '2' bot go on defense).

These are just ideas off the top of my head that could be fun. Obviously if you wish to be the host of such a challenge, you'll have a lot more details than that to discuss and hammer out. These are just quick and fuzzy brainstorming ideas - take them or leave them.

Link to comment
Share on other sites

Some new challenges would be great, but I don't see myself maintaining a thread about them without having completed at least one before... So let's find some ideas! A spaceplanes challenge would be nice, I've not yet seen an autopilot capable of landing on the runway.

What about an automated crane for recovering debris, using Infernal Robotics and KAS? This could be fun too, and this could be a good way to test the new feature of the upcoming release.

Link to comment
Share on other sites

Some new challenges would be great, but I don't see myself maintaining a thread about them without having completed at least one before... So let's find some ideas! A spaceplanes challenge would be nice, I've not yet seen an autopilot capable of landing on the runway.

What about an automated crane for recovering debris, using Infernal Robotics and KAS? This could be fun too, and this could be a good way to test the new feature of the upcoming release.

Sadly that new feature won't be in the upcoming release but probably a release after that.

Link to comment
Share on other sites

Hey, does anybody know how to get Isp "automatically" ?

I am writing a script that executes precision deltaV maneuvers based only on direction and dV, no other factors or inputs required.

To do this, I am calculating a reverse Tsiolkovsky to give change in mass, then calculating the fuel rate (both dm and df/dt require Isp).

I'm about to use the KOS sensors mod to bridge this gap, but I'd rather use stock KOS for this. Any pointers or ideas? (I've already combed the KOS wiki for references to Isp.)

Link to comment
Share on other sites

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