Jump to content

Creating a Config File for my Plasma Rocket


BradMick

Recommended Posts

Howdy all!

First post. Been a long time support of KSP and am now finally getting into playing around with config files and the like. I'm trying to work out how to translate the numbers I've run for a VASIMR style engine into the config file. Here is what i'm working with:

First I started by deciding the size of my powerplants radiator. For this system I went with a 200m2 radiator. Using this formula:

Radiator Area * (Emissivity * Boltzman Constant * Temperature^4) = 200 * (0.95*(5.670373*0.00000001)*1173.15^4 = 20,407,011.47 watts OR 20.41 MW.

I then divided this by 4. Why 4 you ask? Because through research (that was pointed out by Ken Burnside of Attack Vector: Tactical fame) I understand that for every watt of useful power, there's 4 watts of waste heat. This gives me 5.10 MW of useable output.

Further research into VASIMR has it sitting around 60% efficient right now, so taking 60% of 5.10 MW, I've now got 3.06 MW going to my actual thruster.

I set my ISP values for Low to 400 sec, medium 2550 sec and high to 5500 sec.

Running the numbers based on the power going into the thrust beam using:

(2 * Thrust Power ) / (Isp * 9.81)

I came up with thrust for Low to be 1.56 kN, medium 0.24 kN and high to be 0.11 kN

Total waste heat is going to be 17.35 MW ((20.41-5.10) + (5.10-3.06))

Which is more than covered by the system as it's designed right now...So, sorry for the long winded post, but yeah..there is my dilemma.

As I understand it right now, in the config file I can specify Max Thrust, Minimum Thrust, Heat Production, and fuel consumption. What I can figure out is how I get the variable parts in there within the ranges I've specified. I'm sure to there are lots of mistakes in my assumptions, and there's a lot of debate as to whether or not VASIMR is viable anyway, but it'd be neat to simulate all of this and see hhow it might work in real time. The reactor is assumed to be a nuclear fission reactor. Also, I am assuming a lot of research shrunk the reactors down to manageable sizes, but even assuming 500 kilograms per megawatt, this reactor at 20.41 MW output is 10,200kg! But, anyway...Hopefully some of the brains out there that have been doing this for a minute can help me along!

Thanks in advance!

V/R

Brad McKinstrys

Link to comment
Share on other sites

Are you trying to make it so you can adjust the ISP and thrust separately from the throttle? If so then you'll need a plugin to actually accomplish that, as KSP be default doesn't support multiple ISPs and thrusts except based on atmospheric pressure and speed respectively.

A good way to accomplish this is using a GUI slider to change the ISP and thrust by taking the slider's value, doing some math (probably with a floatCurve) and then outputting the values for the engine to use. I just finished my heat sink plugin and I think we (Puffin Technologies) were going to work on a VSAMIR engine but we'd be willing to work together on this :)

Link to comment
Share on other sites

I think i'm starting to figure this out a little bit...the problem is though, getting a power source to work for it.

After referencing this thread:

http://forum.kerbalspaceprogram.com/showthread.php/26354-Ion-Engine-consumes-more-energy-than-it-should?p=321868&viewfull=1#post321868

It looks like the ratio would be energy: 7,698,888 electricity per second for every 0.398 kg/s propellant usage in Low gear (1.56 kN / 400 sec Isp)

That way, when multiplied, the energy used per second when the engine is at full thrust is 3,061,051. Still pluggin' away.

Brad McKinstry

Link to comment
Share on other sites

Orbitus,

Sounds awesome! I'll be more than happy to lend whatever knowledge and stuff like that! I'm getting ready to start modeling the parts to the ship I've envisaged in the next couple of days. Right now i'm looking at a total of four total modules. Actually, make that 5. It'll be the Drive section, Waste Heat Array/Power Plant Module, Propellant Module, Spin Hab module and Flight Module. May change, but that's the general idea so far. Will post some stuff as I get things working.

Brad

Link to comment
Share on other sites

So, some good news. I've programmed the functions to allow all of this stuff to be generated. The bad news is, it's not a loop right now, and it's also using the Dark GDK. I haven't written the bits for limiting the users Isp input range yet either. Actually, there's zero input right now. it's all just hard coded. I'm going to try my hand at coding it for Kerbal. Will let you know!

Brad

Link to comment
Share on other sites

If you don't already I'd recommend downloading Unity because it includes a custom version of Monodevelop (programming software) with Unity syntax and debug capability built in. I hate having to program without syntax assistance... :/

Link to comment
Share on other sites

If you don't already I'd recommend downloading Unity because it includes a custom version of Monodevelop (programming software) with Unity syntax and debug capability built in. I hate having to program without syntax assistance... :/

Thanks! You just made my day. :)

I was looking with some trepidation at the annoying task of installing .Net, GTK for .Net, and MonoDevelop. You just clued me in that since I've installed Unity, I already have it. There it is, right in the Start menu!

Edited by nyrath
Link to comment
Share on other sites

Awesome! So, I've started coding this in Unity using the Monodevelop software, and it's a pretty awesome tool! Now, the problem is...I'm trying to get it to display a console window with the results of the function that I've coded and it's not showing me any output. There are no errors, warnings only because I've specified some initial values that haven't been used yet, and no window showing me the output I'm telling it to print to the screen. I would like to see that the output matches what I've coded, been looking through the unity stuff, but can't really find a clear cut 'put this in there and it'll print to the screen!'. I'm learning this on the fly and as I go with my 'intro to programming' class I'm taking right now...appreciate the patience!

Brad

Link to comment
Share on other sites

If you want to print something to the log, use

print ("text here"+variableYouWantToPrint+"any other text");

It'll print every frame so your log may get full, but you can use some boolean logic to limit the printing.

I can work on the GUI, so if you can get the math working then that should be it. :) I'll send you the GUI code once it's finished so you can add it into the main class.

I let Mek know (not too late I hope) so he might be working on some models.

Edit: I'd also take a look at the floatCurve class (which is what KSP uses for atmosphere-based ISP) and use that to determine the settings (high ISP, low thrust or low ISP, high thrust)

[KSPField]public floatCurve isp;
[KSPField] public floatCurve thrust; //or whatever you want to name the variables

and then

/*engine component, found using GetComponent*/.maxThrust = thrust.Evaluate(/*GUI slider variable here*/);

and the same thing for ISP.

In the config files those will be

MODULE {

[INDENT]name = VSAMIR //or whatever you named the class in Monodevelop
isp
{
key = 0 600 //high ISP setting
key = 1 250 //low ISP setting
}
thrust
{
key = 0 25 //low thrust setting
key = 1 250 //high thrust setting
}[/INDENT]

}

Edited by OrbitusII
Link to comment
Share on other sites

Rock on! Okay, I'll work on finishing up the code tonight and then post it for you here. I'll have to dig around to find the log as well to make sure all the math is functioning right. I've got it working in the C++ code, but I really ant to visually see it in the C# code to make sure I didn't mess anything up. Bear in mind this is going to be the first real program I've written, so...it'll probably be woefully inefficient, but it'll pump out all the data needed, so...that's the bonus, right? Heheh...

Brad

Also, I've done zero modeling so far, as I've really been interested in the code side of the house, so let's just have Mek do the modeling. If he wants I can help, but I'm having fun tinkering right now with code...a lot of fun, probably more than I should be.

Edited by BradMick
Link to comment
Share on other sites

Howdy all!

First post. Been a long time support of KSP and am now finally getting into playing around with config files and the like. I'm trying to work out how to translate the numbers I've run for a VASIMR style engine into the config file. Here is what i'm working with:

First I started by deciding the size of my powerplants radiator. For this system I went with a 200m2 radiator. Using this formula:

Radiator Area * (Emissivity * Boltzman Constant * Temperature^4) = 200 * (0.95*(5.670373*0.00000001)*1173.15^4 = 20,407,011.47 watts OR 20.41 MW.

I then divided this by 4. Why 4 you ask? Because through research (that was pointed out by Ken Burnside of Attack Vector: Tactical fame) I understand that for every watt of useful power, there's 4 watts of waste heat. This gives me 5.10 MW of useable output.

Further research into VASIMR has it sitting around 60% efficient right now, so taking 60% of 5.10 MW, I've now got 3.06 MW going to my actual thruster.

I set my ISP values for Low to 400 sec, medium 2550 sec and high to 5500 sec.

Running the numbers based on the power going into the thrust beam using:

(2 * Thrust Power ) / (Isp * 9.81)

I came up with thrust for Low to be 1.56 kN, medium 0.24 kN and high to be 0.11 kN

Total waste heat is going to be 17.35 MW ((20.41-5.10) + (5.10-3.06))

Which is more than covered by the system as it's designed right now...So, sorry for the long winded post, but yeah..there is my dilemma.

As I understand it right now, in the config file I can specify Max Thrust, Minimum Thrust, Heat Production, and fuel consumption. What I can figure out is how I get the variable parts in there within the ranges I've specified. I'm sure to there are lots of mistakes in my assumptions, and there's a lot of debate as to whether or not VASIMR is viable anyway, but it'd be neat to simulate all of this and see hhow it might work in real time. The reactor is assumed to be a nuclear fission reactor. Also, I am assuming a lot of research shrunk the reactors down to manageable sizes, but even assuming 500 kilograms per megawatt, this reactor at 20.41 MW output is 10,200kg! But, anyway...Hopefully some of the brains out there that have been doing this for a minute can help me along!

Thanks in advance!

V/R

Brad McKinstrys

If the usable energy:waste heat ratio is 1:4, you'll have to divide by five, not four.

Link to comment
Share on other sites

//GUI stuff
private float setting;
private Rect _windowPos = new Rect();
// Use this for initialization
public override void OnStart ()
{
//cut or copy and paste this into the OnStart function
RenderingManager.AddToPostDrawQueue(0, OnDraw);
}
//OnDraw and OnWindow are new, needed functions, so copy and paste the whole thing for both
private void OnDraw ()
{
if(this.vessel == FlightGlobals.ActiveVessel)
{
_windowPos = GUILayout.Window(78, _windowPos, OnWindow, "VSAMIR Manager");
}
}
private void OnWindow(int WindowID)
{
GUILayout.BeginHorizontal(GUILayout.Width(350f));
GUILayout.Label("High ISP... ...Balance... ...High Thrust");
GUILayout.HorizontalSlider(setting, 0, 1);
GUILayout.EndHorizontal();
GUILayout.DragWindow();
}
//in public override void OnUpdate()
//use "<the name of your floatCurve variable>.Evaluate(setting);"
//to get the value from the floatCurve and assign it
//to the engine component's corresponding variable.
}

Link to comment
Share on other sites


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cSharpHelloWorld
{
class Program
{
static double radiatorWasteHeatCapacity(double radiatorArea, double radiatorEmissivity, double boltzmanConstant, double radiatorTemp)
{
double maxReactorOutput = radiatorArea * (radiatorEmissivity * boltzmanConstant * Math.Pow(radiatorTemp, 4)) * 0.000001;

return maxReactorOutput;
}

static double reactorOutput(double maxReactorOutput, double wasteHeatFraction)
{
double useableReactorPower = maxReactorOutput * (1 - wasteHeatFraction);

return useableReactorPower;
}

static double thrusterOutputPower(double useableReactorPower, double thrusterEfficiency)
{
double thrusterPower = useableReactorPower * thrusterEfficiency;

return thrusterPower;
}

static double wasteHeat(double maxReactorOutput, double useableReactorPower, double thrusterPower)
{
double systemWasteHeat = (maxReactorOutput - useableReactorPower) + (useableReactorPower - thrusterPower);

return systemWasteHeat;
}

static void Main()
{
double minimumIsp = 400; //Isp in seconds
double maximumIsp = 5500; //Isp in seconds
double currentIsp = 400; //the thrusters current set Isp <-- needs to be driven by a slider

double radiatorArea = 200; //the systems radiator area in square meters
double radiatorTemp = 1173.15; //radiator temperature in Kelvin (celsius + 273.15)
double radiatorEmissivity = 0.95; //the radiators emissivity, dimensionless. For carbon ~0.95
double boltzmanConstant = 5.670373 * 0.00000001; //the boltzman constant!
double wasteHeatFraction = 0.75; //this is the percentage of the output that is waste heat
double thrusterEfficiency = 0.60; //for a Plasma Thruster (VASIMR) currently at about 0.60

double maxReactorOutput = radiatorWasteHeatCapacity(radiatorArea, radiatorEmissivity, boltzmanConstant, radiatorTemp); //determined through a function!
double useableReactorPower = reactorOutput(maxReactorOutput, wasteHeatFraction); //this is the actual useable power from the reactor after subtracting out waste heat. For a Fission reactor, around 0.75 is the waste heat, and for a Fusion Reactor around 0.05 to 0.25
double thrusterPower = thrusterOutputPower(useableReactorPower, thrusterEfficiency); //the amount of power available in the thrust beam
double systemWasteHeat = wasteHeat(maxReactorOutput, useableReactorPower, thrusterPower); //the systems (reactor + thruster(s)) total waste heat output
double thrust; //the thrusters current level of thrust in kilonewtons (kN)
double mDot; //the thrusters mass mDot (propellant mass flow rate) in kg/s

Console.WriteLine("{0} {1} {2} {3} {4} {5}", "Radiator Area: ", radiatorArea, "Radiator Temp: ", radiatorTemp, "Radiator Emissivity: ", radiatorEmissivity);
Console.WriteLine("{0} {1} {2}", "Maximum Reactor Output:", maxReactorOutput, " MW");
Console.WriteLine("{0} {1} {2}", "Useable Reactor Power: ", useableReactorPower, " MW");
Console.WriteLine("{0} {1} {2}", "Thruster Output Power: ", thrusterPower, " MW");
Console.WriteLine("{0} {1} {2}", "Total Waste Heat: ", systemWasteHeat, " MW");


Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}


}
}

Here's what I accomplished today...which isn't as much as I wanted. I've put this all together in visual studio just so I could actually wet my teeth on the actual syntax and flow of C# (it's enough different from C++, and my knowledge there is ridiculously rudimentary at this point) that it was a little bit of an uphill fight, but I at least got the functions working. I'll work on it some more tomorrow, but I wanted to at least show some progress on this. Basically I just have to finish up the parts that will get integrated into the slider, which that looks like it'll be fun to do for sure. Anyway, any hints/tips/tricks/etc. would be awesome! I'm learning as I go here and enjoying every minute of it.

Brad

Link to comment
Share on other sites

Nice, I haven't done anything with C++ personally but it looks like the syntax is fairly similar, although once you put the math and everything in you will have to define your class as a partModule (which is just "public class className: PartModule")

Link to comment
Share on other sites

using UnityEngine;
using System.Collections;

public class plasmaThruster : MonoBehaviour
{
static double radiatorWasteHeatCapacity(double radiatorArea, double radiatorEmissivity, double boltzmanConstant, float radiatorTemp)
{
double maxReactorOutput = radiatorArea * (radiatorEmissivity * boltzmanConstant * Mathf.Pow(radiatorTemp, 4)) * 0.000001;

return maxReactorOutput;
}

static double reactorOutput(double maxReactorOutput, double wasteHeatFraction)
{
double useableReactorPower = maxReactorOutput * (1 - wasteHeatFraction);

return useableReactorPower;
}

static double thrusterOutputPower(double useableReactorPower, double thrusterEfficiency)
{
double thrusterPower = useableReactorPower * thrusterEfficiency;

return thrusterPower;
}

static double wasteHeat(double maxReactorOutput, double useableReactorPower, double thrusterPower)
{
double systemWasteHeat = (maxReactorOutput - useableReactorPower) + (useableReactorPower - thrusterPower);

return systemWasteHeat;
}

static double thrustOutput(double thrusterPower, double currentIsp)
{
double thrust = ((2 * (thrusterPower / 0.000001)) / (currentIsp * 9.81)) * 0.001;

return thrust;
}

static double thrusterPropellantFlow(double thrust, double currentIsp)
{
double mDot = (thrust / 0.001) / (currentIsp * 9.81);

return mDot;
}


static void Main()
{
//double minimumIsp = 400; //Isp in seconds
//double maximumIsp = 5500; //Isp in seconds
double currentIsp = 400; //the thrusters current set Isp <-- needs to be driven by a slider

double radiatorArea = 200; //the systems radiator area in square meters
float radiatorTemp = 1173.15f; //radiator temperature in Kelvin (celsius + 273.15)
double radiatorEmissivity = 0.95; //the radiators emissivity, dimensionless. For carbon ~0.95
double boltzmanConstant = 5.670373 * 0.00000001; //the boltzman constant!
double wasteHeatFraction = 0.75; //this is the percentage of the output that is waste heat
double thrusterEfficiency = 0.60; //for a Plasma Thruster (VASIMR) currently at about 0.60

double maxReactorOutput = radiatorWasteHeatCapacity(radiatorArea, radiatorEmissivity, boltzmanConstant, radiatorTemp); //determined through a function!
double useableReactorPower = reactorOutput(maxReactorOutput, wasteHeatFraction); //this is the actual useable power from the reactor after subtracting out waste heat. For a Fission reactor, around 0.75 is the waste heat, and for a Fusion Reactor around 0.05 to 0.25
double thrusterPower = thrusterOutputPower(useableReactorPower, thrusterEfficiency); //the amount of power available in the thrust beam
double systemWasteHeat = wasteHeat(maxReactorOutput, useableReactorPower, thrusterPower); //the systems (reactor + thruster(s)) total waste heat output
double thrust = thrustOutput(thrusterPower, currentIsp); //the thrusters current level of thrust in kilonewtons (kN)
double mDot = thrusterPropellantFlow(thrust, currentIsp); //the thrusters mass mDot (propellant mass flow rate) in kg/s
}
}

So, here's the completed set of functions for the thruster. I'm starting to play with figuring out how to put this all together with the GUI stuff, but I'm not really 100% with what goes where inside of the GUI code. Essentially the slider needs drive currentIsp. A small function needs to be written to make sure that currentIsp cannot go higher than maximumIsp and minimumIsp. Really, it'd be something like: (maximumIsp - minimumIsp) / 100 = slider setting, then currentSliderSetting * sliderSetting = currentIsp. Just spit-balling that off the top of my head. Well, except that 0 on the slider would equal 400 and 100 would equal 5500. So, that logic needs to be built in there too. So, really it'd be if currentSliderSetting = 0, set to minimumIsp, and then minimumIsp + (sliderSetting * currentSliderSetting) = currentIsp. So that way it's not going lower than the minimum and and then just adds the sliderSetting to the minimumIsp value. The neat thing, after playing with it in Excel, is that no logic check for exceeding the maximum is required, because at 100% it'll total up to 5500 for the Isp.

Anyway, gonna keep plugging away, but the integration may need to be bounced into your court now.

Brad

Link to comment
Share on other sites

The good thing about floatCurves is that once they're defined all you need to do is give them values in the config file and evaluate the current value based on input from a float.

If you look at my post on the previous page with the floatCurve information this'll make sense– all you need to do is define the time and value for each key in the floatCurve through the config file, then floatCurveName.Evaluate will take the time you put in and return the value for that time. It's your standard algebraic function and it helps minimize the amount of code in use, plus the code I posted above will automatically constrain the ISP and thrust values to whatever you set the min and max to.


//in config file:
MODULE
{
name = ModuleName
isp
{
key = 0 400
key = 1 5500
}
}

You can use math to figure out what the thrust will be based off of the ISP value, but using floatCurves will simplify the code and your job immensely.

I'd also use floats, not doubles. Sure, you can switch between the two, but using a consistent type to begin with will also simplify the code. Floats may have floating-point number errors, but they are used the most in KSP and plugin code. Your class also needs to be either a non-derived class or derived from PartModule depending on the purpose of this bit of code.

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...