Last updated on

Convex-Optimization–Based Rocket Recovery in KSP


Based on Kerbal Space Program (KSP), this work addresses terminal powered descent and soft landing. Following a “Baseline → Plus → G‑FOLD convex optimization” pipeline, trajectory generation and tracking are unified within a single dynamics‑and‑constraints framework, emphasizing a small set of reusable hyperparameters, clear termination criteria, and an online‑deployable solution procedure.

1. Problem and Modeling

Dynamics (local constant gravity):

r˙=v,v˙=g+1mu,m˙=αu.(1)\dot{\mathbf r}=\mathbf v,\quad \dot{\mathbf v}=\mathbf g+\frac{1}{m}\mathbf u,\quad \dot m=-\alpha\|\mathbf u\|. \tag{1}

Thrust magnitude and tilt constraints:

TminuTmax,unucosθmax.(2)T_{\min}\le\|\mathbf u\|\le T_{\max},\quad \frac{\mathbf u\cdot \mathbf n}{\|\mathbf u\|}\ge \cos\theta_{\max}. \tag{2}

Glide-slope (relative to the landing site (\mathbf r_f)):

(rrf)ev  tan(γmax)(rrf)h.(3)(\mathbf r-\mathbf r_f)^\top \mathbf e_v\ \ge\ \tan(\gamma_{\max})\,\|(\mathbf r-\mathbf r_f)_h\|. \tag{3}

2. Method (Baseline → Plus → G‑FOLD)

2.1 Baseline: Energy‑Based Uniform Deceleration

Speed and distance estimates:

v2as,tbrakev0a,sreqv022a.(4)\|\mathbf v\|\approx\sqrt{2as},\quad t_{\mathrm{brake}}\approx \frac{\|\mathbf v_0\|}{a},\quad s_{\mathrm{req}}\approx\frac{\|\mathbf v_0\|^2}{2a}. \tag{4}

Speed upper bound:

v=min{2as,vmax}.(5)\|\mathbf v\|=\min\{\sqrt{2as},\,v_{\max}\}. \tag{5}

2.2 Plus: Reference‑Point Tracking + Thrust‑Cone Projection

Near a reference ((\mathbf x_i,\mathbf v_i,\mathbf u_i)), use PD form:

ad=ui+Kv(viv)+Kx(xir).(6)\mathbf a_d=\mathbf u_i+K_v(\mathbf v_i-\mathbf v)+K_x(\mathbf x_i-\mathbf r). \tag{6}

Terminal cylindrical region with tightened velocity/angular‑rate bounds:

C={ (rrf)hrf, 0(rrf)evhf },(7)\mathcal C=\{\ \|(\mathbf r-\mathbf r_f)_h\|\le r_f,\ 0\le (\mathbf r-\mathbf r_f)^\top\mathbf e_v\le h_f\ \}, \tag{7} vvf,ωωf.(8)\|\mathbf v\|\le v_f,\quad \|\boldsymbol\omega\|\le \omega_f. \tag{8}

2.3 G‑FOLD: Convex Trajectory Generation

Common convexification variables and discretization:

σ=1m,q=um.(9)\sigma=\frac{1}{m},\quad \mathbf q=\frac{\mathbf u}{m}. \tag{9} xk+1=Axk+Bqk+c,xk=[rk;vk].(10)\mathbf x_{k+1}=A\mathbf x_k+B\mathbf q_k+\mathbf c,\quad \mathbf x_k=[\mathbf r_k;\mathbf v_k]. \tag{10}

Discrete constraints and objective:

TminσkqkTmaxσk,qknqkcosθmax.(11)T_{\min}\sigma_k\le \|\mathbf q_k\|\le T_{\max}\sigma_k,\quad \frac{\mathbf q_k\cdot \mathbf n}{\|\mathbf q_k\|}\ge \cos\theta_{\max}. \tag{11} min{qk,σk} k=0N1qk.(12)\min_{\{\mathbf q_k,\sigma_k\}}\ \sum_{k=0}^{N-1}\|\mathbf q_k\|. \tag{12}

Terminal set:

rNrfεr,vNεv.(13)\|\mathbf r_N-\mathbf r_f\|_\infty\le \varepsilon_r,\quad \|\mathbf v_N\|_\infty\le \varepsilon_v. \tag{13}

3. Execution and Tuning (with Pseudocode)

Termination criteria (auto throttle cut):

(rrf)hrf, 0(rrf)evhf, vvf, ωωf.(14)\|(\mathbf r-\mathbf r_f)_h\|\le r_f,\ 0\le (\mathbf r-\mathbf r_f)^\top\mathbf e_v\le h_f,\ \|\mathbf v\|\le v_f,\ \|\boldsymbol\omega\|\le \omega_f. \tag{14}
# Simplified pseudocode (Python)
state = (r, v, m)
while True:
    v_data = pack_scene(state, params)         # g, T_min/max, theta_max, tf, ...
    path   = gfold_solve(v_data)               # {r_k, v_k, q_k, sigma_k}
    r_i, v_i, q_i = select_nearest(path, state)

    a_d = q_i + K_v*(v_i - v) + K_x*(r_i - r)  # (6)
    u   = conic_project(a_d, T_min, T_max, theta_max, n)  # satisfy (2),(11)

    attitude_thrust_follow(u)                  # align attitude to u; throttle tracks ||u||
    state = sense()                            # read latest state (e.g., via kRPC)

    if in_cylinder(r, r_f_radius, h_f_height) and \
       speed_ok(v, v_f) and angvel_ok(omega, w_f):  # (14)
        throttle(0.0); break

Demo Video