MechJeb2

MechJeb2

4M Downloads

Accuracy of BurnTime(double dv) in Node Executor class

poteat opened this issue ยท 3 comments

commented

The current code takes the average acceleration over stages to estimate how long the burn will be. This function is primarily used to estimate how long a burn will take, so the autopilot will begin the burn early. In-game I've often noticed how it does not display the accurate value until it begins burning, and is highly inaccurate sometimes.

This is because, mathematically, maximum acceleration increases over the time of a burn due to mass loss. You can analytically take this into account by integrating Thrust/Mass(t) with respect to time.

I derived the following formula using integration:
burn_time_formula

I think most of the variables are pretty obvious, but to clarify:
t_burn-> Time the craft must burn at the apoapsis to achieve circularization
Isp -> Vacuum Isp of the craft,
g -> 9.81, or not, depending upon your units of Isp
m_i -> mass at the beginning of the burn
T -> Maximum thrust
S -> Standard gravitational parameter of current planet
r -> Radius of apoapsis
e -> orbital eccentricity at beginning of burn
Important note: The 'e' in the base of the exponent is Euler's number 2.718, not eccentricity.

It does not take into account the mass lost during staging, so it still requires some logic around it. Implement it or not, I don't mind. I'm using it for my project (also for beginning burns early), and thought it may or may not prove useful to you. I understand that a small amount of accuracy is rarely worth complicated code.

Attached is a small Excel spreadsheet I was using to confirm it worked.

Burn_time_calculation.xlsx

commented

The current node executor code currently takes this into account, and there's cleanup in #1061 which should further help

commented

Are you sure you looked at the right part of the code ? Because the current code does take the start and end mass of each stage into account.

commented

Yes, the delta-v calculation is spot-on. It gets inaccurate (by about a second and a half) when you calculate average acceleration. You're assuming that because mass has a constant negative rate, and a = T/m, that you can calculate the average mass and just use that to find the average acceleration.

However, because mass is in the denominator, the average acceleration does not equal thrust divided by the average mass.

On further perusal of the code, I realized the above formula can be simplified down, since you are given the required dv already.