A number is not a measurement
For weeks my console showed altitude as 394. The number was right. But on its own it didn't tell you much, because you need three more things before a number means anything:
- The unit. 394 feet or 394 meters? Both are normal heights for a small drone, and one is three times the other.
- Where it's measured from. Sea level, or the ground under the drone? Over a 200-meter hill, that's a big difference.
- How old it is. Is the drone there now, or was it there before the radio went quiet?
I knew all three because I wrote the code. That's fine until someone else is flying. So today I put them on the screen.
The plan
Two small things: a metric/imperial switch, and a little card that shows a drone's status when you hover over it. An easy afternoon, I thought.
What I built
All unit conversions now live in one file. Before this, one part of the
screen had * 3.28084 written straight into it to turn meters into feet. Do
that in enough places and you get different rounding everywhere, and no clean
way to add a switch.
The rule, which I wrote at the top of that file:
Inside the system, everything is metric: meters, meters per second, and standard GPS coordinates (WGS84). Drivers convert when they talk to hardware. The screen is the only other place a unit can change.
This isn't about neatness. If feet sneak into the inside of the system, they end up in the flight recorder. Then nobody can replay a recording without knowing which setting the operator picked that day. A recording has to mean the same thing forever.
The screen says where altitude is measured from. The drone card now reads
394 ft MSL, meaning above sea level, which is what the drone actually reports.
The takeoff height box says AGL, meaning above the ground, because that's
measured from where the drone is sitting. Both are "altitude" and both used to
show as a plain number. For weeks the simulator and the screen were off by
exactly the height of the terrain, and I thought it was a sync bug. It was just
a missing label.
Hover to see status. Point at a drone on the map or in the list and a small card pops up: link, battery, mode, armed or not, altitude, and last update, counting up in seconds. No clicking needed.
That last line is the important one. It answers question three. It also follows the rule from last time: when the link goes quiet, every live value turns into a dash and only the age keeps counting. The card shows you what it doesn't know.
What surprised me
A test caught me loosening a safety limit. The takeoff height box has a minimum and a maximum. Small drones are usually kept to about 400 meters above the ground. For imperial I added my own limits: 3 to 1312 feet.
Then I wrote a test to check that the feet limits always sit inside the meter limits. It failed. 3 feet is 0.914 meters, and my metric minimum was 1 meter. So just by switching to feet, an operator could set a takeoff height lower than metric allowed.
Nine centimeters, on the minimum. Not a big deal by itself. But the way it happened is the problem: changing a display setting changed a safety rule. If that happens on the maximum instead, a screen preference is quietly moving a legal limit. Nakakatakot (that's scary). I only caught it because I wrote the test. Now converted limits always round inward, and "switching units can never loosen a limit" is a test, not just a comment.
That's why conversions belong in one tested file. Spread across six screens, that bug has six places to hide.
The hover card keeps its own clock. "8s ago" has to keep counting even when nothing new arrives, and no new data means nothing tells the screen to update. I expected to pass a timestamp down through everything. Instead, the card runs its own one-second timer, only while your mouse is on a drone. Nothing else on the screen has to redraw for it.
I almost copy-pasted it. Two maps needed the same hover behavior. I built the first one, started copying into the second, then stopped and made one shared piece. The map only says "this drone was hovered, here." It knows nothing about batteries or modes, and I want to keep it that way.
What I'm taking away
Every number on the screen is making a claim, and it can be wrong in three ways:
- Wrong unit: off by a multiple, like 3x. Usually easy to spot. Sometimes deadly.
- Wrong starting point: off by the height of the ground. Hard to spot, because the number still looks normal.
- Too old: not wrong, just not true anymore. You can't tell by looking at it.
The console now answers all three. It cost a few extra letters on the screen.
What's next
Move link-loss detection out of the screen and into the drone link itself, so the parts of the system that act on it (fly home, hold, surface) know the drone has gone quiet too, not just the person watching.
Build log entry. © Victoria's Code, all rights reserved.
Thoughts?
Comments are threads on GitHub, so a GitHub account is needed to post. No account? Email me instead — I read everything.