LUA Lua script help, Delta-v

dgatsoulis

ele2png user
Donator
Joined
Dec 2, 2009
Messages
2,031
Reaction score
673
Points
128
Location
Sparta
I'm trying to show on screen how much dv a deltaglider has left with it's current fuel.

The formula is: Dv=ln(mo/m1)*(excaust velocity)
where m0= drymass
where m1= drymass+fuelmass

In the case of the DG the drymass is 11000 and the excaust-v is 40000

I already have the drymass and the drymass+fuelmass in the script.

How can i input, in Lua, the formula for the Dv above, in order to show the remaing Dv the spacecraft has?

Thank you in advance
:cheers:
 
Simple:

Code:
-- Inputs: 
--   w   Exhaust velocity
--   drymass
--   propmass

dv = math.log(drymass/(drymass + propmass)) * w
 
Simple, elegant, and worked like a charm!
Thank you very much! :tiphat:
 
is this going to be in a DV MFD? that will be incredibly useful for planning interplanetary burns
 
is this going to be in a DV MFD? that will be incredibly useful for planning interplanetary burns

You can use BurnTimeCalc for that, not sure if there is a 2010 version of it already though.
 
:ninja:
is this going to be in a DV MFD? that will be incredibly useful for planning interplanetary burns

There is one already.


The questions above where for a Lua Script.

---:ninja: by Urwumpe...
 
Last edited:
The solution Urwumpe gave me for the dv worked very well.
In my attempt to apply it for the XR2 i run to this problem: the drymass of the XR2 changes, due to oxygen and APU fuel consumption.

For the oxygen, i found a work-around. I just set the initial mass and then apply a rate of change due to time. Not perfect, but it works as long as you don't open the cabin hatch (on Earth) or don't have the external cooling online (landed or docked).

Here is a the piece of the script:
Code:
hp0 = v:get_propellanthandle (0)  -- main tank
hp1 = v:get_propellanthandle (1)  -- RCS tank
hp2 = v:get_propellanthandle (2)  -- SCRAM tank
m0 = 14200 -- main + rcs
mscram = 3350 --scram
[I]...snip (bla-bla-bla, initial fuel, create annotation)...snip[/I]

t_limit = 365
t_start = 52020.001
t_term = t_start+t_limit

[I]...snip (bla-bla-bla, wait for engines, create annotation)...snip[/I]

-- wait for landing event
planet = v:is_landed()
contact = false
while planet == nil do
    t_current = oapi.get_simmjd()
    t_rem = t_term - t_current
    o2_maxmass = 1013.7 -- the mass on LOXLoadout=3 for 365 days
    o2_mass = o2_maxmass*(t_rem / 365) -- rate of change for the oxygen
    excaust_v = 20775 -- default MainIsp=2 setting
    ship_mass = 16080 + 3384.60 + 78 + 58 + 268 -- ship,CHM,crew,crew and [I]apu fuel[/I]  
    dry_mass = o2_mass + ship_mass -- this way the drymass changes as the days pass
    m1a = v:get_propellantmass (hp0)
    m1b = v:get_propellantmass (hp1)
    m1c = v:get_propellantmass (hp2)
    d_vel = math.log (dry_mass / (dry_mass+m1a+m1b+m1c))*excaust_v*(-1) -- i know, instead of all that, i can use v:get_mass, but i'll need those later anyway
I]...snip (bla-bla-bla, landing vertical speed, passing the time limit, distance from target, annotation)...snip[/I]    
     msg = string.format("Rocket Fuel remaining:\n%.2f kg (Main) + %.2f kg (RCS)\nSCRAM fuel remaining: %.2f kg\nRemaining delta-v: %.2f m/s\nTime left: %.2f days", m1a, m1b, m1c, d_vel, t_rem)

Is there a function that i can use, to show the APU fuel consumption?

Thanks in advance
:cheers:
 
Last edited:
Back
Top