I used GetBurnTime from TransX to program burns in Lua.
In DG-XR1 "In orbit" scenario I type:
And the error seems to grow with the growth in commanded dV. As I understand, if it were the frame rate to blame for the error, the error would be more or less constant (with high Isp propellants mass depletion isn't a problem). The burns aren't long, so loss of velocity during the burn is not large either. So my guesses are:
a) TransX doesn't calculate burn time correctly (strange!)
or b) Lua proc.wait_simdt() isn't good
or c) something else (like Mr.Murphy stepping in and ruining the show).
the testcode.lua file:
In DG-XR1 "In orbit" scenario I type:
Code:
run('testcode')
pulse_dv('XR1-01', 10.0)
pulse_dv('XR1-01', 20.0)
pulse_dv('XR1-01', 30.0)
And the error seems to grow with the growth in commanded dV. As I understand, if it were the frame rate to blame for the error, the error would be more or less constant (with high Isp propellants mass depletion isn't a problem). The burns aren't long, so loss of velocity during the burn is not large either. So my guesses are:
a) TransX doesn't calculate burn time correctly (strange!)
or b) Lua proc.wait_simdt() isn't good
or c) something else (like Mr.Murphy stepping in and ruining the show).
the testcode.lua file:
Code:
function pulse(vessel_name, dt, thrustlevel)
local v = vessel.get_interface(vessel_name)
if v == nil then
term.out ('Could not find '..vessel_name..'. Aborting')
return
end
local tacc = oapi.get_tacc()
oapi.set_tacc(1.0)
v:set_thrustergrouplevel(THGROUP.MAIN, thrustlevel)
proc.wait_simdt(dt)
v:set_thrustergrouplevel(THGROUP.MAIN, 0.0)
oapi.set_tacc(tacc)
end
-- from transX
function get_burntime(vessel_name, dV, thrustergroup, thrustlevel)
local v = vessel.get_interface(vessel_name)
if v == nil then
term.out ('Could not find '..vessel_name..'. Aborting')
return
end
-- Returns the time to burn to the required deltaV. Calculates via rocket equation
local d_V = dV
if(dV < 0) then
d_V = -dV
end
local T = 0
local isp = 0
local numThrusters = v:get_groupthrustercount(thrustergroup)
for i = 0, numThrusters-1 do
local thruster = v:get_groupthruster(thrustergroup,i)
T = T+ v:get_thrustermax0(thruster)*thrustlevel
isp = isp+ v:get_thrusterisp0(thruster)
end
return - (isp * v:get_mass() / T * (math.exp(-d_V / isp) - 1.0))
-- return - (isp * GetStackMass(vessel) / T * (exp(-d_V / isp) - 1.0))
end
function pulse_dv(vessel_name, dV)
-- todo: add check for attitude! add thruster throttling before cutoff
local v = vessel.get_interface(vessel_name)
if v == nil then
term.out ('Could not find '..vessel_name..'. Aborting')
return
end
local tacc = oapi.get_tacc()
oapi.set_tacc(1.0)
local body = v:get_surfaceref()
local currV = v:get_relativevel(body)
local currVmod = vec.length(currV)
local dt = get_burntime(vessel_name, dV, THGROUP.MAIN, 1.0)
pulse(vessel_name, dt, 1.0)
local newVmod = vec.length(v:get_relativevel(body))
local dV_error = dV - (newVmod-currVmod)
oapi.dbg_out(string.format("delta V error: %.4f", dV_error))
oapi.set_tacc(tacc)
end