Jump to content

How to calculate throttle to exactly counteract gravity?


Recommended Posts

but depends on the planet.

Just got it working, here's the code if anyone else would be interested:

var thrust = GetThrustInfo(FlightGlobals.ActiveVessel);

Vector3d CoM = FlightGlobals.ActiveVessel.GetWorldPos3D();
double localg = FlightGlobals.getGeeForceAtPosition(CoM).magnitude;
var throttle =  (FlightGlobals.ActiveVessel.totalMass * localg) / thrust;

 

Link to comment
Share on other sites

I'm not familliar with all the terms in your calculation (KOS?) so I'm not sure if you have it already, but it also depends on the angle your ship makes in relation to the planet.
Veer off for just a degree in any direction and the thrust won't be sufficiënt.
Better to add some trigonometry to account for this.

Link to comment
Share on other sites

4 hours ago, T-Bouw said:

I'm not familliar with all the terms in your calculation (KOS?) so I'm not sure if you have it already, but it also depends on the angle your ship makes in relation to the planet.
Veer off for just a degree in any direction and the thrust won't be sufficiënt.
Better to add some trigonometry to account for this.

This code is being used after a suicide burn, the velocity is minimal and the vessel is/should be upright

Link to comment
Share on other sites

On 24.04.2017 at 8:24 AM, linuxgurugamer said:

but depends on the planet.

Just got it working, here's the code if anyone else would be interested:


var thrust = GetThrustInfo(FlightGlobals.ActiveVessel);

Vector3d CoM = FlightGlobals.ActiveVessel.GetWorldPos3D();
double localg = FlightGlobals.getGeeForceAtPosition(CoM).magnitude;
var throttle =  (FlightGlobals.ActiveVessel.totalMass * localg) / thrust;

 

@linuxgurugamer, is this code supposed to run in a loop? If yes, for the performance reasons, I'd suggest calculating localg as mu/R^2, where mu is standard gravitational parameter of the parent body, R is distance from body center. In kOS it's as follows:

set rb to ship:position - body:position.
set localg to body:mu / (rb:x*rb:x + rb:y*rb:y + rb:z*rb:z).

Don't know how it looks like for mod development though.

From your code, it looks like that FlightGlobals.getGeeForceAtPosition is calculated as a vector, and only its magnitude is used. It adds a lot of unnecessary computations if you only need a scalar.

Link to comment
Share on other sites

On 24/4/2017 at 7:07 AM, linuxgurugamer said:

Subject says it.  I have the total thrust available, and the vessel mass.  What's the calculation to set the throttle to balance against gravity?

Thanks in advance

Maybe this mod is one of the best resources to answer such a question

The mod is great for hovering. I use it for my suicide burns (timing is manual), and then soft landings.

Link to comment
Share on other sites

22 minutes ago, Warezcrawler said:

Maybe this mod is one of the best resources to answer such a question

The mod is great for hovering. I use it for my suicide burns (timing is manual), and then soft landings.

thanks, I got it solved a couple of weeks ago.

 

Link to comment
Share on other sites

On 4/24/2017 at 1:43 AM, T-Bouw said:

I'm not familliar with all the terms in your calculation (KOS?) so I'm not sure if you have it already, but it also depends on the angle your ship makes in relation to the planet.
Veer off for just a degree in any direction and the thrust won't be sufficiënt.
Better to add some trigonometry to account for this.

Already taken care of.  I calculate how much dV is needed to stop the vessel, then calculate the distance to stop, and use the distance to the touchdown point to figure out when to start the burn. 

Believe it or not, just pointing prograde will effectivaly zero out your horizontal velocity, no need for any really complex calculations.

However, Mechjeb does essentially the same thing, but in a smoother way;  it doesn't use sas, it does it's own calculations.

On 4/29/2017 at 7:32 PM, Pand5461 said:

@linuxgurugamer, is this code supposed to run in a loop? If yes, for the performance reasons, I'd suggest calculating localg as mu/R^2, where mu is standard gravitational parameter of the parent body, R is distance from body center. In kOS it's as follows:


set rb to ship:position - body:position.
set localg to body:mu / (rb:x*rb:x + rb:y*rb:y + rb:z*rb:z).

Don't know how it looks like for mod development though.

From your code, it looks like that FlightGlobals.getGeeForceAtPosition is calculated as a vector, and only its magnitude is used. It adds a lot of unnecessary computations if you only need a scalar.

  @Pand5461      

That was an early calculation, when I first got it work.

Currently, this is what I'm doing:

 

float gravHeight = (float)this.vessel.altitude + (float)vessel.mainBody.Radius; //gravity force at this altitude (not in m/s^2)            

double localg = (float)vessel.mainBody.gMagnitudeAtCenter / (float)Math.Pow(gravHeight, 2); //accel down due to gravity in m/s^2

It is faster.         

         

Edited by linuxgurugamer
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...