C++ Question Variable max engine thrust above certain accelerations

Grover

Saturn V Misfire
Addon Developer
Donator
Joined
Oct 3, 2010
Messages
1,468
Reaction score
0
Points
0
Location
Ascension Island
as i was working through making my Haworth MPEV and launcher, i decided to make the launcher a custom DLL craft, similar to the stock atlantis launch solution

but, after working some numbers, i found that the only way to prevent unbearable acceleration, the engines will have to be controlled. now, i can work out what the maximum force SHOULD be, using simple F=MA, so i can calculate a maximum force that the engine should produce, whilst keeping acceleration below a maximum of ~25m/s/s

currently, the third stage will produce 8m/s/s acceleration upon ignition, but this will increase to just over 25m/s/s acceleration at the end of TLI. my second stage accelerations range from 10m/s/s to 33m/s/s (unacceptable IMHO) and the first stage will range from 14m/s/s (with boosters for liftoff) to 40m/s/s upon separation.

ideally, each stage's maximum acceleration should be between 2g and 2.5g for all stages, to relieve the crew of stupidly high accelerations. and 2G is plenty for a multistage rocket to get up to orbit.

the problem is, i need a way to cap the engine force.
starting with 2nd and 3rd stages:
when the maximum force would push acceleration above 2g, i would then change the definition of engine max thrust, to a variable souce, where the force is calculated by multiplying the vessel mass (obtained through API) by 20, so essentially, the engines are automatically damped to save the crew from G forces

i THINK i could acieve this by coding something like this:
Code:
if
   (MaxEngineForce/VesselMass) > 20  // a=F/m  a should always be less than 20
      LimitedEngineForce= VesselMass*20  //calculate engine force required to give required acceleration
      MaxEngineForce=LimitedEngineForce  //swap MAXengine thrust for LIMITED engine thrust defined in the last line
   else
      return   // not sure if this is necessary, but i guess it is

it will need to be "Translated" into C++ first obviously, but will that general string work? and if not, how do i make it work?

once i can get this one working, i can get the other stages limited using similar code, by checking the vessel StageStatus (where 0=1st stage with boosters, 1=1st stage after booster sep, 2=2nd stage, 3=third stage, 4=payload jetissoned) to make sure that the correct thrust limitation is used, so each of the thrust limitations will be embedded inside:
Code:
if
   StageStatus=0
      [limitation code for this stage]
else
   stageStatus=1
      [Limitation for 1st stage alone]
  (ETC...)


obviously, its a little messy, and hard to grasp for a first time C++ coder, but i think its worth the challenge

thanks guys, perhaps ill have more questions later... ok, i probably will... ok, i DEFINATLEY will :p

later
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Of course, you could simplify things by:

[math]L = \frac{F}{F_0} = \frac{m \cdot a}{F_0}= m \cdot \frac{a}{F_0} = m \cdot c[/math]
For preventing setting the throttle too high, use

Code:
SetThrusterLevel(thX, min(L, 1.0));
 

Grover

Saturn V Misfire
Addon Developer
Donator
Joined
Oct 3, 2010
Messages
1,468
Reaction score
0
Points
0
Location
Ascension Island
thanks for the lightning-fast reply!

but unfortunatley, those are just letters to me, and i dont see how the first one simplifies it at all

is the second one an API control to set a maximum acceleration based on the equations above it? again, i need to understand the first to understand the second

thanks man! :D
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
but unfortunatley, those are just letters to me, and i dont see how the first one simplifies it at all

It simply says in math, that for achieving constant acceleration (a), with engines that have a fixed vacuum thrust([math]F_0[/math]), the thrust level ([math]L = \frac{F}{F0}[/math]) is a linear function of current mass, with a constant proportionality coefficient ([math]c = \frac{a}{F0}[/math])

Which then means: Instead of having a complex formula there, you just do something along:

Code:
const double STAGE1_THRUST_CONTROL = STAGE1_ACC_LIMIT/STAGE1_MAXIMUM_THRUST;

...

double L = STAGE1_THRUST_CONTROL * GetMass();
SetThrusterLevel(thX, min(L, 1.0));
 
Last edited:

Grover

Saturn V Misfire
Addon Developer
Donator
Joined
Oct 3, 2010
Messages
1,468
Reaction score
0
Points
0
Location
Ascension Island
i understand it... kinda...

well, i suppose that since you didnt criticise my method (apart from it being perhaps a little bulky) that it at least works mathematically.

will it work inside orbiter as well? can you just change the value of a constant or float like that, and then have it stay like that untill you NULL it:
Code:
MaxEngineForce=NULL
or assign it a new value in a similar fashion?

in that case, i may yet manage to get this working!

thanks Urwumpe! you've definatley earned kudos in my book ;)
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Constant MEANS constant, you can't set it after initializing it.

It is also not needed, since you would also need to work with different stage data (other maximum thrust, other engine count, engine handle).

If you want to keep your code lean and mean, make this all an inline function, that you copy into the code that handles your current stage behavior.
 

Grover

Saturn V Misfire
Addon Developer
Donator
Joined
Oct 3, 2010
Messages
1,468
Reaction score
0
Points
0
Location
Ascension Island
so i can use the same set of code for multiple uses by assigning other functions (like using the API to get vessel mass, or using an external function to set the max acceleration) into the code, then using just one instance of the code?

ill keep to my easily-understandable one for now, but i do understand what you're saying, and i really appreciate it. maybe in the future i'll make coding like this much shorter and more efficient to run.

untill my next question...
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
so i can use the same set of code for multiple uses by assigning other functions (like using the API to get vessel mass, or using an external function to set the max acceleration) into the code, then using just one instance of the code?

Yes, like:

Code:
class MyVessel:public VESSEL3
{ 
   inline void LimitThrust(THRUSTERHANDLE thX, const double PropConstant)
   {
       //Like above
   }
};
 
Top