Victoria's Code STA / 01
GCS — build log

The EMERGENCY button that did nothing

I pressed HOLD on a drone and got this:

[FALCON-1] HOLD → REJECTED

No reason. Just no.

That turned out to be two problems. The first was annoying. The second scared me.

Problem 1: the console knew why and didn't say

The reason was there the whole time. It was in the result, and it was even saved to the flight recorder. The screen just didn't show it.

"It said no" is useless to an operator. You can't act on it. So I put the reason on the status line, about four lines of code:

[FALCON-1] HOLD → rejected — MAVLink adapter does not map command 'set_mode'

If that line had been there from the start, I wouldn't have had to go digging.

Problem 2: the drone never could do it

Every aircraft in my system has a list of what it says it can do: take off, land, return home, change mode. The screen uses that list to decide which buttons to show. The adapter, the code that talks to the drone, uses the same list to decide which commands to let through.

For this autopilot, the list said "change mode". But the code that actually sends that command to the drone had never been written.

So HOLD got past the check, because the list said yes. Then it reached the part that sends commands, which said no.

Then it hit me. EMERGENCY uses the same kind of command. On every aircraft of that type, the EMERGENCY button had never done anything. It was red. It lit up when you hovered. It looked exactly like a working button. In a real emergency you'd press it and get a refusal, and until that morning, a refusal with no reason.

I sat with that for a while.

Nothing crashed. No test would have caught it. Each piece was right on its own. The bug lived in the gap between them, and nothing was watching the gap.

The rule I should have written down earlier

That list isn't documentation. It's a promise, and both the screen and the safety check believe it. So:

An aircraft can only claim what it can actually do.

A test can check that, so now one does. For every adapter, it confirms that everything on the list really works.

If your interface builds its buttons from a list like this, treat the list like safety code, not like a config file.

While I was in there: disconnect now asks first

The console hid the Disconnect button while an aircraft was flying. But "Disconnect all" would cut off flying aircraft with one click and no warning. The safe path was blocked and the risky one was wide open right next to it.

Akala ko (I thought) disconnecting was harmless. The drone keeps flying, you just stop watching. I was wrong. My console sends the drone a heartbeat once a second. Both major open-source autopilots notice when it stops, and after a few seconds they go into failsafe: usually hold, then fly home or land. One of them stays in failsafe even after you reconnect.

That's a real consequence the operator never asked for, so it needs a confirmation. And the warning should say exactly what will happen, not just "Are you sure?". The dialog now reads:

HAWK-3 is AIRBORNE. Losing the ground-station link normally triggers the vehicle's own link-loss failsafe within a few seconds — typically hold, then return-to-launch or land, depending on how it is configured. Reconnecting may not return it to its current mode. This station stops sending its heartbeat and will no longer receive telemetry or be able to command it.

Cancel is the default. The confirm button says "Disconnect anyway", not "OK". And "Disconnect all" now tells you how many of those aircraft are in the air.

What should EMERGENCY even mean?

PX4, the autopilot this adapter talks to, has no "emergency mode". It has four different things you could mean:

  • Land: come down right here, whatever is underneath.
  • Return: fly home.
  • Kill switch: stop the motors. The drone falls.
  • Flight termination: everything off, parachute if there is one. No recovery.

Two of those save the drone. Two destroy it.

Picture the moment. Something's going wrong, the operator hits EMERGENCY, and what happens depends on which of the four the developer happened to pick. Expect a landing and get a falling drone: that's a crash. Expect the motors to stop and watch it fly itself home over a road instead: that's worse.

The label was the bug. Ang pindutan na may apat na kahulugan ay walang kahulugan (a button with four meanings has none). We already have LAND and RTL buttons, so an EMERGENCY that secretly means "land" is just LAND with a worse name.

So EMERGENCY is gone as a command. A drone can still report that it's in failsafe, and that belongs on the screen. You just can't press a vague button for it anymore.

The part that made me wince

Then I checked the adapter for the small consumer drone. There, EMERGENCY did work. It cut the motors instantly. One click, mid-flight, no confirmation.

Meanwhile disconnecting that same drone, which doesn't even touch the motors, now asked you to confirm.

I had built a console that guarded the action you can undo and waved through the one you can't.

What shipped

All of this went out the same week:

  • STOP MOTORS replaced EMERGENCY. It's its own command with an honest name.
  • It only appears on aircraft that can really do it. The consumer drone can. The PX4 adapter can't, and it tells you why if you try.
  • It asks first, in plain words: the drone will fall from where it is, so use LAND or RTL if you want it down safely.
  • A test checks that every adapter can do everything it claims, so this exact bug can't come back.

The bigger fix

Someone asked me: isn't this exactly what adapters are for? Yes. The design was fine. The list was just too vague. "Change mode" covered hover, fly home, land, and on some drones, cut the motors. Those are very different things.

So going forward:

  • Only the adapter knows what a drone can do. If the screen ever needs if (this is the little drone), the list is wrong. Fix the list, not the screen.
  • Split the list until it matches what an operator would tell apart. Stopping the motors is not a mode change.
  • Ask the drone, don't just trust the list. Two drones on the same autopilot can still differ. What the drone reports can only shrink the list, never grow it.

The goal is a screen that can't draw a button for something the drone can't do. Not "a test catches it". It just can't happen. Mas mahirap, pero iyon ang punto (harder, but that's the point). Adding a new vehicle should mean writing one adapter and nothing else.

One guardrail so I don't overdo it: a capability is something the drone can do, not something the screen shows. "Stop the motors" is a capability. "Show a battery icon" isn't.

What I'm taking away

The dead button wasn't a typo. Every piece worked. Two parts of the system described the same thing differently, and nothing checked that they matched. Bugs like that get through code review, kasi (because) each half looks fine on its own. Being more careful won't fix that. A test that checks it every time will.

And the small lesson: when your software says no, tell the person why. It already knows.


Build log entry. © Victoria's Code, all rights reserved.

Comments

Thoughts?

Comments are threads on GitHub, so a GitHub account is needed to post. No account? Email me instead — I read everything.