Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

Can anyone target ships via script? it seems broken and I know some of my scripts used to work.

for instance:

list targets in targetobjects.

set target to targetobjects[0].

fails with a vessel (ship) not found

even a direct:

set target to vessel("Miner Vtol").

will fail. However:

set target to body("Mun").

will work just fine. Seems like something broke with ship targeting for me. Does anyone else have this problem?

also, I remember I used to be able to switch ships and have kos run on the one I'm not controlling. It seems to turn off telling me it's lost it's target. (I initially set it manually.) But if I go back the ship I targeted it still is...

SET TARGET TO "name", works for me. Setting and changing target on an uncontrolled ship gave me problems, I'm pretty poor at kOS though and assumed it was me doing it wrong.
Link to comment
Share on other sites

My newest problem is, a very shy planet. For some reason KOS does not see Duna and because of that my probe doesn't know when to stop accelerating. Encounter command and :patches suffix bought have this issue.

http://obrazki.elektroda.pl/3865724400_1415569007.jpg

It think you're running into this problem:

https://github.com/KSP-KOS/KOS/issues/252

The fix will be out with 0.15, which should be ready "any day now".

Link to comment
Share on other sites

Hey, I just started actually trying to use this to fly most of my rockets, and I am having a great time with it.

However, I noticed that ship:angularvel:roll seems to return a value proportional to yaw rate, and ship:angularvel:yaw seem to return roll rate.

That little switch-up threw me off for a couple hours while trying to get my raw steering setup to run.

Link to comment
Share on other sites

Alright, I'm trying to create my first simple useful program in kOS.

The Goal of the program is to toggle actiongroup 2 (toggle watersplitter) when the ships power get's below 10000 and toggle it again when power gets above 10000. The program should run until I turn off the core.


SET WaterSplitterActive TO TRUE.

UNTIL FALSE
{

WHEN WaterSplitterActive = TRUE AND SHIP:ELECTRICCHARGE < 10000 THEN {
Toggle AG2.
SET WaterSplitterActive TO FALSE.
PRESERVE. }.

WHEN WaterSplitterActive = FALSE AND SHIP:ELECTRICCHARGE > 10000 THEN {
TOGGLE AG2.
SET WaterSplitterActive to TRUE.
PRESERVE. }

WAIT 0.001.
}.

It doesn't appear to have any effect when I run the program (no error message and its waiting).

So what am I doing wrong?

EDIT:

Obviously, I seem to be using WHEN .. THEN in a wrong manner, I replaced them by a simple IF .. ELSE

SET WaterSplitterActive TO TRUE.

UNTIL FALSE
{

IF WaterSplitterActive = TRUE AND SHIP:ELECTRICCHARGE < 10000 {
print "Deactivating Watersplitter".
Toggle AG2.
SET WaterSplitterActive TO FALSE.
}.

IF WaterSplitterActive = FALSE AND SHIP:ELECTRICCHARGE > 10000 {
print "Activating Watersplitter".
TOGGLE AG2.
SET WaterSplitterActive to TRUE.
}
.

WAIT 0.001.
}.

this one does seem to work at intended. Still I wish to understand how to use WHEN .. THEN correctly

Edited by FreeThinker
Link to comment
Share on other sites

Alright, I'm trying to create my first useful program in kOS.

The Goal of the program is to toggle actiongroup 2 (toggle watersplitter) when the ships power get's below 10000 and toggle it again when power gets above 10000. The program should run until I turn off the core.


SET WaterSplitterActive TO TRUE.

UNTIL FALSE
{

WHEN WaterSplitterActive = TRUE AND SHIP:ELECTRICCHARGE < 10000 THEN {
Toggle AG2.
SET WaterSplitterActive TO FALSE.
PRESERVE. }.

WHEN WaterSplitterActive = FALSE AND SHIP:ELECTRICCHARGE > 10000 THEN {
TOGGLE AG2.
SET WaterSplitterActive to TRUE.
PRESERVE. }

WAIT 0.001.
}.

It doesn't appear to have any effect when I run the program (no error message and its waiting).

So what am I doing wrong?

The WHEN clauses are events, not tests. Move them out (and before) the UNTIL loop.

Link to comment
Share on other sites

I've had some issues with the throttle I'd like to discuss here while we are on the subject of LOCK ... When I hit the X key prior to a launch to kill the throttle, then activate an ascent script, even if I do


LOCK THROTTLE TO 0.
UNLOCK THROTTLE.

...I end up with the engine kicking back to life at 50% power... I've made a workaround by doing a kill switch of sorts, by doing


FOR eng IN lseng { // List of engines
SET eng:THRUSTLIMIT TO 0.
}.

which kinda works... but you have to remember to rekill the engines with the X key and then push back the thrust limit slider to 100 when you regain manual control... So am I the only one with this issue?

EDIT:

I've just tried out with my 0.15 compile, and it seems to be gone ... I'll have to do further tests but right now I am scratching my head on trying to solve some other bugs...

Edited by Cairan
Link to comment
Share on other sites

Alright, I'm quite pleased with the fact that I have a functional script. However I want to improve it. Right now I'm using the following script to get my ship current ships power.

SHIP:ELECTRICCHARGE

However, what I really want to know is my ships electriccharge percentage.

I guess I need to collect this information from all the parts on my ship.


SET totalMaximumElectricCharge to 0.
LIST PARTS FROM SHIP IN partsList.
FOR part in partsList {
FOR resource in part:RESOURCES
{
IF resource:NAME = "ELECTRICCHARGE"
{
SET totalMaximumElectricCharge TO totalMaximumElectricCharge + resource:CAPACITY.
}.
}.
}.
PRINT "The Maximum ElectricCharge is " + totalMaximumElectricCharge.

SET electricChargePercentage TO (SHIP:ELECTRICCHARGE / totalMaximumElectricCharge) * 100.
PRINT "The current Electriccharge percentage is " + electricChargePercentage.

perhaps this could work, but it would be helpfull if that was made easier if there was language support to achieve the same with the following code.

SHIP:RESOURCES:ELECTRICCHARGE:CAPACITY

EDIT:

It appears there is an existing way:


LIST RESOURCES IN resourcesList.
FOR resource IN resourcesList {

if resource:NAME = "ELECTRICCHARGE"
{
PRINT "Resource " + resource:NAME + ": value = " + AMOUNT +
" which is " + ROUND(100 * resource:AMOUNT / resource:CAPACITY) + "% full.".
BREAK.
}.
}.

Edited by FreeThinker
Link to comment
Share on other sites

Hi. My problem is a little bit to complicated for my English level so I'll explain it with a simple example:

My program runs in a infinite loop.

at time1 i want to check my latitude.

I set my latitude from time1 to "x".

some time passes

at time2 i want to check my latitude. (again)

I set my latitude from time2 to "y".

i check the difference in my latitude(x-y).

i get a number from it.(lets call it z)

I dont know if its because of the infinite loop or something different but my "z" is always 0. For this simple example i know how to make the code run exactly once. I just use, a additional variable and a IF.

but in my real problem (not the example) i want to store latitude, longitude, angle of slope and (after 0.15 update) Karbonite abundance. and not just check them once or twice but a little bit more, and that is:

A) to much code for a IF method. B)not flexible C) just insane.

I hope the thing i said have some sense. So my question is:

How i can store large amount of data, using as less code as plausible.

Link to comment
Share on other sites

Use lists...


SET KarbMap TO LIST().
SET idx TO 0.
UNTIL ... {
SET KarbMap:ADD TO LIST().
SET KarbMap[idx]:ADD TO SHIP:LATITUDE.
SET KarbMap[idx]:ADD TO SHIP:LONGTITUDE.
SET KarbMap[idx]:ADD TO Slope. // calculated previously...
SET KarbMap[idx]:ADD TO KarbQty. // get the value somewhere before this...
SET idx TO idx+1.
}.
...
FOR KarbData IN KarbMap {
pRINT "Lat "+KarbData[0]+" Long "+KarbData[1]+" Slope "+KarbData[2]+"Karbonite concentration:"+KarbData[3].
}.

...havent tried this specific code but it should work...

Link to comment
Share on other sites

I dont know if its because of the infinite loop or something different but my "z" is always 0.

Are you allowing any time to pass between your two measurements of latitude?

In a real computer, it's physically impossible to have a program instruction finish in literally zero amount of time. Between when the instruction began and when it ended, time had to pass or else the state of the universe (which contains the bits in memory) cannot have changed.

But this is a place where the kOS simulated computer is very different from reality.

The Unity software that Kerbal Space Program uses simulates the universe by updating things in quantum time. During the tiny slices of time the simulated universe is split into, nothing changes, not your position, not your velocity, and not even the clock. The kOS program runs many instructions between these simulated jumps in time.

In order to do something where time has to pass and you have to take a new reading that MUST be at a different time, try doing this in between your 'x' latitude reading and your 'y' latitude reading:


set thisTime to TIME:SECONDS. // record the universe's current time-stamp.
set x to latitude.
wait until time:seconds > thisTime // wait until an update in which the time stamp moved.
set y to latitude.

Now you will have an x and a y that were taken at different times in the simulation.

Note, currently kOS runs once every Update(), not once every FixedUpdate(). In simple terms this means it's tied to your animation framerate instead of being tied to the world's physics. People with faster framerates may end up running more than one Update() in a row in which the universe has not moved yet.

In the past I used to say that doing WAIT 0.001 is sufficient to guarantee that the universe has moved. I was wrong. To really be sure you have to use the timestamp example shown above, just in case you have a fast enough frame rate to do two Updates() back to back before the world of physics has moved.

IMO, this needs to be addressed in a future update. perhaps we need a simple WAIT UNTIL PHYSICS for when you need to guarantee that a new physics tic has occurred.

Edited by Steven Mading
I was in github so long I used ``` instead of [code] tags.
Link to comment
Share on other sites

Thank Cairan this is something i can start working with.

Are you allowing any time to pass between your two measurements of latitude

Now when You mention it... there is a high chance the code needs to wait a bit longer.

Edit:

I dont know it is a bug, but everytime i use vecdrawargs() my ram usage constantly goes slowly up to 100% and crashes the game.

Edited by Trewor007
Link to comment
Share on other sites

IMO, this needs to be addressed in a future update. perhaps we need a simple WAIT UNTIL PHYSICS for when you need to guarantee that a new physics tic has occurred.

I concur... And maybe also a physics update trigger... as in WHEN PHYSICS THEN { ... }. which could be transparently internally be something along the lines of (TIME:SECONDS - lastphysicsupdatetime ) >= 0.04 ... where 0.04 is the default physics delta-t, is there a way to query Unity/KSP for this value which we can set in the game settings?

Thinking about it, one could LOCK PHYSICS TO MIN(1,FLOOR((TIME:SECONDS-LASTPHYS) / 0.04 )). which would yield 0 or 1 depending on if a physics update tick has passed or not since the last time LASTPHYS was set to TIME:SECONDS. Then when you get in your loop, the first thing you do is SET LASTPHYS TO TIME:SECONDS.


SET LASTPHYS TO TIME:SECONDS.
LOCK PHYSICS TO MIN(1,FLOOR((TIME:SECONDS-LASTPHYS) / 0.04 )).
...
WHEN PHYSICS THEN {
SET LASTPHYS TO TIME:SECONDS.
//stuff that needs to be done at each update tick...
PRESERVE.
}.

...just tested it. It works. 8-)

Edited by Cairan
Link to comment
Share on other sites

set line0 to duna:position:vec.set line1 to ship:facing:vector.
set katprzod to 90-vang(line0,line1).print katprzod at(0,24).

With the code above i can now check the slope angle in front and behind my rover.

what im looking for is a way to build a vector sticking out from the side of my rover and responding to the rovers roll (Q E).

Link to comment
Share on other sites

http://steamcommunity.com/sharedfiles/filedetails/?id=340629493

Really? this all the precision you can get out of kerbal? I wanted to make a sky crane but the the position kos tells it to go is way off on where the crate actually is...

Is there any way to get better precision? The red line represents the 2 positions subtracted one another so I know for a fact that the spot is where the game (or at least kos) says it is. (also, where it stops is where it goes into the terrain.)

Or is it at least possible to cheat a bit and set the position of the object where the game thinks it is?

So after further experimenting I think the position is pointing to where the object would be if it was on the surface of the water... Any one know of a way to actually get an accurate position of an object sitting on a large mountain?

Edited by ouch
Link to comment
Share on other sites

http://steamcommunity.com/sharedfiles/filedetails/?id=340629493

Really? this all the precision you can get out of kerbal? I wanted to make a sky crane but the the position kos tells it to go is way off on where the crate actually is...

It is impossible to tell what the complaint is without seeing the script code you're talking about. What were the vectors that you were drawing?

Link to comment
Share on other sites

here is the code for the vector lines:

SET anArrow2 TO VECDRAWARGS( v(0,0,0),target:position-ship:position, rgb(1,0,0), "Target Heading", 5.0, true ).

SET anArrow3 TO VECDRAWARGS( v(0,0,0),(-1*ship:velocity:surface), rgb(0,0,1), "Surface Velocity", 5.0, true ).

SET anArrow4 TO VECDRAWARGS( v(0,0,0),target:direction:vector, rgb(1,1,0), "Target Direction", 5.0, true ).

these run forever in an "until abort" loop. And ignore the label on the red one, it was the heading, I just quickly replaced the target heading with the position subtraction to see where the game was telling my craft to go.

And the green one was an experimental path finding vector that didn't work out.

it's also worth noting that when I used jeb to push the box the line followed it's movements precisely, which leads me to believe it's either pointing at a spot at water level or something else entirely...

Edited by ouch
Link to comment
Share on other sites

here is the code for the vector lines:

SET anArrow2 TO VECDRAWARGS( v(0,0,0),target:position-ship:position, rgb(1,0,0), "Target Heading", 5.0, true ).

There were some problems with this but I'd fixed it in a code commit supposedly merged in on Sept 18. Are you on version 0.14.2?

Link to comment
Share on other sites

yep the version file says it's 14.2.

come to think of it here, this might help you track down the issue:


clearscreen.
list targets.
list targets in tar.
set arrows to list().
set x to 0.
for t in tar
{
SET arrows:add TO VECDRAWARGS(v(0,0,0), t:direction:vector, rgb(1,0,0), t:name, 5.0, true).
}
for t in tar
{
set target to t:name.
set arrows[x]:vector to t:direction:vector.
set arrows[x]:color to rgb(0,1,0).
set arrows[x]:scale to 10.

//SET pointything TO VECDRAWARGS(v(0,0,0), t:direction:vector, rgb(0,1,0), t:name, 10.0, true).
wait 2.
set arrows[x]:vector to t:direction:vector.
set arrows[x]:color to rgb(1,0,0).
set arrows[x]:scale to 5.
set x to x + 1.
}.
for arrow in arrows
{
set arrow to "".
}.
set arrow to arrows:clear.

creates red arrows pointing at each target, and the cycles through them making the arrow green and larger 2 seconds at a time. I made it when I was having issues targeting stuff but might come in handy for this.

Edited by ouch
Link to comment
Share on other sites

yep the version file says it's 14.2.

come to think of it here, this might help you track down the issue:

If what you're reporting is true, it certainly does look like a bug I need to look into, as the vecdraw stuff was mostly my fault. I don't see the effects you're seeing when I try, but I will try to reproduce the effect when I can. It might require that I get an entire copy of your saved game and craft file to try to mimic the situation as precisely as I can.

But, we're in a race against time to try to get out v0.15 RSN because of an upcoming thing that might interfere with @erendrake's free time. There are a lot of nice changes in 0.15 that are a shame they're not out there yet to be used by all the script writers. I promise I'll take a look at this bug in more detail once v0.15 is out, but at the moment getting v0.15 takes first priority.

Link to comment
Share on other sites

Yeah there is definitely a problem here.

take a look at this:

http://cloud-4.steampowered.com/ugc/53243610307866655/3A13CFB12778276D3DA2E6BA7CAEAB881E1EBA07/

In this picture I have 3 rovers pointing to the exact position where KOS thinks all objects in the world are.

As you can see all 3 rovers thinks Enmy Kerman is in a different position. These positions seem to change depending on the rovers orientation in the world.

Here is the code each rover is running: (note only the color was changed for each rover.)


clearscreen.
list targets.
list targets in tar.
set arrows to list().
set x to 0.
for t in tar
{
SET arrows:add TO VECDRAWARGS(v(0,0,0), t:position-ship:position, rgb(1,0,0), t:name, 1.0, true).
}
until abort
{
for t in tar
{
set arrows[x]:vector to t:position-ship:position.
set x to x + 1.
}.
set x to 0.
}.
for arrow in arrows
{
set arrow to "".
}.
set arrow to arrows:clear.

I know you said you guys are working on new stuff right now but, won't this throw off orbital projections and well... Just about everything else? Knowing where stuff is, is pretty important...

Do you guys an updated version of KOS that I can test out for you?

Edited by ouch
Link to comment
Share on other sites

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