Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

No, where are you running into nulls?

Tigermisu was talking about undefined variables, which is slightly different from a variable which is defined and who's value is null.

For example this code works:


set x to 7.
print "value is " + x.

But remove the 'set x' line and it errors out:


// set x to 7.
print "value is " + x.

The question was whether there was some way to do a thing like this:


if isdefined(x) { print "value is " +x. } else { print "x doesn't exist yet". }.

Link to comment
Share on other sites

1.- How are the parameters passed/called?

RUN program(p1,p2).

passes arguments to the running script.

DECLARE PARAMETER bar, foo.

at the top of the invoked script to assign p1 to bar and p2 to foo.

2.- It was just that one of my scripts needed a variable from a previous one, but I wanted to to ignore the call if the variable wasn't defined (Previous script wasn't run) and assign a rudimentary value.

yeah, that is annoying. We dont have any tools for accessing the state of variables that might be undefined or null.

3.- Hmm, would that work for engines that are yet-to-be-activated-in-a-future-stage?

Soon I hope to have the stage available for each part. Until then i am not sure you could get the ISP for the engines in an arbitrary future stage.

Link to comment
Share on other sites

RUN program(p1,p2).

passes arguments to the running script.

DECLARE PARAMETER bar, foo.

at the top of the invoked script to assign p1 to bar and p2 to foo.

Woah what? Really? How out of date are the docs? I realize documentation is a hard thing to keep up to date :/ This should at least be mentioned in the section on RUN though. Also, I still don't know how to use the added ability to get/set the warp mode. I'm looking to warp to 2x physics and can't always rely on the craft moving fast enough to automatically jump into physics warp by just calling set warp to 2.

Link to comment
Share on other sites

Woah what? Really? How out of date are the docs?

I had no idea it was that badly documented before I got my hands on it. The parameters aren't mentioned at all. I'll add it to the TODO list. It's not due to being out of date. It's just not well documented.

Link to comment
Share on other sites

Yea docs are a pain to both write and maintain. Look forward to the updates there

But I would still like a quick answer on the warp syntax so I can get out my v1.0 of Rover Driver... I have a workaround for the targeting bug.

Link to comment
Share on other sites

You can get the constant e this way:

print "Value of e is " + constant():e.

Any value can be exponented with "^", so you can do:

(constant():e)^x.

I just saw that constant() is missing from the docs as well. I added it as an issue.

Link to comment
Share on other sites

so... unless I completely missed something, this:

print stage:liquidfuel.

Should return how much liquid fuel I have, listed by stage?

Using print ship:liquidfuel. works just fine, and returns the proper number. the stage listing appears to do nothing, always returning 0. Am I missing something?

Link to comment
Share on other sites

stage:liquidfuel is supposed to be how much fuel is in the current stage. If you have no active engines, it returns zero. If you do have active engines and they have fuel, and it still says zero, then that's a bug.

Link to comment
Share on other sites

Hmmmm. In order to learn the system I am writing a small "testing" script. So when a new vessel is on the pad, I "run test." and it will cycle through tests of power levels, fuel, etc, etc.

Two things about it...

First, you were right about the "active" stage. Any way to have it look at a future stage? (IE, the stage that I haven't activted yet, stage 0 when on the pad)

Second, I thought I saw something about adding parameters when running a program (IE, I could run test (1,2) to have it use those variables.) Is there any documentation on how to use this? I would like to use 1 as a variable for fuel, 2 for battery (to give the values I have the test script check for).

would it be something along the lines of "run test(fuellevel, batterylevel)."? If so, how do I then use those variables? - Nevermind, found the post :)

Thank you for your assistance! :D

Edited by kalor
Link to comment
Share on other sites

It's very hard to predict future stages because of the ability to perform weird staging methods. If every stage was simply a fuel tank and an engine and a separator it would be easy - but there are stages that siphon fuel with yellow hoses, and have fuel feeds taking fuel from tanks on the other side of a decoupler - these make it very hard to predict the fuel level in future stages. It's messy enough just to get the values of the current stage. (The algorithm is to walk the list of parts starting from each engine that is currently active, summing up all the fuel that is 'suckable' by that engine, and culling out all the duplicate fuel that you get from having multiple engines sucking fuel from the same tank.)

One other thing. Is it possible to print out the available memory on the selected volume?

I doubt you'll ever run into a memory cap. There hypothetically is one, but it would be quite hard to actually reach it. The game doesn't have a way to tell you how many bytes of ram you're using. The disk space will be a problem long before the memory would be.

Link to comment
Share on other sites

Can someone explain to me what the reference frame for rotation is? The game seems to have issues for me if I try to just enter some absolute direction to face in, at times anyways. Especially if I am trying to control roll, sometimes it just spazzes out entirely in that case.

Link to comment
Share on other sites

Ok, after playing with this some, I love it. I've done nothing today but start working out an auto-launcher :P

When I meant printing out memory on the selected volume I meant on the volume in game :D Part of the script I was writing was a sort of POST, much like a home desktop goes through. Mostly, just to see what I could do with the language and interface, and a "memory test" was one of the components I was looking at. Mostly for in the future, as programs become more sizable, determining when I need, in script, to start unloading/moving files and such between banks.

So far, realisitically, all I have accomplished is the flashing of lights, lowering of gears, and a straight vertical lift to escape velocity. But... that beats the first try, which was smashing into the ground. Hopefully with a lot of (bugging of better scripters!) I mean help, I will get better :P

One question I have, as I can't seem to start a turn. Do I have to UNLOCK steering, in order to LOCK it to something else? Can't get the autopilot to do a gravity turn to save my Kerbal. EDIT: Ok, now I am confused. In launch 1, I did NOT unlock the steering, and it just flew straight up. In launch 2, I unlocked the refinement turn... one at 40KM altiitude, but left the initial turn, at 7KM altitude locked. In this launch, BOTH turns were made with no issue. Nothing else was changed within the code. I'm curious what I missed?

Edited by kalor
Link to comment
Share on other sites

Beats me, post your code perhaps? I'm still confused about orienation myself. I can do gravity turns, but thats about it. There doesn't seem to be any absolute rotation reference frame somehow.

Link to comment
Share on other sites

I have a very, very rough orbital autopilot done, but the circularization sucks a bunch. Last time it was 1.3Mm Ap, 77KM Pe. Now I'm working on a circularization script to run after the orbit is made, to get it at least somewhat closer.

With the rotation frame, you mean as in turning the ship, IE, "turn left"? or "turn 10 degrees *direction*"?

Also, is there the ability to write things to a text file somewhere? I would like to try to make a flight recorder of sorts, but not seeing any kind of file IO ability anywhere.

Edited by kalor
Link to comment
Share on other sites

I mean like, why does lock steering break when you feed it an absolute direction, for instance.

If you just say:

lock steering to R(0,0,-90).

It will break lock steering. No roll will occur. It doesn't know what to align to for some reason.

This is an issue because in my case I kinda want to dock (in a manner of speaking), and if I cant align my RCS thrusters to velocity components then it will be pretty much impossible to do anything useful with them if I'm using linear thrust.

Link to comment
Share on other sites

Both the page about Directions (like R(a,b,c) ) and Vectors (like V(a,b,c)) have links to a page describing the coordinate system of KSP:

http://ksp-kos.github.io/KOS_DOC/ref_frame/index.html

This is messy behavior inherited from the main base game. The actual coordinate system of KSP itself doesn't really stay put in a rational way, owing to all the weird tricks they did for optimizations.

Lock steering to R(0,0,-90) is a case of gimbol lock, I think, given the messy way things work in Unity (where the rotations occur in a very strange order, I think it was Around Z, then Around X then Around Y, if I remember correctly, thus making controlling the roll actually quite hard to do).

At any rate, the rotations expressed in R(a,b,c) are, sadly, based on KSP's native system, not the craft. You're not rolling around the CRAFT's Z axis when you put a value in the 3rd argument to R(). You're rolling around the Universe's Z axis, which sadly keeps moving so I can't give a straight answer what it means all the time.

The easiest way I've found to deal with the mess if you want to think in axes rotated with the ship's current facing, is this:

lock shipx to ship:facing * V(1,0,0).

lock shipy to ship:facing * V(0,1,0).

lock shipz to ship:facing * V(0,0,1).

From now on the unit vectors shipx, shipy, and shipz are unit vectors expressed in KSP's messy native coordinate orientation, but they are describing the directions that the X, Y, and Z axes would be if they were oriented with the ship.

Therefore you can use dot products with them to convert any vector expressed in KSP's messy native coordinate orientation into a vector expressed in a ship-relative orientation, like so:

// Assume someVec is a vector in KSP messy native coords - like SHIP:VELOCITY:ORBIT for example.

set someVecShipFrame to V( vdot(shipx,someVec), vdot(shipy,someVec), vdot(shipz,someVec) ).

Now someVecShipFrame is a vector expressed in an alternate frame of reference in which X,Y, and Z are shipx, shipy, and shipz respectively.

Link to comment
Share on other sites

I have read that article in the past, it didnt really help. That being said, if what you just described works then I shall worship you for all eternity. And probably post a cool video of my thing working.

e: This would save me much time, do the inbuilt scalar projections produce signed output? e2: Nix that, I went back in and misread the documentation. Looks like ill be using dot product.

Edited by QuakeIV
Link to comment
Share on other sites

any1 got a tutorial or something for basic programming, i really enjoy the mod, but i cant quite make anything i was, oh and i did the tutorial on the kos wiki i can make a rocket get into orbit but i cannot set a specific speed not to go too fast and would like to know if there is a way to make like a program with KOS that would start up and ask me the actual orbit i would like to get to and so it would make the necessary calculation

Link to comment
Share on other sites

Yes, basic programming tutorials are everywhere, for basic Kos ones see the wiki or the videos.

And nice dream, but wont work*. Best you can do is write up a set of them for different altitudes.

*It might, but it might be hard, certainly harder than changing two lines of code and calling it a new file.

Oh, and quake? Kudos on actually codeing it.

Link to comment
Share on other sites

It will totally slow your game, but it works (at least on my PC)! A 'kOS fullscreen animated map'! Hehe.

Script shows "heightmap" of current body, zooming in to ship:geoposition. Great to have latlng:terrainheight!:cool: Finally some sort of situational awareness. Now working on pathfinding for rovers in kOS. There goes my precious time...

Symbol table for height display is for demonstration purpose. If your kscii art is better than mine, go ahead and optimize. :P


set offset to ship:geoposition.
set scale to 1.0.

set symbols to list().
set symbols:add to " ".
set symbols:add to ".".
set symbols:add to "-".
set symbols:add to "+".
set symbols:add to "x".
set symbols:add to "A".
set symbols:add to "B".
set symbols:add to "C".
set symbols:add to "D".
set symbols:add to "E".
set symbols:add to "F".
set symbols:add to "G".
set symbols:add to "H".
set symbols:add to "I".
set symbols:add to "J".
set symbols:add to "K".
set symbols:add to "L".
set symbols:add to "M".

set vScale to 2000/symbols:length. // 2000 is upper limit, higher is cut off

set x to 0.
set y to 0.
set screenDimX to 49.
set screenDimY to 35.
set nSymbols to symbols:length - 1.

clearscreen.
set config:ipu to 100000. // use carefully

until scale < 0.001 {
until y>screenDimY {
set gpLat to 90-(y/screenDimY*180).
set gpLat to scale*gpLat + offset:lat.
until x>=screenDimX {
set gpLng to (x/screenDimX*360)-180.
set gpLng to scale*gpLng + offset:lng.

set h to latlng(gpLat,gpLng):terrainheight.
set h to max(-1,h/vScale).
set h to round(h+.5,0).
set h to min(nSymbols,h).
set w to symbols[h].

print w at(x,y).
set x to x+1.
}
set y to y+1.
set x to 0.
}
set y to 0.
set offset to geoposition.
set scale to scale*0.98.
}
set config:ipu to 100. // don't forget.
wait 2.

Link to comment
Share on other sites

hello there, i am trying to make a "surface info" screen for my ascent little prog, the issue i get is that the number just keep flickering and i would like somtething that do like a real MFD like this one:

here is what i use atm, way far from completion, maybe you could help me,


//90 km orbit.

// Launch print
// *******************************************************************
// *******************************************************************
clearscreen.

print "Launch Mode" at (19,1).
print "==================================================" at (0,2).
wait 1.
print "90 Km orbit chosen" at (16,4).
wait 1.
print "Launch in..." at (19,6).

set countdown to 2.

when countdown = 2 then
{
lock throttle to 1.0.
lock steering to up + R(0,0,180).
}.

until countdown = 0
{
print countdown at (24,8).
wait 1.
set countdown to countdown -1.

}.

clearscreen.

print "Launch!" at (22,15).

// *******************************************************************
// *******************************************************************

stage.
wait 1.

clearscreen.

until altitude > 10000
{
run surfaceinfo.
}.

wait until apoapsis > 15000.

the actual surface info:


//surface info


// writting data on 1st column start at 15
//wrtiting data on 2nd column start at 39

print "Surface info" at (19,2).
print "*========================*=======================*" at (0,3).
print "| | |" at (0,4).
print "| altitude: |inclination: |" at (0,5).
print "| Ap: | Eccencity: |" at (0,6).
print "| Time to Ap: | Speed: |" at (0,7).
print "| Pe: | TermVel: |" at (0,8).
print "| Time to Pe: | SurfGrav: |" at (0,9).
print "| | |" at (0,10).
print "*========================*=======================*" at (0,11).

print round (altitude) at (15,5).
print round (apoapsis) at (15,6).
print round (ETA:apoapsis) at (15,7).
print round (periapsis) at (15,8).
print round (ETA:periapsis) at (15,9).

P,S, im just beginning with KOS and programming so dont be too harsh on judging me XD

thank you in advance!

Link to comment
Share on other sites

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