Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

Which "newest version of kOS" do you mean? The pre-release from Github or the publically official ones from curse or kerbalstuff? Currently the official ones aren't working with 0.90 yet, but there's a pre-release on github that is but has some other issues with 0.90 (mostly, not issues where it's broken, but issues where it is thematically clashing with 0.90's career restrictions and allowing you to bypass them - for example setting a maneuver node via kOS, or getting the next predicted encounter with kOS, both do not first check to see if your tracking center upgrade level supports it.)

Edit: just saw your last post show up. Yes, if you're getting complaints about part.uid then you are definitely not running the version that's compatible with 0.90. Part.uid is one of the things SQUAD changed between version 0.25 and 0.90.

Ah ok. I'll check on Github tomorrow.

Link to comment
Share on other sites

My latest code without that period still has the same problem

http://hastebin.com/caqaxojoko.coffee

Or did i remove the wrong period?

No - that looks like the right syntax.

Here's a test about a suspicion I have. BEFORE you run the script, select your target, then run the script and see how it behaves. The target should get de-selected by "set target to body("Duna").", and then you can re-select it. If THAT works, while it doesn't work when you didn't have a target selected beforehand, then I know the problem, and it's an ugly problem with how the target variable works which I never liked. But before I try to explain it, just check and see if that makes a difference. I could be making the wrong guess.

Link to comment
Share on other sites

If I have a target or not before the script runs it switches to duna and when i then select the target i want to select it keeps printing "Please select a target"

So no difference.

Well, then maybe it's still the same problem as I mentioned earlier. You're comparing two different wrappers around the same object - the object is the same but the wrapper objects around it differ. kOS needs better equality checkers for these cases.

Link to comment
Share on other sites

Yes but the thing with the ""+ thing you suggested does not work, and in either case if they are wrapped differently they should not be equal?

""+target makes a object does not exist blabla error

it has to work ive been given the same advice a while ago and it helped.

the problem is somewhere else.

if You compare directly 2 values that are planets like kerbin, duna, mun.. the code will don't work properly, but look what happens when i give it literary some space:

Capture.png

Link to comment
Share on other sites

I want to thank you first for all the work that's gone into this mod - it's certainly changed how I conduct a lot of the mundane aspects of the game (in fact, they're rather fun now).

Anyway, I'm interested in making maps of a lot of different things based on raw data (so as awesome as scansat is, I kinda prefer to generate the stuff myself & have more control) and my latest scheme is to be able to model the radiation belts and magnetosphere simulated in the Interstellar mod. I suspected that since the "Rad." and "|B|" information is displayed in a right-click menu, it might be accessible/loggable via kOS as well, albeit in a slightly more roundabout way than the simple elevation scanner I wrote earlier.

Problem is that I'm quite a noob (even with the useful kOS documentation) when it comes to general coding syntax & such. So far I've only figured out that the partModules in question are FNModuleRadiation and DTMagnetometer, but my attempts to get the fields needed (and ultimately how to call everything up to log the fields I need) have been pretty fruitless. Thanks in advance - any help would be appreciated.

Link to comment
Share on other sites

object reference... ble bla bla... that's just a not selected target, I remember seeing that very often when i programmed my missile.

Steven Mading explained this once to me in this post http://forum.kerbalspaceprogram.com/threads/68089-0-25-kOS-Scriptable-Autopilot-System-v0-15-2-2014-11-19?p=1550611&viewfull=1#post1550611

this is how i understand this problem:

things like target , body are special words, and some times they have a additional wrapper and instead of comparing if x=y we compare if (x^k)=(y^d) and that's a lottery.

thou trial and error I can say that is always safer to do something like this:

instead of set target to body("Duna"). use set t to Duna. this way You eliminate the wrapping in target (since its special) and You unwrap Duna from the Body wrapper. so its easier to predict the number of wrappers in wrappers (wrappercepcion :P )

in line 10 i see Your are checking if duna is duna. so maybe try setting duna to some value first and than comparing. in that way You unwrap unnecessary wrappers.

but first try dooing that simple check i did in that pic i Posted in the previous post maybe its some different strange bug.


set t_info to list().
set finished to false.
set t to Duna.
set COMPAREPLANET to Duna

wait 1.

until finished = true { // Forces you to select a target
clearscreen.
if ( (" " + t ) <> (" " + COMPAREPLANET) ) {
print "Target Acquired".
print "----------------".
print "Target Distance: " + t:distance.
print "Target Heading: " + t:heading.
set heading_up to 90 - vang(t:position, ship:up:vector).
print heading_up.
t_info:add(t:distance).
t_info:add(t:heading).
t_info:add(heading_up).
set finished to true.
}
else {
print "Please select a target".
}
wait 0.2.
}

wait 0.5.

print "You have "+stage:amount+" Missiles remaining".
if (ship:electricity < 20) {
print "You have low electricity".
}

if (ship:heading > t_info[1]) {
until (ship:heading < t_info[1]) {
AG1 on.
}
AG1 off.
}

if (ship:heading < t_info[1]) {
until (ship:heading > t_info[1]) {
AG2 on.
}
AG2 off.
}
print "Gathering Target Info...".

Link to comment
Share on other sites

Thank you so very much! Using a slightly modified version of what you just posted i got it to work :D :D :D


set t_info to list().
set finished to false.
set target to Duna.
set COMPAREPLANET to Duna.
wait 1.

until finished = true { // Forces you to select a target
clearscreen.
set t to target.
if ( (" " + t ) <> (" " + COMPAREPLANET) ) {
print "Target Acquired".
print "----------------".
print "Target Distance: " + t:distance.
print "Target Heading: " + t:heading.
set heading_up to 90 - vang(t:position, ship:up:vector).
print heading_up.
t_info:add(t:distance).
t_info:add(t:heading).
t_info:add(heading_up).
set finished to true.
}
else {
print "Please select a target".
}
wait 0.2.
}

wait 0.5.

print "You have "+stage:amount+" Missiles remaining".
if (ship:electriccharge < 20) {
print "You have low electricity".
}

if (ship:heading > t_info[1]) {
until (ship:heading < t_info[1]) {
AG1 on.
}
AG1 off.
}

if (ship:heading < t_info[1]) {
until (ship:heading > t_info[1]) {
AG2 on.
}
AG2 off.
}
print "Gathering Target Info...".

Link to comment
Share on other sites

Ah so the null reference was just the fact that Target was null. it was correct, not an error. KSP refuses to let you set a target tp the currec SOI body. when you try it refuses and nulls it out.

kOS still needs a check versus null though.

Link to comment
Share on other sites

Hi all, I've been able to write a script to get me all the way to Mun orbit, but I'm having a bit of difficulty approaching the problem of landing. What ways are there with koS to land at a particular area on Mun? Any specific maths involved?

Link to comment
Share on other sites

Problem is that I'm quite a noob (even with the useful kOS documentation) when it comes to general coding syntax & such. So far I've only figured out that the partModules in question are FNModuleRadiation and DTMagnetometer, but my attempts to get the fields needed (and ultimately how to call everything up to log the fields I need) have been pretty fruitless. Thanks in advance - any help would be appreciated.

I have been toying with this before without much results, but in response to your post I decided to fiddle with it some more. I think I have something that is a start, though please do not ask me how I got this to work - I have only vague ideas and fanciful stories :D You need to label your part (magnetometer) manually as yourname and you need to remember to switch the magnetometer on before running these commands:

set partlist to ship:partstagged("yourname").
set foo to partlist[0]:getmodule("DTMagnetometer").
print foo:getfield("|b|").

That should print the |b| value you are looking for :)

If you remove the |b| part from between the quotation marks you will get an error message, but also other possible commands you can issue to readout different values. It might be that kOS needs to be in verbose mode to see that. You can insert those in the same place |b| was in the code and you should get the value you want. You can set some fields by using


foo:setfield("fieldname", value).

But that does not seem to work when it is a KSP action.

Edited by Camacha
Link to comment
Share on other sites

stage:amount returns 0 even when i have 4 stages, any ideas?

EDIT:

https://gfycat.com/OblongSnoopyGreendarnerdragonfly

Just need to get the actual missile to hit and i'm done.

There is no such suffix as STAGE:AMOUNT, and sadly the stage values are written in a way where any suffix you use that is not recognized returns zero.

STAGE:thingy is supposed to tell you how much of resource thingy is available to the current stage.

Link to comment
Share on other sites

Thanks very much, Camacha; it looks like the main thing I was missing was the bracketed element and the proper field name.

For anyone interested, I modified Camacha's code a bit to log the value every second to a .txt file for later importing into excel. It's probably sloppy, but gets the job done for now. My hope is to eventually do away with the archaic Logomatic and Flight Recorder :confused:


UNTIL ship:electriccharge < 50 {
WAIT 1.
SET partlist to ship:partstagged("mag"). //be sure to tag the part
SET foo to partlist[0]:getmodule("DTMagnetometer").
SET output to foo:getfield("|b|").
LOG output + "," + round(longitude,2) + "," + round(latitude,2) + "," + round(altitude,2) to magb.txt.
}.

Link to comment
Share on other sites

For anyone interested, I modified Camacha's code a bit to log the value every second to a .txt file for later importing into excel.

Can't you use the .csv format? It should be pretty much the same, but is intended for spreadsheet use. I think I made a logger that used it in the kOS dark ages :)

Let me know what data you are able to coax from KSP via this method and how you process it. Loggers can be a pretty interesting use of kOS and the data you are collecting could be turned into pretty snazzy information indeed.

Link to comment
Share on other sites

How do i get my ships horizontal heading? ship:heading returns something else. Don't even know what

Getting clean cut readings for roll, pitch and heading remains an issue due to the weird KSP internal reference frame.

I don't see kOS in CKAN, yet I saw in a previous post support for it was added. Am I supposed to be able to install kOS via CKAN?

The 0.90 version is still considered experimental, so it is not officially available through CKAN.

Edited by Camacha
Link to comment
Share on other sites

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