Jump to content

Ypsilon

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by Ypsilon

  1. I've been wondering about the surface gravity, but my thinking was that it only needs to be reasonably accurate for the last calculation I do, as thoose are the only values I'm actually using to control the spacecraft. As that is usually below 1000m I was hoping to get away with using the surface gravity. Do you think that's to optimistic? I've been anticipating that my calculation won't be 100% accurate, but I think there's more at play here than that, as I am consistently and repeatably breaking to early. If the tick rate of my script was too slow, I'd expect to have more inconsistent results. As you say, sometimes burning too early, sometimes too late. But that's not the case. You're right of course about the 2.7171. I'd put that in there for debugging purposes and forgot to take it out before posting. But the problem happens as described regardless.
  2. I don't think floating point imprecision is the problem. I'm only doing ~10 operations and in the past I had to do a lot more before that became a problem. I've been testing either at Kerbin or the Mun. At Kerbin from ~15000m. This gives me a velocity of ~250m/s when the burn starts at ~900m. It slows me to 0 m/s which I reach at ~150m above ground. At the Mun I've done tests from ~35000m. This gives me a top speed of ~300m/s. The burn starts at ~835m and finishes at ~135m. I can totally land manually. The suicide burn leaves me about ~150m above the ground at 0m/s, so the hardest part from then on is to not overshoot the actual landing burn, as the engines are quite powerful for such a small craft.
  3. I'm trying to write a python script (using the kRPC mod) to do a suicide burn. However, so far I always reach a velocity of 0 a few hundred meters above the ground and then proceed to plummet to my death. My assumption is that the problem is a mathematical one, as the code is fairly simple. So I'd be very grateful if someone could check my math. Alternatively, if anyone has a different solution for what I'm trying to accomplish, I'd be happy to hear that to. For simplicity's sake I assume that my spacecraft is always pointing straight up and falling straight down. I also assume that there is no atmosphere and thus no drag. So here is what I have come up with: (Handwritten version of math) t: Time since start of the burn in seconds (s) Fe: Thrust of the spacecraft's engines in Newton (N) M0: Wet Mass of the spacecraft at the beginning of the burn in Kilogram (Kg) g: Surface gravity of the body I'm landing on in meters per second squared (m/s^2) W: Weight of the spacecraft in Newton (N) W = M0 * g F: Net thrust of the engine when decelerating the spacecraft in Newton (N) F = Fe - W K: Fuel consumption of the engine in Kilograms per second (Kg/s) a(t): Acceleration (or deceleration, depending how you look at it) of the spacecraft after t seconds, taking into account the decreased mass due to fuel being burned. In meters per second squared (m/s^2) a(t) = F / (M0 - K * t) Tb: Duration of engine burn in seconds (s) Dv(Tb): Speed change of spacecraft for a burn of Tb seconds in meters per second (m/s) Dv(Tb) = Integral from 0 to TB [a(t)] dt = Integral from 0 to Tb [F / (M0 - K * t)] dt = (F/K) * ln(1 + Tb * (K/M0)) Up until this point everything is based on this reddit comment. However, I am not sure if the integration for Dv(Tb) is correct. If I do it myself I get a different result, but the dimensional analysis for my result doesn't work out, so I've been sticking to this one. v0: velocity of spacecraft at the beginning of the suicide burn in meters per second (m/s) To calculate Tb, let Dv(Tb) = (F/K) * ln(1 + Tb * (K/M0)) = v0 and solve for Tb: Tb = (e^((v0 * K) / F) - 1) * (M0 / K) Da(Tb): Distance the spacecraft falls during burn of Tb seconds in meter (m) Da(Tb) = Integral from 0 to Tb [-v0 + Dv(Tb)] dt = Integral from 0 to Tb [-v0 + (F/K) * ln(1 + t * (K / M0))] dt Because I couldn't find an analytical solution for Da(Tb) I decided to solve it numerically every tick. I now run the above calculations every tick (multiple time per second) and then check if the resulting Da(Tb) is close to (within 10m) of the current altitude of my spacecraft. If it is I know I have to start the suicide burn. However, as mentioned above, it always starts a few hundred meters to early. It shouldn't be relevant, but this is the spacecraft I'm using to test my code. In case the above is to confusing to follow, here are my handwritten notes. They should contain the same information as above but more neatly formatted. Beware my handwriting though Also, is there a way to insert latex formulas in my post? I think that would have helped a lot. And this is a copy of my code so far, if anyone is interested: So, again, if anyone is willing to check my math, I'd be very grateful.
×
×
  • Create New...