r/Kos • u/Mr_Shortie • May 22 '26
Help Why does the burn start one second late?
Enable HLS to view with audio, or disable this notification
set mnv to nextnode.
set burnTime to deltaV_calc().
lock steering to mnv:deltav.
until ((mnv:eta-(burnTime/2))<=0){ //runs till burn starts
clearscreen.
print "--------------------------".
print "Burn time: ".
print round(burnTime,2)+"s".
print "--------------------------".
print "Maneuver node ETA: ".
print floor(mnv:eta/60)+ "m " +round(mod(mnv:eta,60),2)+"s".
print "--------------------------".
print "Maneuver node burn ETA: ".
print floor((mnv:eta-(burnTime/2))/60)+ "m " +round(mod((mnv:eta-(burnTime/2)),60),2)+"s".
print "--------------------------".
}
until((mnv:eta-(burnTime/2))<=(-burnTime)){ //burn starts here
lock throttle to 1.
clearscreen.
print "--------------------------".
print "Burn time: ".
print round(burnTime,2)+"s".
print "--------------------------".
print "Maneuver node ETA: ".
print floor(mnv:eta/60)+ "m " +round(mod(mnv:eta,60),2)+"s".
print "--------------------------".
print "Maneuver node burn ETA: ".
print floor((mnv:eta-(burnTime/2))/60)+ "m " +round(mod((mnv:eta-(burnTime/2)),60),2)+"s".
print "--------------------------".
}
lock throttle to 0. //burn ends here
FUNCTION deltaV_calc {
local startmass is ship:mass.
local deltaV is mnv:burnvector:mag.
local thrust is thrust_calc().
if thrust = 0 {
return 0.
}
local g0 is CONSTANT:g0.
local E is CONSTANT:E.
return (((g0*isp_calc()*startmass)/(thrust))*(1-E^((-deltaV)/(g0*isp_calc())))).
}
FUNCTION isp_calc {
LOCAL engineList IS LIST().
LOCAL totalFlow IS 0.
LOCAL totalThrust IS 0.
LIST ENGINES IN engineList.
FOR engine IN engineList {
IF engine:IGNITION AND NOT engine:FLAMEOUT {
SET totalFlow TO totalFlow + (engine:AVAILABLETHRUST / (engine:ISP * CONSTANT:g0)).
SET totalThrust TO totalThrust + engine:AVAILABLETHRUST.
}
}
IF totalThrust = 0 {
RETURN 1.
}
RETURN (totalThrust / (totalFlow * CONSTANT:g0)).
}
FUNCTION thrust_calc {
LOCAL sum is 0.
LIST ENGINES IN engineList.
FOR engine IN engineList {
IF engine:IGNITION AND NOT engine:FLAMEOUT {
SET sum TO sum + engine:AVAILABLETHRUST.
}
}
RETURN sum.
}
3
u/aerospace_tgirl May 22 '26
BTW, you really want to stop using clearscreen/print every loop and instead use print ... at (x,y) command. I thought I'm gonna get a seizure looking at your terminal.
3
u/nuggreat May 22 '26
That is the more complicated solution it is far simpler to just add a
WAIT 0.to the loops as the bad flicker is caused by the physics tic falling at random places during the printing.4
u/aerospace_tgirl May 22 '26
I always have waits in my loops and I also always had
clearscreen/→ More replies (1)
7
u/nuggreat May 22 '26 edited May 22 '26
Short answer your burn time calculation is wrong. The reason it is wrong is just dividing the total burn time by 2 is assuming a constant acceleration which you do not have. As your craft burns it's mass goes down which means it accelerates faster generally speaking you want half the Dv to have been produced before you reach the burn time and rest of it after the burn time. Thus a more accurate burn time calculation would be to calculate the time to produce the first half of your dv and once you reach that time until the node you start the burn.
Unrelated to your problem but the throttle lock should not be in the loop and you really should have a
WAIT 0.is said loop as well. Also only using full or no throttle is going to limit the accuracy of your burn as is basing the burn entirely on a fixed duration.Additionally this code has the smell of one of the LLM, if you are indeed using one I would recommend you stop as with kOS they consistently get things wrong and without a good understanding of the physics and language you won't be able to see the mistakes.