Hopper rocket 1.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.


Hopper v1.0 Stock

Mission

You can either build your own rocket, or download a ready to go fully stock KSP v.1.6.1:

Hopper v1.0 Rocket

Remember, we want to start small! Mind you, if you decide to use your own rocket, tuning may slightly differ.

We want our rocket to have:

  • RCS at the top
  • landing gear
  • no clamps!

We’re going to:

  • launch the rocket straight up
  • land anywhere, without location requirement

Implementation

You can either create a regular script in your archive(“0:/”), or a boot script in your boot directory.

Importing FALL

Let’s get into it! First we want to load FALL libraries. In this tutorial we need only the hoverSlamModel:

runoncepath("0:/fall/models/hoverSlamModel").

Launch

Now let’s add some launch logic:

lock steering to up. // we want to go straight up
lock throttle to 1.

// turn on the engines
wait 1.
stage.
gear off.

// gain some decent altitude
wait until ship:apoapsis > 500.
lock throttle to 0.

// wait until falling
wait until ship:verticalspeed < 0.
rcs on.

// deploy landing gear when 50 meters ATL
when alt:radar > 50 then { gear on. }

Landing

At this stage our rocket majestically falls to its inevitable destruction. But have no fear! Hoverslam is here to rescue us:

// creating new hoverSlamModel object
// 10 is height of the rocket
local hoverslam is hoverSlamModel(10).
// let hoverslam control the throttle
lock throttle to hoverslam["getThrottle"]().

wait until ship:status = "landed".
// Uff! We've done it!

How does it work? HoverSlamModel implements getThrottle() method. It calculates when(as late as possible) and how much throttle should be applied to successfully kill all the velocity before our rocket hits the ground.

Summary

Code as a whole looks like this:

 1 runoncepath("0:/fall/models/hoverSlamModel").
 2 
 3 lock steering to up.
 4 lock throttle to 1.
 5 
 6 wait 1.
 7 stage.
 8 gear off.
 9 
10 wait until ship:apoapsis > 500.
11 lock throttle to 0.
12 
13 wait until ship:verticalspeed < 0.
14 lock steering to ship:srfretrograde.
15 rcs on.
16 
17 when alt:radar > 50 then { gear on. }
18 local hoverslam is hoverSlamModel(10).
19 lock throttle to hoverslam["getThrottle"]().
20 
21 wait until ship:status = "landed".

But what if?

Let’s take a look at line 10 of this code. What happens if we increase this number to say, 10000? Our ship will still go straight up and land, but you’ll notice that we’ve landed far away from the launchpad. That’s not good!

In the next tutorial we will try to reduce the error when falling from higher altitudes.

Hopper Rocket 2.0