Jump to content

kOS Scriptable Autopilot System 0.9


KevinLaity

Recommended Posts

How do you work out TWR I assume you use maxthrust and mass, but what's the equation.

Is it (mass x9.81)/maxthrust ?

Yes and no. Firstly that's a weight to thrust ratio. You have to invert it. Secondly what you typed there is the formula for WTR at maximum thrust and at sea level on kerbin. But that's useless since rockets are designed to move away from the sea level and the further away you move from a body the strength of gravity decreases.

You get the weight with m*g*(r/(r+a))^2

where:

m is the ships mass

g is the gravitational strength of the body you're orbiting

r is the mean radius of the body

a is your altitude

The actual TWR is:

(maxthrust*throttle)/(mass*9.81*((radius/(radius+altitude))^2))

But you can't get the actual throttle value yet.

Edited by Cpt. Kipard
Link to comment
Share on other sites

Just set the plugin to load a txt file called autoexec from the archive. It shall be called autoexec so that your plugin knows what to load. The files them selves are not removed and I can call those from any unit. Why not have the autoexec work the same way? Just called automatically by the terminal. If it's empty or it doesn't exist, it does nothing. If it has commands, it executes them. Like a call to MAIN with a BREAK and RUN. Even my old 286 had an autoexec.

One problem with that is that it would apply to every ship you launch from that point on, which may or may not make sense for everybody. And it would take us further away from having the system make sense inside the Kerbal universe. I didn't want the Archive drive to transcend time and space the way it does now, I just didn't have a good way for it not to. When you revert in KSP, everything in the universe reverts to the way it was at that time, except the Archive drive. I consider this a bug, not a feature.

The reason the Archive drive exists is to give you a place to back up your files and share files between craft. If you're looking for a way to do fast development iterations, I recommend using F5 before you launch and F9 after. But yes, that does make it a pain if you also want to also backup to the Archive at the same time.

My ideal would be that you configure the loadout of your unit while you're in the VAB, including assigning autoexecs that apply to individual craft or whatever you like to it. But again I haven't found a way to do that.

Clearly something is needed here to make this less painful. I'd like it to be something that makes sense in-universe. But if this is the only way, then I'll do that.

Link to comment
Share on other sites

One problem with that is that it would apply to every ship you launch from that point on, which may or may not make sense for everybody. And it would take us further away from having the system make sense inside the Kerbal universe. I didn't want the Archive drive to transcend time and space the way it does now, I just didn't have a good way for it not to. When you revert in KSP, everything in the universe reverts to the way it was at that time, except the Archive drive. I consider this a bug, not a feature.

The reason the Archive drive exists is to give you a place to back up your files and share files between craft. If you're looking for a way to do fast development iterations, I recommend using F5 before you launch and F9 after. But yes, that does make it a pain if you also want to also backup to the Archive at the same time.

My ideal would be that you configure the loadout of your unit while you're in the VAB, including assigning autoexecs that apply to individual craft or whatever you like to it. But again I haven't found a way to do that.

Clearly something is needed here to make this less painful. I'd like it to be something that makes sense in-universe. But if this is the only way, then I'll do that.

I am building a flight computer comprised of modules made by others and my self. If I have a EXIT AND RUN command it is supremely easy to add and remove modules and it makes it to where they are self contained things that are easy to debug. I have tried what you suggested and had my orbit program run the splash and the menu. It did work. The only issue I have with that is I now have to cram every module into the main. It's going to get big and slow. My orbit program is already too slow. Mostly my fault, but you can imagine the nightmare with module integration. Nice de-bugg-able and replaceable chunks. That is what we are going after. This is a scripting language after all. It should be as easy as possible.

The autoexec would be nice. It's not as important as break and run though. For now, that is what is really required. Then module writers only need to add EXIT AND RUN main. or whatever you wish to call it. My main menu then only has to do the same on selection.

Right now I have everything set to run from main menu. The problem is then when it runs the orbit program that the program orbit no longer has control of the ship. It stages but it doesn't throttle or steer. The menu literally doing nothing. It is set to wait for end condition.

Yet some how it is not allowing the orbit program full control of the craft. I suspect it is because the menu program has control of those things. I even tried moving the main loop out to the main menu and had it do the loop and the orbit program just set when flags but that still doesn't work. Break and run solves all my problems.

Autoexec is nice but not nearly as important.

Edited by Payload
Link to comment
Share on other sites

Well, I figured out how to save my cruddy programs, now I don't know what I'm doing wrong with them.

I have a simple two-stage rocket with the first stage being two fuel tanks adding up to 720 l of liquid fuel, and a second stage one 180 l fuel tank.

My command is:

Wait until stage:liquidfuel < 180.

Stage.

What have I done wrong?

Link to comment
Share on other sites

My ideal would be that you configure the loadout of your unit while you're in the VAB, including assigning autoexecs that apply to individual craft or whatever you like to it. But again I haven't found a way to do that.

Clearly something is needed here to make this less painful. I'd like it to be something that makes sense in-universe. But if this is the only way, then I'll do that.

Infernal Robotics (and Damned Robotics before it) has input areas in the VAB for setting the names of groups and parts. I'm not sure if those are saved with the craft file or not, but maybe it could give some ideas.

Link to comment
Share on other sites

Well, I figured out how to save my cruddy programs, now I don't know what I'm doing wrong with them. I have a simple two-stage rocket with the first stage being two fuel tanks adding up to 720 l of liquid fuel, and a second stage one 180 l fuel tank. My command is: Wait until stage:liquidfuel < 180. Stage. What have I done wrong?
What is the script doing? Anything? Try a loop that prints stage:liquidfuel and fly manually. Maybe kOS isn't interpreting things the way you want it to.
Link to comment
Share on other sites

How are you making the flight computer?

How do you display the options and just click in them, no so interested in using the built in modules, but would like to make my own.

Also back to KOS general, I'm not a programmer and I'm sure many more aren't, there's a list of instructions on the help page, but not a list of how to use them all, loops, checking etc. would be great if you could make a better help page with far more full lines of code examples

I still can't see how to check if a value is between two numbers. Check if it is higher, lower or equal is easy. But can't seem to get say checking a if a value lies between for example for it to excite a loop only when ALT:RADAR is between 10000 and 15000.

So there's no easy way to calculate TWR , would it be possible to include this in a future update, it would make hovering or accelerating/decelerating at x-g so much easier. If you and a very accurate TWR you can use mass and tell it to do many things.

this is what I've manged so far but as above cant get one of the if statements working(in bold). is there a better way to try and match thrust and gravity to cancel each other out.


clearscreen.
print "5". wait 1.
print "4". wait 1.
print "3". wait 1.
print "2". wait 1.
print "1". wait 1.
print "launch".
set tVal to 1.
stage.
lock throttle to tVal.
lock steering to up + R(0,0,180).
wait 5.
Print "Descending".
until Alt:radar < 75 {
if verticalspeed > 0 {
set tVal to 0.
}.
[B]if verticalspeed <0 >-3 {
set tVal to 0.98/(maxthrust/(mass*9.81)).
}.[/B]
if verticalspeed <-3 {
set tVal to 1/(maxthrust/(mass*9.81)).
}.
}.

Print "landing".
until Alt:radar < 6 {
if verticalspeed > 0 {
set tVal to 0.
}.
if verticalspeed <0 {
set tVal to 1/(maxthrust/(mass*9.81)).
}.
}.

set tVal to 0.

Print "landed".

Edited by Glaucus
Link to comment
Share on other sites

Well, I figured out how to save my cruddy programs, now I don't know what I'm doing wrong with them.

I have a simple two-stage rocket with the first stage being two fuel tanks adding up to 720 l of liquid fuel, and a second stage one 180 l fuel tank.

My command is:

Wait until stage:liquidfuel < 180.

Stage.

What have I done wrong?

Try this:

wait until stage:liquidfuel < 1.

stage.

AFAIK, the computer is measuring your fuel levels only in the current stage, so you need the value to be less than 1, or 0...this works for me at least.

Link to comment
Share on other sites

Try this:

wait until stage:liquidfuel < 1.

stage.

AFAIK, the computer is measuring your fuel levels only in the current stage, so you need the value to be less than 1, or 0...this works for me at least.

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.

Link to comment
Share on other sites

Is there a way to do retrograde but with surface information, rather than orbit. Failing that a way to work out the steering coordinates for it.

+1 to this. We need either this or trigonometric functions so we can land things from orbit.

Link to comment
Share on other sites

Infernal Robotics (and Damned Robotics before it) has input areas in the VAB for setting the names of groups and parts. I'm not sure if those are saved with the craft file or not, but maybe it could give some ideas.

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.

Link to comment
Share on other sites

Is there a way to do retrograde but with surface information, rather than orbit. Failing that a way to work out the steering coordinates for it.

It's one thing I'm working towards. My initial tests with hooking the steering system up to a rover did not go well.

I'm hoping to have the abliity to set a target or give it a set of coordinates and have rovers autodrive to them.

Edit: realized you may not be talking about rovers at all. I see what you're looking for though, I just need to find where to grab those values in the assembly.

Edited by KevinLaity
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.

There has to be a way to set each kOS part you attach to a ship a certain folder. It could give you a dialog box in the VAB to pick a folder from the list. You could use more than one folder instead of just one called archive, and just maintain a list of folders that is the archive for that particular piece.

I imagine the flow going something like this. I grab a kOS part and attach it to a ship in the VAB. A menu/dialog box pops up asking me to set a folder that will be that parts archive folder.

I select a folder from the list. They are folders that the user has put in the archive folder. You could even have a way for a user to make a new folder then. Such as a text entry field. If it finds the folder you have named, it uses it. If it doesn't find it, it asks you if you would like to make one.

A lot of work that Bac9 has done in B9 aerospace might be helpful. Items such as the info drive. It might be really helpful to know how that works.

Link to comment
Share on other sites

Wow... this is exactly what the community is really looking for - an autopilot for those who actually want to do the work for themselves! I always hoped that something like this would become stock as a compromise between automation and manual challenge. I haven't used mechjeb for months due to the bloat and memory overheads, and had been looking for something lightweight to fill the gap.

Beyond the videos, it would be good to share script examples as well.

Great work, man!

Edited by TMS
Link to comment
Share on other sites

I have a small question since I'm a programming noob. What script function would i need at the start of my code to tell it to hold off on running it till an action group is fired? What I'm wanting to do is load the game up load in my program into KoS then have a friend through telemachus hit an action group that fires the loaded code. Thanks in advance if anyone knows the code I'd need to have the thing sit on hold till told to go farther.

Link to comment
Share on other sites

I have a small question since I'm a programming noob. What script function would i need at the start of my code to tell it to hold off on running it till an action group is fired? What I'm wanting to do is load the game up load in my program into KoS then have a friend through telemachus hit an action group that fires the loaded code. Thanks in advance if anyone knows the code I'd need to have the thing sit on hold till told to go farther.

Many ways to do this. You could do:

 on AG1 { "insert code here }. 

Or, if you don't want to spend the entire script inside brackets you could do it with a flag:

 
set X to 0.
On AG1 set X to 1.
wait until X is 1.
"Your code"

And probably there are dozens of other ways to do so.

Link to comment
Share on other sites

+1 to this. We need either this or trigonometric functions so we can land things from orbit.

I'm not sure this is an either/or proposition. Trigonometry is essential for calculating horizontal and vertical components of thrust. Want to do this? You need trig.

Edited by Cpt. Kipard
Link to comment
Share on other sites

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