Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

Hmm. Do you really mean any tank?

The typical solution is

IF STAGE:LIQUIDFUEL < 0.01 {STAGE.}

This checks to see if all engines in the current stage are empty and drops if they are. The 0.01 is because KSP doesnt always empty big tanks. Im not sure how this behaves with asparagus staging, whether the radial tanks are considered same stage as the core booster. It also obviously only works on LF engines. Works well as a WHEN THEN trigger.

If you specifically want as you stated: If any LF tank anywhere on the ship is empty, then stage:

You probably need Lists. Off the top of my head something like:

 list tanks in tanklist. for t in tanklist {if t:liquidfuel < 0.01 {stage.}}.

Not tested that one but it should walk the entire ship and check each tank, calling stage everytime it finds an empty, if you have a bunch of empty tanks this would dissassemble your ship, but you see what i mean... Set a boolean flag true when you find empties and stage when true, would work for asparagus and slack tank setups i guess.

Personally I use:

 set nO to 0.
list engines in el.
for e in el {
if e:flameout {
set nO to nO + 1.
}
}
IF nO > 0 {STAGE.}

Stages if anything is 'flamed-out', which includes not just jet engines but absolutely any motor that is resource starved, so works for solids/ions/any mod fuels and is immune to the residual fuel-traces which can muck with staging logic. The disadvantage of the two list methods is that they kinda need to be inside your loops and dont work as WHEN triggers, and the last one absolutely cannot handle a slack tank since its actually inspecting engines.

Edited by celem
typos in code sections
Link to comment
Share on other sites

Hello everyone! I'm here to let you know that I just started a little project on GitHub for a Notepad++ language file for kOS. I'm pretty sure I have the basics down already, but I know there are some holes. I would like it if people started using this so they can tell me the holes, or maybe fix them themselves.

You can try it out here.

Link to comment
Share on other sites

By the way, I talked to erendrake and confirmed that LOCK STEERING does not properly use engine gimbaling, so if you intend to use this mod in say, Realism Overhaul, you're going to have to resort to using Raw Input.

Link to comment
Share on other sites

Hello everyone! I'm here to let you know that I just started a little project on GitHub for a Notepad++ language file for kOS. I'm pretty sure I have the basics down already, but I know there are some holes. I would like it if people started using this so they can tell me the holes, or maybe fix them themselves.

You can try it out here.

It has been done in the past, but your version may be more up-to date if you keep maintaining it.

Link to comment
Share on other sites

By the way, I talked to erendrake and confirmed that LOCK STEERING does not properly use engine gimbaling, so if you intend to use this mod in say, Realism Overhaul, you're going to have to resort to using Raw Input.

Then why do I remember over and over again seeing the engine nozzles tilting back and forth as kOS yanks the controls back and forth (in its overzealous way)? I know I've seen it do this a lot, but then again I don't play under RO. Is it a specific thing the RO mod does to change the API for gimbals?

As far as I knew, kOS lock steering merely yanks the "joystick" WASDQE controls around, and lets the main KSP game engine do whatever it will with those inputs, without making any fancy exceptions. The main game gimbals when you use WASDQE, so why doesn't kOS when it does?

Link to comment
Share on other sites

list tanks in tanklist. for t in tanklist {if t:liquidfuel < 0.01 {stage.}}.

Ah this was the sort of thing I was looking for, just couldn't get my head around it. Thanks. The 'standard' WHEN STAGE:LIQUIDFUEL < 0.001 only seems to work for very simple fuel setups.

I'm still having trouble building a tanklist that contains a list of fuel tanks. I've tried this:

set TANKLIST to SHIP:MODULESNAMED("fueltank")

But it doesn't seem to match anything.

So now I've got something like this:

SET tanklist to SHIP:PARTSDUBBED("fueltank").

for t in tanklist {

if t:RESOURCES:LIQUIDFUEL:AMOUNT < 0.01 {

STAGE.

}

}

But apparently t:RESOURCES:LIQUIDFUEL:AMOUNT is wrong. How do I get the amount of liquid fuel left in a part?

Edited by Sonny_Jim
Link to comment
Share on other sites

I'm so confused... New to kOS here. The command LOCK STEERING TO R(0,0,0) should keep the ship pointing in whatever direction it's currently facing, right? No rotation about its axis or anything as a result of that command?

The command LOCK STEERING TO HEADING (SHIP:FACING:ROLL,90) should also result in no change to roll, right? Why does it make my ship do a 360 degree roll? How can I avoid this and lock steering without changing my ship's roll??

More to the point though, is something wrong with how kOS handles changes to a ship's roll value? My vessels seem to shift on other axes when I give it a command to change its roll (which is why I'm trying get it to maintain its current roll...).

Link to comment
Share on other sites

Ah this was the sort of thing I was looking for, just couldn't get my head around it. Thanks. The 'standard' WHEN STAGE:LIQUIDFUEL < 0.001 only seems to work for very simple fuel setups.

I'm still having trouble building a tanklist that contains a list of fuel tanks. I've tried this:

But it doesn't seem to match anything.

There are a lot of ways to trigger stages, and not all of them require resource monitoring. For example see the next snippet:


set stagemaxthrust to ship:maxthrust.
when status <> "PRELAUNCH" and (ship:maxthrust<stagemaxthrust or ship:maxthrust<1) then {
print "Stage!".
stage.
set stagemaxthrust to ship:maxthrust.
preserve.
}

You remember ship's maxthrust and stage when it changes (due to engine flameout). The example I provided works with asparagus staging design

- - - Updated - - -

I'm so confused... New to kOS here. The command LOCK STEERING TO R(0,0,0) should keep the ship pointing in whatever direction it's currently facing, right? No rotation about its axis or anything as a result of that command?

The command LOCK STEERING TO HEADING (SHIP:FACING:ROLL,90) should also result in no change to roll, right? Why does it make my ship do a 360 degree roll? How can I avoid this and lock steering without changing my ship's roll??

More to the point though, is something wrong with how kOS handles changes to a ship's roll value? My vessels seem to shift on other axes when I give it a command to change its roll (which is why I'm trying get it to maintain its current roll...).

It seems you are confusing ROLL and compass. In HEADING(x,y) parameter x is the compass direction (http://ksp-kos.github.io/KOS_DOC/commands/flight/cooked.html?highlight=heading)

It is not kOS way of handling, but more of a how UnityEngine handles directions.

If you want your ship keep a steady roll during ascend consider the following code snippet:


lock steering to lookdirup(up:vector, ship:facing:topvector).

Or as a part of the loop:


until altitude > ha or apoapsis > orbitAlt {
set ar to alt:radar.
// control attitude

if ar < gt0 {
set arr to ar / gt0.
set pda to (cos(arr * 180) + 1) / 2.
set pitch to pitch0 * ( pda - 1 ).
set pitchvector to up + R(0, pitch, 0).

lock steering to lookdirup(pitchvector:vector, ship:facing:topvector).

}

Edited by Ziw
Link to comment
Share on other sites

Thanks for the reply. I don't really mind changing the roll if the ship does it smoothly without deviating off its roll axis. Just to clarify, is that an artefact of UnityEngine or were you referring to the 360 degree roll I experience?

That first bit of code you posted keeps the roll steady, but locks the ship to UP. Is there a way to get one without the other?

Also, is gt0 an undefined variable in the until loop?

Link to comment
Share on other sites

Ok, so I've managed to figure out a way to check for resources in a partslist that's made up of fuel tanks:

SET tanklist to SHIP:PARTSDUBBED("fueltank").

for t in tanklist {if t:resources[0]:AMOUNT < 0.01 {STAGE.}}

What I'd like to do now is to build a parts list containing all the fuel tanks by seeing if they have a LIQUIDFUEL resource, rather than finding them by a part name:

for i in SHIP:PARTS {

if i:RESOURCES:CONTAINS ("LIQUIDFUEL") {

tanklist:ADD (t).

}

}

But again I'm running into syntax problems. Could someone post a way to build a list of all parts that contain liquidfuel as a resource?

Link to comment
Share on other sites

How? From what I see it only stages when an engine flames out, not when a tank is emptied, which is what I'm trying to do.

Sorry, it works not for every type of asparagus staging, but only where engine flameout means there is need to stage.

- - - Updated - - -

*Push*

Better post code here.

In your code


PRINT "Deploying Payload".
STAGE.
SET ANTENNA TO SHIP:PARTSTAGGED("Comms").
ANTENNA:DOEVENT("activate").

ANTENNA is not a PartModule, it is a Part. You need to get the PartModule corresponding to your antenna.

If you are using RemoteTech that would be accessed as

set antenna_pm to ANTENNA:getmodule("ModuleRTAntenna").

After that you may call antenna_pm:doevent("activate").

- - - Updated - - -

Ok, so I've managed to figure out a way to check for resources in a partslist that's made up of fuel tanks:

What I'd like to do now is to build a parts list containing all the fuel tanks by seeing if they have a LIQUIDFUEL resource, rather than finding them by a part name:

But again I'm running into syntax problems. Could someone post a way to build a list of all parts that contain liquidfuel as a resource?

http://ksp-kos.github.io/KOS_DOC/language/flow.html#for

http://ksp-kos.github.io/KOS_DOC/structures/vessels/resource.html#structure:RESOURCE

- - - Updated - - -

Thanks for the reply. I don't really mind changing the roll if the ship does it smoothly without deviating off its roll axis. Just to clarify, is that an artefact of UnityEngine or were you referring to the 360 degree roll I experience?

That first bit of code you posted keeps the roll steady, but locks the ship to UP. Is there a way to get one without the other?

Also, is gt0 an undefined variable in the until loop?

I posted just a fraction of the ascend script as an example of how to keep the rocket pointing where you want it to, while keeping the roll stable. It is not that hard to figure out. Try finishing my second part by setting up missing variables. gt1 is the altitude of the first part of the ascend, during which you need to do the initial pitchover maneuver. It depends on your design and whether or not you're using FAR, but set it to say 5000 and set pitch0 to say 5 and see how your rocket behaves.

Edited by Ziw
Link to comment
Share on other sites

In your code


PRINT "Deploying Payload".
STAGE.
SET ANTENNA TO SHIP:PARTSTAGGED("Comms").
ANTENNA:DOEVENT("activate").

ANTENNA is not a PartModule, it is a Part. You need to get the PartModule corresponding to your antenna.

If you are using RemoteTech that would be accessed as

set antenna_pm to ANTENNA:getmodule("ModuleRTAntenna").

After that you may call antenna_pm:doevent("activate").

Ok, clear now...

Will try and report...

Link to comment
Share on other sites

Yeah! new failure:

Code:

PRINT "Deploying Payload".

STAGE.

SET ANTENNA TO SHIP:partstagged("Comms").

SET ANTENNA_PM TO ANTENNA:GETMODULE("ModuleRTAntenna").

ANTENNA_PM:doevent("activate").

screenshot8u3ber.png

Edited by JD_Tiger
Link to comment
Share on other sites

Use FOR loop to look through PART:RESOURCES

But how? I tried using CONTAINS and I got a syntax error. The closest I've got so far is to check whether the part has more than one resource:

SET tanklist to LIST().

for i in SHIP:PARTS

{

if i:RESOURCES:length > 1

{

tanklist:ADD (i).

}

}

Link to comment
Share on other sites

So i have to write 3 lines to activate all right?

like so:

PRINT "Deploying Payload".

STAGE.

SET ANTENNA TO SHIP:PARTSTAGGED("Comms").

SET ANTENNA_PM TO ANTENNA[0]:GETMODULE("ModuleRTAntenna").

ANTENNA_PM:DOEVENT("activate").

SET ANTENNA_PM TO ANTENNA[2]:GETMODULE("ModuleRTAntenna").

ANTENNA_PM:DOEVENT("activate").

SET ANTENNA_PM TO ANTENNA[1]:GETMODULE("ModuleRTAntenna").

ANTENNA_PM:DOEVENT("activate").

Edited by JD_Tiger
Link to comment
Share on other sites

JD_Tiger:

Yes, if you have 3 antennas. But I see some of them are Dishes and you will also need to target them manually - there is no way to do it via kOS right now.

Sonny_Jim:


set fuelTanks to List().

for i in ship:parts
{
for i1 in i:resources
{
if i1:name = "LIQUIDFUEL"
{
fuelTanks:ADD(i).
break.
}
}
}

I spent 3.5 minutes writing this, it is not that hard to create a workaround for CONTAINS

Edited by Ziw
Link to comment
Share on other sites

I've noticed today that when using STAGE:LIQUIDFUEL with an Interstage Fairing Adapter from Procedural Fairings acting as a decoupler between my stages, kOS will calculate the amount of fuel in the current stage and the stage above it. Therefore, the following staging code is never executed:


WHEN stage:liquidfuel < 0.1 THEN {
STAGE.
}.

For example, say stage 1 has 500 liquid fuel and stage 2 has 100 liquid fuel... when I do PRINT STAGE:LIQUIDFUEL as soon as I launch the rocket, it will output 600, and when stage 1 has used all of its fuel, it will output 100.

Link to comment
Share on other sites

I've noticed today that when using STAGE:LIQUIDFUEL with an Interstage Fairing Adapter from Procedural Fairings acting as a decoupler between my stages, kOS will calculate the amount of fuel in the current stage and the stage above it. Therefore, the following staging code is never executed:


WHEN stage:liquidfuel < 0.1 THEN {
STAGE.
}.

For example, say stage 1 has 500 liquid fuel and stage 2 has 100 liquid fuel... when I do PRINT STAGE:LIQUIDFUEL as soon as I launch the rocket, it will output 600, and when stage 1 has used all of its fuel, it will output 100.

kOS used to use its own complex parts walk algorithm to find all the fuel. Now it just relies on KSP's own API for it. Is there a discrepancy between the fuel shown in the indicators on the side and what kOS says? I.e. when it says there's 100 units left, are the green indicators all empty, or do they also show fuel left? If they also show fuel left then there's not much we can do - that means KSP itself thinks there's fuel for some of the active engines.

If it is showing zero fuel in the indicators when kOS says 100, can you show a screenshot of the game, showing where the 100 units of fuel are coming from (highlight the tank it is counting that it shouldn't be and show the popup for it if you can)? It's hard to diagnose from just the verbal description.

Link to comment
Share on other sites

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