Jump to content

kOS Scriptable Autopilot System 0.9


KevinLaity

Recommended Posts

That would be strange, because in the demo video of kOS, Kevin bases it off of the total remaining fuel left in the rocket. Maybe that has something to do with the first stage being radially attached. No idea, but I'll try your way.

If you are like me then I tend to change fuel/oxidizer amounts in tanks to more accurate volumes for their sizes (sometimes gallons, other in liters). Not to mention that I will change the burn ratios on engines to match those we use on earth. For that reason even if you were to put amounts for fuel and oxidizer that you think that will be used evenly in an engine, I tend to make my vehicles oxidizer deplete first depending on what I have set for ratios. So you may be reading your liquidfuel amounts with your line of code but running out of oxidizer first which the program never sees if you do not have a line for that as well. Here are a few lines of code I have that works perfect for me that sort of works like an oxidizer gauge.

wait until stage:oxidizer < 650.
print "Lox 5% Sensor".
print "".
wait until stage:oxidizer < 390.
print "Lox 3% Sensor".
print "".
wait until stage:oxidizer < 300.
lock throttle to 0.

Link to comment
Share on other sites

I've used Damned Robotics and the values it saves are global to everything. That's why it doesn't support action groups. I'm trying to find a way to save and load data into a craft file at the time it's saved or loaded in the VAB.

That way, you could one class of ship that always gets launched with the needed programs loaded, and another class of ship loaded with a completely other set of programs.

Infernal Robotics supports action groups:

ir_actiongroups.jpg

I only briefly toyed with DR, but I've used Infernal Robotics for awhile and while group names are global, group assignment (and action groups) are all craft specific.

Link to comment
Share on other sites

Hmph... missing textures.

2cgbm8n.jpg

The two images are in the legacy plugin folder at: D:\Games\KSP 0.21.1\Plugins\PluginData\kOS\gfx

They are:

font_sml.png

monitor_minimal.png

Downloaded from spaceport, advertised as 0.46.

Am I missing something?

Edited by TMS
Link to comment
Share on other sites

If you are like me then I tend to change fuel/oxidizer amounts in tanks to more accurate volumes for their sizes (sometimes gallons, other in liters). Not to mention that I will change the burn ratios on engines to match those we use on earth. For that reason even if you were to put amounts for fuel and oxidizer that you think that will be used evenly in an engine, I tend to make my vehicles oxidizer deplete first depending on what I have set for ratios. So you may be reading your liquidfuel amounts with your line of code but running out of oxidizer first which the program never sees if you do not have a line for that as well. Here are a few lines of code I have that works perfect for me that sort of works like an oxidizer gauge.

wait until stage:oxidizer < 650.
print "Lox 5% Sensor".
print "".
wait until stage:oxidizer < 390.
print "Lox 3% Sensor".
print "".
wait until stage:oxidizer < 300.
lock throttle to 0.

No, sorry. I just use stock amounts, and for some reason kOS is hiccuping on me.

EDIT: By the way, Jaws909, your suggestion did not work.

Link to comment
Share on other sites

That would be strange, because in the demo video of kOS, Kevin bases it off of the total remaining fuel left in the rocket. Maybe that has something to do with the first stage being radially attached. No idea, but I'll try your way.

You're right that in my video it's the amount of fuel left in the rocket, but that's only because I don't have any fuel tanks that are not connected to an active engine.

Looking back at your original post, it sounds like you've got a tank lying dormant. Perhaps connected to an engine but an engine isn't activated yet. That woun't count toward your stage:liquidfuel calculation.

EDIT: In debugging these things, it might be good to try a manual launch, but then when you reach the point you're expecting it to stage at, do a PRINT stage:LiquidFuel. You can bind that to an action group if good timing is needed.

Edited by KevinLaity
Link to comment
Share on other sites

Having some difficulty getting steering commands to work when SAS is enabled. Scripts work fine without SAS (and if I switch it off mid-flight).

Is it currently necessary to instruct SAS to toggle before commencing a vector change?

Link to comment
Share on other sites

Having some difficulty getting steering commands to work when SAS is enabled. Scripts work fine without SAS (and if I switch it off mid-flight).

Is it currently necessary to instruct SAS to toggle before commencing a vector change?

No. SAS removes all (Steering) control from kOS. Leave it off until your program is done. Derp, not all control just steering.

Someone asked about staging. This is how I have been staging.


set Count to 3. //Where 3 is the number of asparagus stages.
set StartFuel to <liquidfuel>. //Where startFuel is the total amount of Liquid fuel your rocket has.

until orbit = 1. // Loop with conditional close.
{
set StageSolid to stage:solidfuel.
Set StageLiquid to stage:liquidfuel. //Loop tracked variables.
set Lfuel to <liquidfuel>.

if Lfuel < StartFuel - 1081 AND Count > 0
{ stage. set StartFuel to Lfuel. set Count to Count - 1. }. //Stages parallel liquid and asparagus. Where 1080 is the amount of fuel in one stage of asparagus.

if StageSolid > 0 AND StageSolid < 1 //Stages Solid paralleled on Liquid.
{ stage. }.

if StageLiquid = 0 AND StageSolid = 0 //Stages Solid and Liquid and Decouplers in serial. If the rocket has 0 liquid fuel, it wont stage.
{ if Lfuel > 0 { stage. }. }.
}.

The only special case I can think of where the above script will fail to stage is Solid fuel paralleled on solid fuel. If you want that, you can do something very similar to the liquid asparagus/parallel section.

Edited by Payload
clarity.
Link to comment
Share on other sites

Having some difficulty getting steering commands to work when SAS is enabled. Scripts work fine without SAS (and if I switch it off mid-flight).

Is it currently necessary to instruct SAS to toggle before commencing a vector change?

Yes KSP won't honor any steering input I give programatically it while SAS is on.

Link to comment
Share on other sites

BTW Kevin, I was reading your blog and saw.

Having said that, a lot of people hate ending statements with periods. Relief for this will come. You'll be able to set terminators to whatever you want, but periods will stay the default.

I think that is a terrible idea. Imagine the compatibility issues. How will one person who uses ; share code with someone who uses . or ^ or $ or.......? The fullstop is fine.

On a side note. <resource> Still doesn't work in expression. Although, stage:resource works perfectly now. :)

Link to comment
Share on other sites

Imagine the compatibility issues. How will one person who uses ; share code with someone who uses . or ^ or $ or.......? The fullstop is fine.

On a side note. <resource> Still doesn't work in expression. Although, stage:resource works perfectly now. :)

Well you may be right, though history seems to show that when presented with an option, most people will keep the default. I'll relegate that to the back burner for now.

I'll take another look at the resource tags, dangit I thought I had those completely nailed down.

Link to comment
Share on other sites

Yes KSP won't honor any steering input I give programatically it while SAS is on.

Is there any way around that?

Larger craft tend to wander back and forth from the lock position. Would be nice to have that stabilised through SAS.

Wrote my first few scripts today. They're a bit amateurish, but I'm happy!

Link to comment
Share on other sites

Well you may be right, though history seems to show that when presented with an option, most people will keep the default. I'll relegate that to the back burner for now.

I'll take another look at the resource tags, dangit I thought I had those completely nailed down.

While I understand the concern about sharing compatibility, I for one, would really like to see the option at least to terminate with semicolons.

There's a reason this is almost universally used in programming languages. It doesn't conflict with most expressions, and is second nature to those of us who program.

Secondly, the idea that one should be able to simply cut and paste someone else's kOS code into their program is a little unlikely anyway. Usually, there will be some modification necessary, and to me, switching a terminator would hardly be the most difficult part of the translation.

I vote for the optional terminator of semicolon at least.

Link to comment
Share on other sites

Even after so much scripts written (most of them for tests purposes), I'm still not used to the fullstop for a command. And from my POV, a period marks the end. Peroiod. While I think a semi colon marks the end of an action, but leaves place for more.

Link to comment
Share on other sites

While I understand the concern about sharing compatibility, I for one, would really like to see the option at least to terminate with semicolons.

There's a reason this is almost universally used in programming languages. It doesn't conflict with most expressions, and is second nature to those of us who program.

Secondly, the idea that one should be able to simply cut and paste someone else's kOS code into their program is a little unlikely anyway. Usually, there will be some modification necessary, and to me, switching a terminator would hardly be the most difficult part of the translation.

I vote for the optional terminator of semicolon at least.

No it's a friggin nightmare. What if I want to change from "." to semicolon. I can't just go replace all periods.. Think about it. There is no reason to have multiple terminators. All it will do is cause problems. If you want to change the default, better to do it now and do it once. If your script is right you should be able to take it and use it anywhere. No one says it won't need modification, but hunting lines of code for eclectic terminators is not my idea of Saturday fun. It just causes problems and solves none. Period as a terminator is not a problem. More than one possible terminator is a problem.

Let me just be clear. I don't really care what it is. If it's changed it needs to stay.

Edited by Payload
Link to comment
Share on other sites

No it's a friggin nightmare. What if I want to change from "." to semicolon. I can't just go replace all periods.. Think about it. There is no reason to have multiple terminators. All it will do is cause problems. If you want to change the default, better to do it now and do it once. If your script is right you should be able to take it and use it anywhere. No one says it won't need modification, but hunting lines of code for eclectic terminators is not my idea of Saturday fun. It just causes problems and solves none. Period as a terminator is not a problem. More than one possible terminator is a problem.

Let me just be clear. I don't really care what it is. If it's changed it needs to stay.

With respect. The . being end-of-command is a problem in and of itself. No you can't simply do a find=replace - precisely due to the . being overloaded. This is why it's already a problem. Having said that, a pretty simple regex will get you where you need. the logic would be: period followed by not a number, switch to semicolon. Period followed by EOL replaced with a semicolon. I think that'd do it.

Also, most scripts will have timings and triggers that depend significantly on the vessel or situation, so yes, you're going to have to comb through the code in most cases anyway. Assuming, of course, the code is in anyway nontrivial, you're going to have to look it over and understand it, so converting the terminators won't be much of an extra burden on that process.

I'm in the ; as default camp, but I know that Kevin wants the language to be as englishlike as possible, but if there's a possibility for a more "standard" terminator to be used, I'm all for it. For me at least, having the option for the semicolon would make writing my own code much more pleasurable, which, I'm guessing that I'm going to be doing much more of that than downloading code from elsewhere. So, this option sounds like a quality of life type improvement.

Edited by Desrtfox
Link to comment
Share on other sites

After all, period was chosen, let everyone go with that, and since it was designed to be verbose (hence the set value to 1 instead ot value=1), it can bypass some "conventions"

...

But for the perfectness, please semi colons :D

Edited by SolarLiner
Link to comment
Share on other sites

Use a text editor with regular expressions and it's pretty easy to swap terminators, actually.

I agree. I don't have time to actually build the regex at the moment, but the logic is pretty simple: Period followed by not a number, switch to semicolon. Period followed by EOL replaced with a semicolon. I think that'd do it.

Link to comment
Share on other sites

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