Project Overview:
During Starship SN15's scrubbed launch window, I developed a 2D simulation of its landing maneuver. After optimizing the flight dynamics model, I recreated the vehicle's signature "belly flop" to a vertical landing sequence.
Compared to actual SpaceX footage, the simulation showed remarkable accuracy - despite being developed purely from first principles without reference to empirical data.
Understanding Optimal Trajectories
In trajectory optimization, "optimal" refers to finding the best path to achieve a goal. Consider walking to your fridge - while countless paths exist, some are better than others.
To determine the best path, we define a "cost function" (similar to machine learning). A simple cost function might measure path length. However, this can lead to impractical solutions - a shortest-path algorithm would ignore obstacles like a pit on the floor.
A more sophisticated approach uses "effort" as the cost function. In this model, each step on safe ground might cost 1 unit, while traversing dangerous areas costs significantly more (e.g., 1000 units). This better reflects real-world optimization problems, like Starship's landing trajectory, where we balance multiple factors including fuel usage, structural loads, and safety margins.
The final piece is adding constraints - rules defining valid solutions. These ensure our optimization stays within physical and practical limits while minimizing our chosen cost function.
Trajectory Optimization Code:
While waiting for Starship SN15's launch (which was ultimately scrubbed), I developed a physics-based optimization model to simulate its distinctive landing maneuver. Here's the key code that made it work:
# Physical parameters for Starship self.m = 100000 # kg (total mass) self.length = 50 # m self.max_thrust = 2210000 # N (single Raptor) self.max_gimbal = np.deg2rad(20)
The optimization minimized a cost function balancing engine effort and stability:
cost = 0 for i in range(self.N - 1): cost += U[0, i] ** 2 # Minimize thrust cost += 100 * U[1, i] ** 2 # Minimize gimbal angle cost += 200 * X[5, i] ** 2 # Minimize angular velocity
What proved particularly remarkable was comparing the simulation output against actual SpaceX landing footage—the trajectories aligned with surprising accuracy, despite the model being developed purely from first principles without reference to empirical flight data.
Animated Trajectory:
See the attached GitHub below:
Starship-Optimization
ewshu • Updated Jan 2, 2025
Â