Grasshopper Flight 1

Mission Code

Mission Overview

The first flight of the grasshopper was in reality just a hop. The flight lasted only 3 seconds and reached a maximum altitude of 6ft (1.8m).

Simulation Plan

While SpaceX likely had a fairly advanced control system on board (even if it was only their first flight), this program will be using a very basic starting point. This is to ensure the basic functionality of kOS with the rocket, and to not take too large of a step without adequate testing. This program simply tests some sensors and performs a mostly blind hop that meets the mission requirements.

Code Walkthrough

Constants

The first section of the code simply defines the constants for use during the flight. Some are specific to this flight, and some are constant across multiple. One of note are the variables used for the throttle shifting. Because the engines cannot throttle all the way down to 0%, the calculated 0 – 100 range needs to be mapped onto the throttle control (which only goes from minThrottle to 100). To do this, the minimum throttle is declared, and then adjThrottle is mapped as follows

$$adjThrottle = \frac{glbThrottle – minThrottle}{1 – minThrottle}$$

This converts a given glbThrottle, which is a value from 0 – 100, to the appropriate throttle setting for the real, minThrottle – 100 range. So, glbThrottle is the percentage of the engines total thrust desired. adjThrottle is then the percentage the throttle on the navball needs to be set too.

There is also a constant (twr) for the thrust to weight ratio of the rocket. This is used to control the acceleration relative to gravity (i.e. hover is 1.0/twr). The value is calculated using

$$twr = \frac{\textrm{SHIP:MAXTHRUST}}{\textrm{SHIP:MASS} \cdot grv}$$

Structure

The interesting part of the program is contained within an until loop which prints out some debug information and then actually controls the rocket. There are three states the program can be in. The first is step = 0. In this state the rocket is accelerating upwards, and does so at a constant 1.2G’s of thrust. At 1/3 the target altitude it switches to step = 1, where it is slowing down and falling. For this the engines are run at 0.8G’s. Finally, when it is on the ground it cuts the engine and moves to step = 2 for cleanup.

Takeaways

The biggest thing to note is that if the rocket is going to be able to meet the criteria precisely, it will need more than a guestimate about the thrust to run at and when to switch. The 1/3 height guess worked okay, but over longer distances (such as Grasshopper Flight 2) it would miss the target more and more. A way to follow a predetermined flight path would greatly help.