Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

I lost the discussion but has there been any development in reintroducing what nivekk had in place for external module registration? I'd like to see about getting IR working. If it's far into the future I could cobble his code with current just to get the ball Rollin on my end.

Link to comment
Share on other sites

Welcome, I hope i can answer your question.

I assume you are talking about Jet engines? Their thrust does vary on atmospheric density and speed. These are part of the eval for "THRUST" aka current thrust. Because we dont expose either the atrmocurve or velocitycurve and KSP doesnt use them for the "MAXTHRUST" calculation you would have to look at "THRUST" with throttle at 1.

If you post a sample of your code we should be able to help more. I havent seen an issue like yours before.

Around the first of the year.

Thanks for the tips! This is the kind of problem I'm encountering:

2bUNmfQ.jpg

Was there an update somewhere that added these values, and I just don't have it?

Link to comment
Share on other sites

Was there an update somewhere that added these values, and I just don't have it?

Can you show the parts where you SET THRUST to something, or SET ENGINE to something? I don't see that part in the screenshot. (Or are you operating under the assumption that these are built-in variables? Because they're not.).

Link to comment
Share on other sites

I lost the discussion but has there been any development in reintroducing what nivekk had in place for external module registration? I'd like to see about getting IR working. If it's far into the future I could cobble his code with current just to get the ball Rollin on my end.

I have been thinking about this but i havent put hands to keyboard on it. I am out this weekend but after that might be a good time to tackle it.

Link to comment
Share on other sites

Can you show the parts where you SET THRUST to something, or SET ENGINE to something? I don't see that part in the screenshot. (Or are you operating under the assumption that these are built-in variables? Because they're not.).

Oh shoot. I guess I'm really that dumb. In the kOS docs, under the 'Structure Reference' title, does that list not refer to built-in variables?

Link to comment
Share on other sites

Thanks for the tips! This is the kind of problem I'm encountering:

http://i.imgur.com/2bUNmfQ.jpg

Was there an update somewhere that added these values, and I just don't have it?

MAXTHRUST is an alias for the max thrust of the currently active engines. It is a pretty simple query to the vessel that doesnt take into account available fuel or anything complicated.

if you want to get more sophisticated information about engines you need to get the engines into an array and then iterate over them. We i wouldnt mind helping you figure that out if you tell us more about what you are trying to do.

Link to comment
Share on other sites

Oh shoot. I guess I'm really that dumb. In the kOS docs, under the 'Structure Reference' title, does that list not refer to built-in variables?

Those are the structure definitions, once you have an engine or body or whatever structure this will help you figure out what your available suffixes are.

If you get your engines into an array and iterate over them like this:


LIST ENGINES IN foo.
FOR engine IN foo {
PRINT "Name: " + engine:NAME + " Thrust: " + engine:THRUST.
}

Edited by erendrake
Link to comment
Share on other sites

Those are the structure definitions, once you have an engine or body or whatever structure this will help you figure out what your available suffixes are.

Ah, so I need to name the engine somehow, perhaps with the names under 'list parts.'?

Very aware of the limitations of MAXTHRUST, my current goal is to build a hovercraft, and to do that I need to calculate, using engine data, what throttle percentage needs to happen to bring my TWR to 1.

Currently I am setting my throttle to '(mass*9.81*desiredTWR)/maxthrust' but I think because of atmospheric limitations, using a TWR of exactly 1 actually causes a rise in altitude if not corrected.

Link to comment
Share on other sites

Ah, so I need to name the engine somehow, perhaps with the names under 'list parts.'?

Very aware of the limitations of MAXTHRUST, my current goal is to build a hovercraft, and to do that I need to calculate, using engine data, what throttle percentage needs to happen to bring my TWR to 1.

Currently I am setting my throttle to '(mass*9.81*desiredTWR)/maxthrust' but I think because of atmospheric limitations, using a TWR of exactly 1 actually causes a rise in altitude if not corrected.

You could also use a PID controller with your setpoint being your altitude and your output as the throttle. Then when you are trying to gain speed by thrusting away from "UP" you can still maintain the right altitude.

Link to comment
Share on other sites

You could also use a PID controller with your setpoint being your altitude and your output as the throttle. Then when you are trying to gain speed by thrusting away from "UP" you can still maintain the right altitude.

Wow, that looks complex. Might be what I'm looking for, though! Thanks.

Link to comment
Share on other sites

Wow, that looks complex. Might be what I'm looking for, though! Thanks.

One of the reasons i recommend a PID is that there are so many resources out there to help understand how it works and how to tune it. I suggest watching a few videos online.

Link to comment
Share on other sites

Ah, so I need to name the engine somehow, perhaps with the names under 'list parts.'?

Very aware of the limitations of MAXTHRUST, my current goal is to build a hovercraft, and to do that I need to calculate, using engine data, what throttle percentage needs to happen to bring my TWR to 1.

Currently I am setting my throttle to '(mass*9.81*desiredTWR)/maxthrust' but I think because of atmospheric limitations, using a TWR of exactly 1 actually causes a rise in altitude if not corrected.

Don't forget that g varies with altitude above the planet (or distance from its center). So what you think of as TWR = 1 might actually be higher.

Link to comment
Share on other sites

Oh shoot. I guess I'm really that dumb. In the kOS docs, under the 'Structure Reference' title, does that list not refer to built-in variables?

Those are descriptions of built-in TYPES rather than of built-in variable names. For example, it mentions "Vessel", but "Vessel" isn't a variable. It's the common type shared by both SHIP and TARGET.

Come to think of it, that is a bit sloppy in the docs - perhaps there needs to be a section for built-in variable names, both to document how they work and as just a list of variable names to avoid if you're making up a name for your own homemade variable.

Link to comment
Share on other sites

Simple hover script with a PID controller


clearscreen.
set newThrottle to 0.
lock throttle to newThrottle.

set targetSpeed to 0.
set speedStep to 0.5.

on ag1
{
set targetSpeed to targetSpeed - speedStep.
preserve.
}
on ag2
{
set targetSpeed to 0.
preserve.
}
on ag3
{
set targetSpeed to targetSpeed + speedStep.
preserve.
}

// controller coefficients
set kpT to 0.1.
set kiT to 0.02.
// controller accumulated error
set errSumT to 0.

until false
{
// speed error
set deltams to targetSpeed - ship:verticalspeed.
// predicted throttle for a TWR of 1
set predictedThrottle to ((ship:mass*9.82) / ship:maxthrust).
// -----------------------------------------------
// PID (PI actually) controller code
set tempThrottle to predictedThrottle + (kpT * deltams) + (kiT * errSumT).
set errSumT to errSumT + deltams.
// -----------------------------------------------

set newThrottle to tempThrottle.
print targetSpeed + " " at (0, 0).

wait 0.1.
}.

Uses action groups 1, 2 and 3 to decrease, set to zero and increase the speed, respectively.

Link to comment
Share on other sites

Ah, so I need to name the engine somehow, perhaps with the names under 'list parts.'?

Very aware of the limitations of MAXTHRUST, my current goal is to build a hovercraft, and to do that I need to calculate, using engine data, what throttle percentage needs to happen to bring my TWR to 1.

Currently I am setting my throttle to '(mass*9.81*desiredTWR)/maxthrust' but I think because of atmospheric limitations, using a TWR of exactly 1 actually causes a rise in altitude if not corrected.

Two problems:

1 - The acceleration at sea level from gravity in KSP is not 9.81 m/s^2. It's very very close to that, but not exactly. If you see 9.81 in the readout from the Gravioli device, remember that it's rounding to the hundredths place.

2 - You're better off using the actual Newtonian gravitation formula anyway if you're going to try something as precise as a hover script, as it's sensitive enough to need that level of precision - the reduction in weight due to altitude is enough to throw it off. I use this:

lock heregrav to gConst*bodyMass/((altitude+bodyRadius)^2).

(gConst is newton's gravitational constant, bodyMass is the planet/moon's mass, and bodyRadius is the planet/moon's radius from center to "sea level". You'll have to substitute those values in).

From there on use heregrav in your calculations and you'll get the actual acceleration from gravity at your current location, dynamically updated as you go.

Edited by Steven Mading
Link to comment
Share on other sites

Is there a way for kOS to interact with the "outside world"? Could I talk to it with a C++ program and maybe make a rocket controlled by a wiimote? I just started playing with kOS and some overly ambitious ideas are popping into my head. :D

Link to comment
Share on other sites

Is there a way for kOS to interact with the "outside world"? Could I talk to it with a C++ program and maybe make a rocket controlled by a wiimote? I just started playing with kOS and some overly ambitious ideas are popping into my head. :D

There is a different mod that takes the approach of just being a sever that makes a RPC bridge between KSP's API and other processes you run externally to KSP. It might give you something a bit like what you're asking for. http://forum.kerbalspaceprogram.com/threads/69313-WIP-kRPC-A-language-agnostic-Remote-Procedure-Call-server-for-KSP

I haven't used it so I can't give any advice on whether it gives you what you want, but I'm just guessing it might be closer to what you want.

Link to comment
Share on other sites

Is there a way for kOS to interact with the "outside world"? Could I talk to it with a C++ program and maybe make a rocket controlled by a wiimote? I just started playing with kOS and some overly ambitious ideas are popping into my head. :D

ascentkomputron.blogspot.ca

I haven't actually gotten around to trying it but it apparently can compute optimal launch profiles and then execute them in the game even though it's an external program.

Edited by Starwaster
Link to comment
Share on other sites

I have been thinking about this but i havent put hands to keyboard on it. I am out this weekend but after that might be a good time to tackle it.

Great to hear. Just PM when you have something I can test out. Thanks!

Link to comment
Share on other sites

I've been gone from KSP since last August. When did Nivekk disappear? I just searched the Members list and Nivekk is not to be found.

His Youtube name is Nivekk, his forum (and real) name is Kevin Laity.

Wow, that looks complex. Might be what I'm looking for, though! Thanks.

There is lots of documentation out there. You will need to fiddle with it, but it is actually quite a universal method of getting things done. It can be a little sloppy sometimes, but typically beats doing full mathmatical modelling of your problem. You can solve really complicated problems quite quickly.

Link to comment
Share on other sites

2 - You're better off using the actual Newtonian gravitation formula anyway if you're going to try something as precise as a hover script, as it's sensitive enough to need that level of precision - the reduction in weight due to altitude is enough to throw it off. I use this:

I have found small errors in either method, to be honest. Even at ideal settings, a hover tends to rise or fall slightly.

Link to comment
Share on other sites

I have found small errors in either method, to be honest. Even at ideal settings, a hover tends to rise or fall slightly.
You might have to add another term to account for the non-inertial reference frame(centripetal force) but at this point a simple feedback system would be easier.
Link to comment
Share on other sites

I haven't used kOS since 0.6 .. Were there changes to how editing functions? "edit filename." doesn't work for me. It doesn't move me to the "edit" screen.

Edit is currently broken. You'll want to use your favorite text editor to edit the archive files outside KSP and import them to your ship's computer (or switch to the archive)

Link to comment
Share on other sites

I haven't used kOS since 0.6 .. Were there changes to how editing functions? "edit filename." doesn't work for me. It doesn't move me to the "edit" screen.

I had the same problem in V0.12.1. I switched to the pre release version posted here https://github.com/KSP-KOS/KOS/releases . That fixed the problem for me.

I didn't run into any trouble with the pre-release yet. But didn't give it a great deal of testing either.

Link to comment
Share on other sites

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