Hopper rocket 3.0

Tutorial

Author: smoketeer

In Hopper rocket tutorials we’re paying tribute to historical rockets capable of powered landing in atmospheric environment, namely DC-X, Grasshopper and BlueShepherd. Instead of combining every bit of fall module into one script, we’re going to gradually build complexity.


This tutorial is a continuation of Tutorial: Hopper rocket 2.0.

Mission

Last time we’ve implemented Hopper rocket 2.0, which is capable of correcting its course during unpowered flight stage. This time we’re going to include powered landing guidance in the form of landingController.

Implementation

We’re going to reuse some code from previous tutorial.

Importing FALL

Things we need:

runoncepath("0:/fall/utilities/importFall").

importFall("hoverSlamModel").
importFall("landingDataModel").
importFall("glideController").
importFall("landingController").

Launch

Launch sequence comes from previous tutorials:

local ldata is landingDataModel(ship:geoposition).

lock steering to up.
lock throttle to 1.

// [ Launch ]
wait 1.
stage.
gear off.

// [ Ascent ]
wait until ship:apoapsis > 10000.
lock throttle to 0.
rcs on.

Gliding

Now we set up our glideController and give control to it when our ship starts falling:

// [ Gliding Prep ]
local glide is glideController(ldata, 5, 0.4).


// [ Gliding ]
wait until ship:verticalspeed < 0.
when alt:radar < 50 then { gear on. }

lock steering to glide["getSteering"]().

Landing

This time instead of setting up our hoverslam and locking steering to retrograde, we’re going to create landingController object:

// [Landing Prep]
local hoverslam is hoverSlamModel(10).
local landing is landingController(ldata, hoverslam, 5, 0.4).

Give it control over throttle:

lock throttle to landing["getThrottle"]().

And give it control over steering as soon as it outputs throttle larger than 0 and ship is lower than 5000 meters ATL:

// [ Powered Landing ]
wait until throttle > 0 and alt:Radar < 5000.
lock steering to landing["getSteering"]().

It’s very important to make sure that steering is given to landingController as soon as the engines are fired. Otherwise glideController steering scheme will bring opposite results to what is desired.

For the final touch, as usual, we add some logic so our ship can recognise when its landed:

wait until landing["completed"]().
lock throttle to 0.
rcs off.
wait until false.

Summary

We’re done! Our Hopper 3.0 is now capable of making an autonomous ascent, gliding towards target and finally performing a powered landing maneuver. Code as a whole looks like this:

 1 runoncepath("0:/fall/utilities/importFall").
 2 importFall("landingDataModel").
 3 importFall("hoverSlamModel").
 4 importFall("glideController").
 5 importFall("landingController").
 6 
 7 local ldata is landingDataModel(ship:geoposition).
 8 
 9 lock steering to up.
10 lock throttle to 1.
11 
12 // [ Launch ]
13 wait 1.
14 stage.
15 gear off.
16 
17 
18 // [ Ascent ]
19 wait until ship:apoapsis > 10000.
20 lock throttle to 0.
21 rcs on.
22 
23 // [ Gliding Prep ]
24 local glide is glideController(ldata).
25 
26 
27 // [ Gliding ]
28 wait until ship:verticalspeed < 0.
29 when alt:radar < 50 then { gear on. }
30 
31 lock steering to glide["getSteering"]().
32 
33 // [Landing Prep]
34 local hoverslam is hoverSlamModel(10).
35 local landing is landingController(ldata, hoverslam, 5, 0.4).
36 lock throttle to landing["getThrottle"]().
37 
38 // [ Powered Landing ]
39 wait until throttle > 0 and alt:Radar < 5000.
40 lock steering to landing["getSteering"]().
41 
42 wait until landing["completed"]().
43 lock throttle to 0.
44 rcs off.
45 wait until false.