Glide Computer: Tactical Flight Planning¶
Library:
glide_computer_lib/glide_computer_lib.h- Glider performance models and polar curvesglide_computer_lib/glide_computer_lib.cpp- Implementationinclude/geographic.h- Geographic primitives: bounded coordinates (latitude, longitude, elevation) and orientation angles (azimuth, bearing, heading) with overflow policies and type-safeis_kindconstraints
Example:
glide_computer.cpp- Flight planning simulation
This advanced example implements a simplified tactical glide computer for sailplane (glider) flight planning. It demonstrates how mp-units can model a complex real-world aviation application with multiple interacting subsystems, geographic coordinates, and mixed unit systems.
What is a Glide Computer?¶
A glide computer is an avionic instrument used in soaring (glider) aviation to help pilots make tactical decisions about:
- Whether they can reach their destination from current altitude
- How long a flight will take given weather conditions
- When and where to climb in thermals (rising air columns)
- Optimal speeds to fly between waypoints
This example simulates these calculations for various glider types and weather conditions.
Domain Modeling¶
Custom Quantity Types¶
The example defines aviation-specific quantities:
| glide_computer_lib.h | |
|---|---|
This creates a distinct quantity type for vertical speed (rate of climb/sink), which is different from horizontal speed even though both have dimensions of length/time.
Type-Safe Aliases¶
The example uses type aliases for code clarity:
These aliases:
- Make code more readable (height vs generic length)
- Encode domain intent (these are specific aviation measurements)
- Don't sacrifice type safety (still checked at compile-time)
Complex Data Structures¶
The glider is modeled with its performance characteristics:
| glide_computer_lib.h | |
|---|---|
Each point on the polar curve describes the glider's sink rate at a given airspeed - fundamental aerodynamic data needed for flight planning.
Geographic Integration¶
The example uses a separate geographic module that provides type-safe geographic primitives.
Position and Coordinates¶
| geographic.h | |
|---|---|
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
The module defines six distinct angle types for geographic and aviation use:
- Latitude: reflects at ±90° boundaries (symmetric wrapping - can't cross poles)
- Longitude: wraps in half-open interval [-180°, 180°) (exclusive max)
- Elevation: reflects at ±90° (like latitude)
- Geometric Azimuth: 0° = East, counter-clockwise, wraps [-180°, 180°)
- Bearing: 0° = North, clockwise, wraps [-180°, 180°)
- Heading: 0° = North, counter-clockwise, wraps [-180°, 180°)
All types use is_kind to prevent accidental mixing (e.g., latitude + longitude or
bearing + heading won't compile). Each has:
- Distinct point origins with appropriate overflow policies
- Custom user-defined literals for coordinates (
_N,_S,_E,_W) - Aviation-style display formatting with prefixes (
"Az ","BRG ","HDG ")
Great Circle Distance¶
| geographic.h | |
|---|---|
The spherical_distance function calculates the shortest distance between two points
on Earth's surface using the great-circle formula. Since latitude and longitude use
is_kind, the function explicitly converts them to plain angular_measure for
trigonometric operations:
This ensures type safety while allowing mathematical operations when explicitly intended.
Waypoint Definition¶
With these geographic primitives, waypoints become simple and type-safe:
| glide_computer_lib.h | |
|---|---|
Each waypoint contains:
- Name (airport ICAO code)
- Geographic position with latitude/longitude using custom literals
- MSL altitude in aviation-standard feet
This shows how mp-units integrates with domain-specific abstractions while maintaining type safety across module boundaries.
Multi-System Units¶
The example naturally mixes unit systems as aviators actually do:
- SI units (
km/h,m/s) for glider performance - Yard-Pound units (
ft) for altitude (standard in aviation) - Latitude/longitude in degrees with custom literals
mp-units handles these conversions automatically and safely.
Key Features Demonstrated¶
1. Quantity Points for Absolute Values¶
| glide_computer_lib.h | |
|---|---|
Timestamps are absolute points in time, not durations - correctly modeled using
quantity_point with chrono_point_origin.
2. Custom Quantity Specifications¶
QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::speed,
mp_units::isq::height / mp_units::isq::duration);
Creates a specialized speed quantity specifically for vertical movement, distinct from general speed.
3. Dimensionless Ratios¶
| glide_computer_lib.h | |
|---|---|
The glide ratio (distance traveled per unit altitude lost) is a dimensionless quantity, correctly computed as a ratio of two speeds.
4. Complex Calculations¶
The library performs sophisticated calculations including:
- Distance between geographic coordinates
- Time-to-climb to thermal top
- Ground speed vs airspeed
- Safety margins and minimum altitudes
- Multi-leg route planning
All with full compile-time dimensional analysis.
5. Formatted Output¶
| glide_computer.cpp | |
|---|---|
Custom formatting for all quantity types makes the output readable for pilots.
Scenario Simulation¶
The main program runs multiple scenarios:
- 4 different glider types (from trainer to high-performance)
- 3 weather conditions (good, medium, bad thermals)
- Multi-waypoint tasks with varying distances
For each combination, it calculates whether the flight is possible and estimates the time required.
Sample Output¶
The program outputs detailed flight plans with proper unit formatting:
Safety:
=======
- Min AGL separation: 300 m
Gliders:
========
- Name: SZD-56 Diana
- Polar:
* -0.6366 m/s @ 110.0 km/h -> 48.0 (1.2°)
Waypoints:
==========
- EPPR: 54.24772° N 18.6745° E, 4.9 m AMSL
- EPGI: 53.52442° N 18.84947° E, 35.1 m AMSL
Weather:
========
- Good
* Cloud base: 1900 m AGL
* Thermals strength: 4.3 m/s
Task:
=====
- Start: EPPR
- Finish: EPPR
- Length: 162.5 km
- Legs:
* EPPR -> EPGI (81.2 km)
* EPGI -> EPPR (81.2 km)
Tow:
====
- Type: aircraft
- Height: 400 m
- Performance: 1.6 m/s
Scenario: Glider = SZD-56 Diana, Weather = Good
===============================================
| Flight phase | Duration | Distance | Height |
|--------------|-----------------------------|---------------------------|-----------------------|
| Tow | 4.2 min (Total: 4.2 min) | 0.0 km (Total: 0.0 km) | 400 m ( 405 m AMSL) |
| Glide | 2.6 min (Total: 6.8 min) | 4.8 km (Total: 4.8 km) | -100 m ( 305 m AMSL) |
| Circle | 7.3 min (Total: 14.1 min) | 0.0 km (Total: 4.8 km) | 1602 m (1907 m AMSL) |
| Glide | 41.9 min (Total: 56.0 min) | 76.8 km (Total: 81.6 km) | -1600 m ( 307 m AMSL) |
| Circle | 6.3 min (Total: 62.3 min) | 0.0 km (Total: 81.6 km) | 1383 m (1690 m AMSL) |
| Final Glide | 44.1 min (Total: 106.4 min) | 80.8 km (Total: 162.5 km) | -1685 m ( 5 m AMSL) |
Note
The above is just a part of the actual text output.
Each flight phase shows:
- Duration - time for this phase and cumulative total
- Distance - distance covered and total so far
- Height - altitude change and resulting MSL altitude
The output demonstrates:
- Tow - initial climb to release altitude (400 m AGL)
- Glide - descending flight between thermals
- Circle - climbing in thermals to regain altitude
- Final Glide - direct glide to destination without further thermals
All with automatic unit formatting showing proper aviation notation (km/h, m, m/s, AMSL).
Practical Applications¶
This example is close to what a real glide computer might do (though simplified). Real aviation software needs:
- ✅ Type safety - mixing altitude and distance is dangerous
- ✅ Multiple unit systems - aviation uses nautical miles, feet, meters, knots, etc.
- ✅ Exact conversions - no room for approximation errors
- ✅ Performance - zero runtime overhead from the units library
- ✅ Maintainability - clear, self-documenting code
mp-units provides all of these guarantees.
Key Takeaways¶
- Complex real-world applications can be fully typed with mp-units
- Custom quantity specifications capture domain-specific knowledge
- Multiple unit systems integrate seamlessly
- Geographic and physical quantities work together naturally
- Type safety scales to large, multi-module codebases
- The library doesn't get in the way of domain logic
This example shows that mp-units is production-ready for safety-critical aviation software where correctness is paramount.