KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
697 stars 230 forks source link

Add vessel drag to kOS #1390

Open lamont-granquist opened 8 years ago

lamont-granquist commented 8 years ago

Since 1.0.0 this can't be calculated via formula and needs to be read off of the vessel.

hvacengi commented 8 years ago

Before you spend a bunch of time researching a "fix" for PR #1391 we should probably have a discussion about adding the feature. Historically kOS has intentionally not exposed the raw drag value. Personally I don't like a "magic" suffix/variable for a value that takes as much effort to calculate as drag does. But that doesn't mean it shouldn't necessarily be exposed.

We should consider the implied use cases, the effect on game balance, and the practicality of implementation. You've already found the complication in implementation, but let's talk about those other two points here, if you don't mind. If there is a strong reason to include it, and it isn't a major problem to do so, maybe we can work it into the road map.

hvacengi commented 8 years ago

Oh yeah, and there's a Kerboscript solution floating out there too: https://www.reddit.com/r/Kos/comments/1mmotv/how_to_determine_atmospheric_drag_on_your_craft/

Some times having to find a fix that solves for the data you're looking for can be part of the fun, instead of having it directly accessible :-)

lamont-granquist commented 8 years ago

I think that's the old pre-1.0 drag model?

But yeah, agreed. Right now I just want it for a read-out and it seems like a lot of work just to get a read-out. I'm kind of curious about scripting up the Gravity Turn mod as a kerboscript, which is where this is all coming from, and I'll have to see if calculating drag is critical to replicating the launches it does or not.

hvacengi commented 8 years ago

Actually, you're right. It was mentioned in our developer chat, and I didn't read it carefully before I posted it here. I've got a system that should be able to approximate the drag through other means, I calculate the delta v based on mass of fuel used, and I also calculate the steering and gravity losses. Given those three values, the drag loss should be able to be derived based on the actual observed delta v. But I haven't done anything to deal with the vector math involved yet.

TDW89 commented 8 years ago

This is a kerboscript solution I did this a while back. unfortunately it requires the accelerometer science part to be attached to the vessel and I couldn’t find a way to account for reaction wheel forces (I also didn't include RCS) but other than that it works.

SirDiazo commented 8 years ago

While not recently, I have looked at getting lift/drag numbers directly for my own purposes and never found anything remotely usable.

I ended up just recording the origin point of the vessel over several FixedUpdate frames and using observational data to calculate it.

The basic steps for my method would are:

1) Record vessel position A 2) Record vessel thrust 3) Wait a bit (I use 5 FixedUpdate frames) 4) Record vessel position B 5) Calculated expected vessel position C from position A and observed thrust. 6) Amount position B is "behind" position C equals current drag 7) Amount position B is "above" position C equals current lift

I'm not sure how viable this is for 3D positions though, in my implementation all I cared about was vertical velocity so I was able to lock things to a single Axis which makes it a lot simpler.

That's of course assuming you decide you want to add something like this in, due to how KSP handles lift/drag it would be an iffy number to add. I don't think anything else kOS exposes is based on uncertain numbers like this.

lamont-granquist commented 8 years ago

@TWD89 @hvacengi yeah, I think I've got 75% of the work-backwards-and-subtract solution coded up.

piepieninja commented 6 years ago

Is there any update on the progress of adding drag to a vessel?

Nufflee commented 5 years ago

Any updates on this? It's been 3.5 years since this issue was created and still nothing?

cc @hvacengi @Dunbaratu

Dunbaratu commented 5 years ago

I think the consensus was not to bother since it's computationally expensive and exactly the sort of thing you can calculate yourself in the script. In fact, the techniques mentioned above require waiting for time to pass in game so you can measure the expected velocity versus the actual velocity you got to calculate what the drag did.

Nufflee commented 5 years ago

That's not the only way to do it though, kRPC does it by just summing up every part's drag and lift value.

Take a look here.

Dunbaratu commented 5 years ago

Well that certainly is do-able. I still think getting a result of summing up all the parts as a single suffix is a bit problematic for performance, but we might be able to make it one of the routines that forces a wait 0. after being called so you're not allowed to call it again and again in the same physics tick (like we do with stage. because changing the vessel part list requires a re-assesment between ticks.)

I'm still not convinced it's the right thing to do though because it's magic information a real autopilot would have to calculate itself. But we do have similar magic information elsewhere so maybe I could be convinced.