r/Kos•
MingTea

PEGAS kOS script crashing

Big thanks to u/r9i for his work on PEGAS kOS scripts.

I have not been able to sucessfully use it yet and was hoping someone might be able to point out what stupid mistake I might be making. I have the impression I'm misunderstanding something, as UPFG does not seem to reliably take over an already burning stage.

The biggest problem is that the script crashes at some point, but I'm hoping it might be due to me misconfiguring something.

I've put up a video of a launch as an example, with timestamps in the description for the interesting moments. I've also added a video of the same vehicle being launched successfully with Mechjeb. My vehicle config script can be found on pastebin.

I'm running all of this in kerbal 1.3.1 with RSS/RO and RP-0 dev, following Bornholio's install order in the Golden Spreadsheet

Posted May 24, 2018, 2:33 PM UTC

16
DunbaratuDeveloper•

Well I don't know the PEGAS script in detail, but the error message was "Tried to push NaN onto the stack" while executing this expression:

Li:ADD( ve[i]*LN(tu[i]/(tu[i]-tb[i])) ).

NaN means Not-a-Number and it means that somewhere in the math it had a value that cannot be expressed in an integer or a Double because it's either not a Real Number, or undefined for the math operation attempted.

There are only two possible places in that expression where NaN is possible:

1 - There is a division operator "/" - it can return NaN if you divide zero by zero. (divide a nonzero by zero and it will return an Infinity. Divide zero by a nonzero and it will return zero, but divide a zero by a zero and it will return NaN.)

2 - There is a natural log function LN(...) - ln(x) is undefined for cases where x <= 0, so it will return NaN.

One of those two things is happening. To find out which, you'll have to print out the values used in the expression just before it calls it, to find out what they were at the moment it crashed.

i.e, just before the:

Li:ADD( ve[i]*LN(tu[i]/(tu[i]-tb[i])) ). 

on line 66 of 0:/pegas/pegas_upfg.ks, insert this:

LOG "ve[i] = "+ve[i] + ", tu[i] = " + tu[i] + ", tb[i] = " + tb[i]  TO "0:/debugpegas.txt".

That should help tell you what the problem is by letting you see the values just before the moment it crashed, at the very end of that log file "0:/debugpegas.txt".

It's going to either be that tu[i] and tb[i] are both zero, or that something causes (tu[i] / tu[i] - tb[i]) to be negative or zero.

2
MingTeaOP•

Thank you for the detailed hint, I'll try further to get it to work

1
Marsforthewin•

Got the same issues with PEGAS. The crashes are due to some numerical errors as u/Dunbaratu wrote. I did not find a particular scenario that would trigger it.

The way I solve this is to tweak the UPFG start time. If it does not work I adjust the masses of the second stage a little. Somehow that is enough to work around the numerical issues.

2
Marsu6996•

Not sure if it’s that but for your first stage did you put the mass of the entire vehicule? Not just the first stage ?

1
MingTeaOP•

Thanks for the tip, but yes. I used the given atlas and saturn boot scripts as a guide. The entire vehicle (2 stages) was given.

1
NavXIII•

Does your ship pitch hard down after pegas takes over or once it stages and pegas is in control?

1