Lunar Lander bug?
06-10-2014, 09:02 PM
Post: #1 David Hayden Member Posts: 277 Joined: Dec 2013
Lunar Lander bug?
I was playing with the lunar lander game on my 29C and took a look at the source code. I can't figure out the terminal velocity calculation and I was wondering if someone could walk me through it. The program is here.

Lines 46-50 indicate that a burn b accelerates the craft by a=2b-5. This indicates that gravity is -5. It's also easy to deduce that each burn lasts 1 second.

So when you burn the last of the fuel, what is the crash velocity? To figure this out, recognize that you get a 1 second burn consisting of the all the fuel (a=2b-5), followed by a free fall that ends in a crash landing (a=-5). Using the equations provided:
\begin{equation}a_0=2b-5\\
v_1 = v_0+a_0t = v_0+2b-5\\
x_1 = x_0+v_0t+\frac{1}{2}a_0t^2 = x_0+v_0+b-2.5\\
v_f^2 = v_1^2 + 2a_1(x_f-x_1) = v_1^2 + 2a_1(0-x_1) = v_1^2+2*(-5)*(-x_1)\\
v_f = -\sqrt{v_1^2+10x_1}\end{equation}

Lines 41-44 compare the burn amount to the remaining fuel. If you're burning the last of the fuel it goes to label 6 at line 68.
Lines 69-74 add b-2.5 to x
Lines 75-77 add 2b-5 to v
Lines 78-86 compute vf from x

I don't understand lines 69-74. It seems to me that it should subtract v from x also. Am I missing something or is this a bug?

Thanks,
Dave
06-11-2014, 07:28 AM
Post: #2
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: Lunar Lander bug?
(06-10-2014 09:02 PM)David Hayden Wrote:  I don't understand lines 69-74. It seems to me that it should subtract v from x also. Am I missing something or is this a bug?

But in some cases that might turn out negative and then you have a problem when taking the square root in line 85. You could change the program that in lines 41-44 you just use the remaining fuel if the entry was bigger than that (no branch to LBL 6), calculate the new values, check whether we crashed and check whether we still have fuel. Only then loop back. Otherwise calculate the final crash velocity. With this approach the redundant calculations after LBL 6 could be avoided.

Cheers
Thomas

PS: The LBL 9 in line 40 could probably be removed.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)