I want to simulate suicide burn to learn and understand rocket landing. OpenAI gym already has an LunarLander enviroment which is used for training reinforcement learning agents. I am using this enviroment to simulate suicide burn in python. I have extracted the coordinates (x,y)
from the first two values of state vector of this enviroment. From these values, considering y
coordinates as the altitude; I have calculated velocity and accelartion of the falling lander using these equations
velocity(v) = delta_y/ delta_t
acceleartion(a) = delta_v/delta_t
As the simulation is incrementing stepwise the difference in time delta_t
was taken as 1. Unable to find the gravity parameter of LunarLander I gave it a default value g=1
. Then using the below equation from this reddit comment
altitude to start suicide burn = [ (current altitude)(acceleration of gravity) + (1/2)(current velocity)2 ] / (acceleration of engines)
I tried to calculate altitude to start suicide burn. This is my full python code. I am only planning to use two actions 0(do nothing) and 2(start main engine) of the four possible actions.
import gym
env = gym.make('LunarLander-v2')
env.seed(0)
g = 1
delta_t = 1
action = 0
state = env.reset()
# x0 = state[0]
y0 = state[1]
v0 = 0
for t in range(3000):
state, reward, done, _ = env.step(action)
y = state[1]
if done or y <0:
break
v = (y-y0)/delta_t # velocity
a = (v - v0)/delta_t # acceleration
# (altitude to start suicide burn) = [ (current altitude)(acceleration of gravity) + (1/2)(current velocity)2 ] / (acceleration of engines)
alt_burn = [y*g+0.5*v*v]/a
v0 = v
y0 = y
print(" y",round(y,5)," v",round(v,5)," a",round(a,5)," Alt_burn",round(alt_burn[0],5))
The output results looks something like this
y 1.41542 v 0.00196 a 0.00196 Alt_burn 722.35767
y 1.41678 v 0.00136 a -0.0006 Alt_burn -2362.78166
y 1.41754 v 0.00076 a -0.0006 Alt_burn -2362.63867
y 1.4177 v 0.00016 a -0.0006 Alt_burn -2362.43506
y 1.41726 v -0.00044 a -0.0006 Alt_burn -2362.64046
y 1.41622 v -0.00104 a -0.0006 Alt_burn -2359.03148
y 1.41458 v -0.00164 a -0.0006 Alt_burn -2358.17355
y 1.41233 v -0.00224 a -0.0006 Alt_burn -2353.50518
y 1.40949 v -0.00284 a -0.0006 Alt_burn -2349.24118
y 1.40605 v -0.00344 a -0.0006 Alt_burn -2343.51016
y 1.40201 v -0.00404 a -0.0006 Alt_burn -2336.31535
y 1.39737 v -0.00464 a -0.0006 Alt_burn -2329.04954
If we look at altitude(y) its a very small value less than 1.5 whereas the calculated altitude to start suicide burn are very high. How can I solve this problem?
In the reddit comments they have only mentioned to start the engine but not to end it. Anyone knows the math for killing the engine dynamically?