Jump to content

[KSP 1.12.x] kOS v1.4.0.0: kOS Scriptable Autopilot System


Dunbaratu

Recommended Posts

21 hours ago, MindChirp said:

wait until alt:radar > 70000. global pitch is 90. lock steering to heading(90,pitch).

This will try to steer upwards, rather than towards the horizon. Surely you should be aiming at a pitch of 0 here?

Doesn't answer why you don't see RCS firing, of course. That is a bit inexplicable without more information (e.g. what does your rocket look like?)

Also, you have that code within the for loop, when it really belongs outside it.

Link to comment
Share on other sites

Hi folks, kOS noob here.  So far I've managed to achieve orbit with a simple square root of altitude function, and am working on improving my circularisation burn.  Great way to learn the maths behind orbital manoeuvres rather than my usual suck it and see approach in KSP.

Simple question though, what do people recommend for editing files?  I'm currently using notepad which is hardly ideal.  I found a list of editors somewhere, and mention of a kOS plugin for Atom, but any specific recommendations?

Link to comment
Share on other sites

I haven't used it, but someone has posted a syntax highlighting and such plugin for vim, google it, it's somewhere on github. Somebody has also created a plugin for microsoft's visual studio code, I have used it, but not extensively enough to say what all of its features are. 

Link to comment
Share on other sites

8 hours ago, RizzoTheRat said:

Hi folks, kOS noob here.  So far I've managed to achieve orbit with a simple square root of altitude function, and am working on improving my circularisation burn.  Great way to learn the maths behind orbital manoeuvres rather than my usual suck it and see approach in KSP.

Simple question though, what do people recommend for editing files?  I'm currently using notepad which is hardly ideal.  I found a list of editors somewhere, and mention of a kOS plugin for Atom, but any specific recommendations?

You can found various additions for various text editors on kOS github page. For windows OS, I recommend notepad++ and language addition for it from linked page. Users with other OS such as linux or MAC might have differente preference what text editor offer better features.

Link to comment
Share on other sites

13 minutes ago, kcs123 said:

You can found various additions for various text editors on kOS github page. For windows OS, I recommend notepad++ and language addition for it from linked page. Users with other OS such as linux or MAC might have differente preference what text editor offer better features.

As a Mac user, I use BBEdit even though it has no KerboScript syntax coloring (I haven’t gotten around to defining it).  Atom does have a KerboScript highlighting extension (https://atom.io/packages/language-kerboscript), so if you want those sweet sweet colors, it’s a good choice.

Edited by meyerweb
Fixed the URL to point to an active Atom package
Link to comment
Share on other sites

Hello everyone! I have a question regarding my code; I am at a loss as to why one piece of it doesn't work. It's a when statement and its contents from line 39 to 44. It's supposed to start and finish a gravity turn. In the past (maybe one or two years ago) I used this same statement to perform gravity turns, and it worked out fine. I have since started playing again and it doesn't work for some reason. Some background info: I have many mods, including Realism Overhaul and its required mods.

Code: https://pastebin.com/uBi6eTyA

Thank you in advance!

Link to comment
Share on other sites

I haven't tried KOS yet, as, until now, I haven't had a want to.  Now I have some probes with Near Future Electric's capacitors on board.  I was wondering if KOS would work for this type of script:
 

Quote

 

While Engine Running

{

   If battery < 10%

Discharge Next Full Capacitor

}

While Engine !Running

{

Charge Next empty Capacitor

Repeat until Charge flow is negative

}

 

 

I figure it will with stock parts, but I'm curious if it can easily pick out mod parts, multiple parts that were added via symmetry and identify them individually, and manipulate them like a user would.

I'm not asking for the code, I'd rather figure it out myself, but not having touched KOS before, some hints/pointers would be appreciated if it's possible to do this.   I'm digging through the documentation now.  

Link to comment
Share on other sites

2 hours ago, Gargamel said:

I haven't tried KOS yet, as, until now, I haven't had a want to.  Now I have some probes with Near Future Electric's capacitors on board.  I was wondering if KOS would work for this type of script:
 

 

I figure it will with stock parts, but I'm curious if it can easily pick out mod parts, multiple parts that were added via symmetry and identify them individually, and manipulate them like a user would.

I'm not asking for the code, I'd rather figure it out myself, but not having touched KOS before, some hints/pointers would be appreciated if it's possible to do this.   I'm digging through the documentation now.  

You can add a name tag to an individual part, and use ship:partsdubbed() to identify it.

Link to comment
Share on other sites

4 hours ago, Gargamel said:

multiple parts that were added via symmetry

everything you want but this. You unfortunately can't set name tags via symmetry in the editor so you are better off using partsdubbed to call the capacitors by their name or title so you can get them all

Link to comment
Share on other sites

12 hours ago, dafidge9898 said:

Hello everyone! I have a question regarding my code; I am at a loss as to why one piece of it doesn't work. It's a when statement and its contents from line 39 to 44. It's supposed to start and finish a gravity turn. In the past (maybe one or two years ago) I used this same statement to perform gravity turns, and it worked out fine. I have since started playing again and it doesn't work for some reason. Some background info: I have many mods, including Realism Overhaul and its required mods.

Code: https://pastebin.com/uBi6eTyA

Thank you in advance!

Try commenting out lines 39 and 44.

The UNTIL block you have above ensures that the conditions of the WHEN will be met immediately. So you may as well run lines 40-43 right away.

To put it another way, it is really confusing to mix imperative UNTIL statements with WHEN interrupts/triggers in this way. Triggers should be used for something that you anticipate happening, but don't know when (in relation to the rest of your code).

As to why it doesn't work now: from memory the lock steering command (which itself sets up a trigger) within a trigger is not actually applied until the trigger block exits, at which point it'll immediately be countermanded by the lock steering in the UNTIL block below, so it'll never be used. I think this is a known issue: https://github.com/KSP-KOS/KOS/issues/2191

Edited by ElWanderer
link to Github
Link to comment
Share on other sites

9 hours ago, Drew Kerman said:

everything you want but this. You unfortunately can't set name tags via symmetry in the editor so you are better off using partsdubbed to call the capacitors by their name or title so you can get them all

Having not played enough with KOS to translate that into English yet, you're saying while it's not easy, it is doable? 

Link to comment
Share on other sites

 

21 hours ago, Gargamel said:

I figure it will with stock parts, but I'm curious if it can easily pick out mod parts, multiple parts that were added via symmetry and identify them individually, and manipulate them like a user would.

The capacitor logic probably has its own part module. You could iterate over all parts of the ship and check which ones have that module. To find the name of the capacitor module, check the config files of those parts.

Link to comment
Share on other sites

18 hours ago, Drew Kerman said:

everything you want but this. You unfortunately can't set name tags via symmetry in the editor so you are better off using partsdubbed to call the capacitors by their name or title so you can get them all

This is utterly false.  Yes If you attach then assign the tag it doesn't clone the tag because that policy still lets you give unique names to the copies.  But you can make clones of the tag by detaching the part after it's been given a tag and then reattaching it symmetrically.  The tag is copied to the clones at the moment of attachment.  The clones all have whatever the tag was at the moment the part got attached.

Link to comment
Share on other sites

On ‎23‎/‎02‎/‎2018 at 6:10 PM, kcs123 said:

You can found various additions for various text editors on kOS github page. For windows OS, I recommend notepad++ and language addition for it from linked page. Users with other OS such as linux or MAC might have differente preference what text editor offer better features.

Cheers, went with Notepad++ and a language addon in the end, works very well.

Link to comment
Share on other sites

FUNCTION D_MT {
	GLOBAL hpd IS 8.
	GLOBAL mt IS missiontime.
	GLOBAL d IS FLOOR(mt/(hpd*3600)).  
	GLOBAL h IS FLOOR((mt-hpd*3600*d)/3600).  
	GLOBAL m IS FLOOR((mt-3600*h-hpd*3600*d)/60).  
	GLOBAL s IS ROUND(mt) - m*60 -   h*3600 - hpd*3600*d.  
	PRINT m + ":" + s.
}

I'm using this script to convert MissionTime into a minutes:seconds format. The script works perfectly and gives me the mission time as i want it, but it also gives me a random 0 on the line below. This happens even when im using the following basic script to test it:

RUN YOURLIB.
PRINT D_MT().

which returns:

1:54
0
Program ended.

I have no idea why its returning that 0. Any help?

Link to comment
Share on other sites

Count the number of your PRINT statements... You are printing the mission time within your function, then you call the function in a PRINT statement. This prints 0 because you did not define a RETURN value for your function, so I assume 0 is default.

Just call your function without the PRINT in front.

Link to comment
Share on other sites

I'm starting to get somewhere with kOS, but having a couple of issues with a script I'm using to log various parameters in attempt to understand the drag as my VTOL SSTO returns, and get it to land near the KSC.

Firstly, I'm assuming that if I measure the acceleration, and then subtract the acceleration due to gravity, any remaining acceleration is due to drag providing the engines are off

Set Acc to ship:sensors:Acc.        //measured acceleration
Set Grav to ship:sensors:grav.      //Acceleration due to gravity
Set Drag to Acc - Grav.             //Acceleration due to drag

However in a stable 86km orbit it's measuring acceleration due to gravity at 7.49, but overall acceleration of 6.83, so where's the other 0.66m/s2 coming from?

 

Secondly, I've calculated air density via 2 different methods,

Set Vel to ship:velocity:surface.                   //Velocity vector
Set Q to ship:Q * constant:AtmToKPa *1000.          //Dynamic pressure in Pa
Set DensQ to (2*Q)/Vel:mag^2.                       //Air density calculated from dynamic pressure

Set Tp to ship:sensors:temp.                        //Measured temperature
Set Press to ship:sensors:pres*1000.                //Measured pressure in Pa
Set DensIns to Press/(287.053*Tp).                  //Air density calculated from temperature and pressure

However with the ship descending through the atmosphere, the density from the instruments is coming out at about 70% of the density from the Q calculation.  I can see that there might be a slight error due to when the individual readings are taken, but it's only doing about 200m/s when I took the data so I can't believe the difference would be that high.

 

 

Any ideas what I'm doing wrong?

Edited by RizzoTheRat
Link to comment
Share on other sites

On 2/26/2018 at 7:25 AM, ElWanderer said:

Try commenting out lines 39 and 44.

The UNTIL block you have above ensures that the conditions of the WHEN will be met immediately. So you may as well run lines 40-43 right away.

To put it another way, it is really confusing to mix imperative UNTIL statements with WHEN interrupts/triggers in this way. Triggers should be used for something that you anticipate happening, but don't know when (in relation to the rest of your code).

As to why it doesn't work now: from memory the lock steering command (which itself sets up a trigger) within a trigger is not actually applied until the trigger block exits, at which point it'll immediately be countermanded by the lock steering in the UNTIL block below, so it'll never be used. I think this is a known issue: https://github.com/KSP-KOS/KOS/issues/2191

Thank you, it works now. I'll keep the bug in mind.

 

Link to comment
Share on other sites

Hello, I just recently got back in KSP and of course there was an update a few days ago and quite a few of the mods I had installed don't work anymore. Can anyone confirm the version for 1.3 doesn't work with 1.4?

Edited by CptAWatts
Link to comment
Share on other sites

3 hours ago, CptAWatts said:

Hello, I just recently got back in KSP and of course there was an update a few days ago and quite a few of the mods I had installed don't work anymore. Can anyone confirm the version for 1.3 doesn't work with 1.4?

It doesn't work with v1.4.0, according to one of the devs: https://github.com/KSP-KOS/KOS/issues/2240

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