Jump to content

Modifying maximum ISP and maximum thrust at runtime


Recommended Posts

KSP Interstellar's DT Vista engine can change its ISP on the fly. I've been trying to add the same functionality to my plugin (http://forum.kerbalspaceprogram.com/threads/120969-WIP-Plugin-1-0-2-RealisticNuke-%28More%29-Realistic-Nuclear-Rocket-Engines) by importing the LV-N's atmosphereCurve, assigning it to a FloatCurve variable, then using a for loop to go through all the keys and multiplying them with a value (between 0 and 1, 0 corresponds to no thrust and zero ISP, and 1 is max thrust and max ISP). I then replaced the original atmosphereCurve with the custom one. This is all in the OnFixedUpdate() function, but for some reason it isn't adjusting the ISP.

How do I make this work? Also, how do I adjust max thrust at runtime? Source is at https://github.com/CaptainKorhonen/RealisticNuke in case someone wants to have a look.

Link to comment
Share on other sites

I don't understand why you need to do that. The current engines already allow variable ISP with the atmosphereCurve, as you obviously saw.

Netera source shows it but if you did not find it in there : you need to recalculate maxFuelFlow and minFuelFlow

Link to comment
Share on other sites

KSP Interstellar's DT Vista engine can change its ISP on the fly. I've been trying to add the same functionality to my plugin (http://forum.kerbalspaceprogram.com/threads/120969-WIP-Plugin-1-0-2-RealisticNuke-%28More%29-Realistic-Nuclear-Rocket-Engines) by importing the LV-N's atmosphereCurve, assigning it to a FloatCurve variable, then using a for loop to go through all the keys and multiplying them with a value (between 0 and 1, 0 corresponds to no thrust and zero ISP, and 1 is max thrust and max ISP). I then replaced the original atmosphereCurve with the custom one. This is all in the OnFixedUpdate() function, but for some reason it isn't adjusting the ISP.

How do I make this work? Also, how do I adjust max thrust at runtime? Source is at https://github.com/CaptainKorhonen/RealisticNuke in case someone wants to have a look.

If you would look at the source code of KSPI Extended, you would figure out How I did it.

I suggest you lalso look at the Thermal Noozle, which takes into account static presure

Link to comment
Share on other sites

It looks like the instant I even look at the atmosphereCurve it just breaks the whole thing. The engine has its exhaust flame on all the time, there's a second flame pointing straight to the side, it doesn't show up in staging and it loses the collision mesh. The reactor temperature also stops updating. Probably some other problems too.

ISPCurve.Add(0f, engine.atmosphereCurve.Evaluate(0f));

ISPCurve.Add(1f, engine.atmosphereCurve.Evaluate(1f));

With these lines in the OnStart() method, the engine is broken. Without them, it works fine. What on earth is going on? These don't even try to write any data to the ModuleEngines, they just read the values from the atmosphereCurve and store them in another FloatCurve variable.

Edited by CaptainKorhonen
Link to comment
Share on other sites

Hard to tell without seeing the current state of your code. One unrelated thing however, you should not set the part.thermalInternalFlux but use part.AddThermalFlux(kilowatts)

Link to comment
Share on other sites

Hard to tell without seeing the current state of your code. One unrelated thing however, you should not set the part.thermalInternalFlux but use part.AddThermalFlux(kilowatts)

Code looks exactly like the version on my github but lacks the OnFixedUpdate() method. If I add the two lines from my previous post to the OnStart() medthod it breaks the thing completely. Also, thanks for the tip, I'll change the heat generation thing.

E: I've synced the current version of the code to my github.

Edited by CaptainKorhonen
Link to comment
Share on other sites

You have this at the top of your class:

ModuleEngines engine = new ModuleEngines();

...so those two lines are accessing the atmosphere curve from an uninitialized ModulesEngines. I suspect that you are getting an exception of some kind which is preventing other code from running correctly...

I would suggest changing that line to say just:

ModuleEngines engine = null;

...and in OnStart add a line of code that gets the ModuleEngines part module from the part.

Edited by Padishar
Link to comment
Share on other sites

You have this at the top of your class:

ModuleEngines engine = new ModuleEngines();

...so those two lines are accessing the atmosphere curve from an uninitialized ModulesEngines. I suspect that you are getting an exception of some kind which is preventing other code from running correctly...

I would suggest changing that line to say just:

ModuleEngines engine = null;

...and in OnStart add a line of code that gets the ModuleEngines part module from the part.

Thank you! This was pretty much exactly what was wrong with it! I think the engine broke because I created an empty ModuleEngines, fed the ISP values to it and then replaced the original ModuleEngines with the custom one which overwrote ALL the data in the original (apart from the atmosphereCurve), thus completely removing the engine functionality.

So I got that working, but then the ISP readout got stuck at "NaNs". Turns out I had completely forgotten to import the max temperature from the engine's config and as it calculated the reactor's power level it ended up trying to divide by zero :sticktongue:

Also, thanks for the thermal thing, sarbian. I'll change the heat generation method.

Link to comment
Share on other sites

FYI, if you're trying to set the thrust and Isp of an engine based on proprietary calculations, there is a plugin interface in development designed to do just that. It's called SolverEngines, and is designed to allow you to use custom solvers which will replace the stock calculations rather than letting them happen and then changing the result.

Link to comment
Share on other sites

Thrust edit:

with 0.90: To set the thrust, change maxThrust (and minThrust if you want) in your ModuleEngine

with 1.0 : To set the thrust, change also maxFuelFlow = maxThrust / (G*vacuumIsp)

(again, you can do the same with minfluelflow if minthrust >0)

G is in moduleEngines.g

vacuum thrust can be obtained by something like ModuleEngines.atmosphereCurve.Curve[0].value

Someone has tried playing with atmChangeFlow? It seem to be a switch between thrust/fuelFlow reference.

Edited by Merill
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...