Passing Control

Advanced topic

POSSIBLE CHANGES

Each controller object implements a passControl method. It is a QoL feature that abstracts the most common way of using specific controller, but you can achieve the exact same results by using getThrottle, getSteering, completed methods.

Even though passControl is considered QoL, it does have it’s quirks when it comes to gliding related controllers. If you’re a beginner I’d recommend avoiding passControl method in glideController and glidePIDController for the time being.

Table of contents:

Blocking nature

Controller.passControl method is using wait to hold control until completed method returns true. It means that until certain condition is met, the passControl method will not fully execute.

Unlocks control after execution

By default passControl will unlock both steering and throttle at the end of execution. You can change this behavior by calling it with false argument.

How it works

Let’s consider two examples. First:

local ascent is ascentController(35000, 90, 10, 3).

lock steering to ascent["getSteering"]().
lock throttle to ascent["getThrottle"]().

wait until ascent["completed"]().

unlock steering.
unlock throttle.

and second:

local ascent is ascentController(35000, 90, 10, 3).
ascent["passControl"]().

Both do the exactly same thing.

The Quirks

Now that we know very basic logic of passControl, let’s consider glidePIDController object :

local glide is glidePIDController(ldata, 2000).

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

wait until glide["completed"]().
// what happens here?

Which is equivalent to:

local glide is glidePIDController(ldata, 2000).
glide["passControl"](false).
// what happens here?

By default glidePIDController["completed"]() returns true only if the throttle is larger than 0 and gliding related controllers never apply any throttle. This means that if you don’t setup any kind of event before passing control, it will never fully execute.

Currently this problem occurs only with glide related controllers.

How to deal with it

Even though passing control to glide controllers seems quite scary, there are ways to deal with their nasty nature.

When … then …

We can setup a when ... then ... before passing control:

local glide is glidePIDController(ldata, 2000).

when alt:radar < 3000 then
{
   lock throttle to 1. // or for example landingController["getThrottle"]()
}

glide["passControl"](false).

Overloading

We could also overload completed method:

local landing is landingController(ldata).
local glide is glidePIDController(ldata, 2000).

glide["completed"] = {
   return landing["getThrottle"]() > 0.
}

glide["passControl"]().
landing["passControl"]().

This way gliding controller will release control as soon as our landing controller wants to start the final burn.