forked from mpusz/mp-units
refactor(example): msl_altitude
moved to geographic.h
and the header file was moved to another dir in examples
This commit is contained in:
@@ -22,6 +22,6 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
add_library(glide_computer STATIC include/geographic.h glide_computer.cpp include/glide_computer.h)
|
add_library(glide_computer STATIC glide_computer.cpp include/glide_computer.h)
|
||||||
target_link_libraries(glide_computer PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility example_utils)
|
target_link_libraries(glide_computer PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility example_utils)
|
||||||
target_include_directories(glide_computer PUBLIC include)
|
target_include_directories(glide_computer PUBLIC include)
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#include "glide_computer.h"
|
#include "glide_computer.h"
|
||||||
|
#include <mp_units/format.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -48,7 +49,7 @@ std::vector<distance> task::make_leg_total_distances(const legs& legs)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
altitude terrain_level_alt(const task& t, const flight_point& pos)
|
geographic::msl_altitude terrain_level_alt(const task& t, const flight_point& pos)
|
||||||
{
|
{
|
||||||
const task::leg& l = t.get_legs()[pos.leg_idx];
|
const task::leg& l = t.get_legs()[pos.leg_idx];
|
||||||
const height alt_diff = l.end().alt - l.begin().alt;
|
const height alt_diff = l.end().alt - l.begin().alt;
|
||||||
@@ -58,7 +59,8 @@ altitude terrain_level_alt(const task& t, const flight_point& pos)
|
|||||||
// Returns `x` of the intersection of a glide line and a terrain line.
|
// Returns `x` of the intersection of a glide line and a terrain line.
|
||||||
// y = -x / glide_ratio + pos.alt;
|
// y = -x / glide_ratio + pos.alt;
|
||||||
// y = (finish_alt - ground_alt) / dist_to_finish * x + ground_alt + min_agl_height;
|
// y = (finish_alt - ground_alt) / dist_to_finish * x + ground_alt + min_agl_height;
|
||||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt)
|
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s,
|
||||||
|
geographic::msl_altitude ground_alt)
|
||||||
{
|
{
|
||||||
const auto dist_to_finish = t.get_distance() - pos.dist;
|
const auto dist_to_finish = t.get_distance() - pos.dist;
|
||||||
return quantity_cast<isq::distance>(ground_alt + s.min_agl_height - pos.alt) /
|
return quantity_cast<isq::distance>(ground_alt + s.min_agl_height - pos.alt) /
|
||||||
@@ -150,8 +152,8 @@ void estimate(timestamp start_ts, const glider& g, const weather& w, const task&
|
|||||||
// estimate aircraft towing
|
// estimate aircraft towing
|
||||||
pos = tow(start_ts, pos, at);
|
pos = tow(start_ts, pos, at);
|
||||||
|
|
||||||
// estimate the altitude needed to reach the finish line from this place
|
// estimate the msl_altitude needed to reach the finish line from this place
|
||||||
const altitude final_glide_alt =
|
const geographic::msl_altitude final_glide_alt =
|
||||||
t.get_finish().alt + quantity_cast<isq::height>(t.get_distance() / glide_ratio(g.polar[0]));
|
t.get_finish().alt + quantity_cast<isq::height>(t.get_distance() / glide_ratio(g.polar[0]));
|
||||||
|
|
||||||
// how much height we still need to gain in the thermalls to reach the destination?
|
// how much height we still need to gain in the thermalls to reach the destination?
|
||||||
|
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "geographic.h"
|
#include "geographic.h"
|
||||||
#include <mp_units/chrono.h>
|
#include <mp_units/chrono.h>
|
||||||
#include <mp_units/format.h>
|
|
||||||
#include <mp_units/math.h> // IWYU pragma: keep
|
#include <mp_units/math.h> // IWYU pragma: keep
|
||||||
#include <mp_units/quantity_point.h>
|
#include <mp_units/quantity_point.h>
|
||||||
#include <mp_units/systems/isq/space_and_time.h>
|
#include <mp_units/systems/isq/space_and_time.h>
|
||||||
@@ -54,14 +53,11 @@
|
|||||||
namespace glide_computer {
|
namespace glide_computer {
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Flight_planning#Units_of_measurement
|
// https://en.wikipedia.org/wiki/Flight_planning#Units_of_measurement
|
||||||
inline constexpr struct mean_sea_level : mp_units::absolute_point_origin<mp_units::isq::height> {
|
|
||||||
} mean_sea_level;
|
|
||||||
QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::speed, mp_units::isq::height / mp_units::isq::time);
|
QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::speed, mp_units::isq::height / mp_units::isq::time);
|
||||||
|
|
||||||
// length
|
// length
|
||||||
using distance = mp_units::quantity<mp_units::isq::distance[mp_units::si::kilo<mp_units::si::metre>]>;
|
using distance = mp_units::quantity<mp_units::isq::distance[mp_units::si::kilo<mp_units::si::metre>]>;
|
||||||
using height = mp_units::quantity<mp_units::isq::height[mp_units::si::metre]>;
|
using height = mp_units::quantity<mp_units::isq::height[mp_units::si::metre]>;
|
||||||
using altitude = mp_units::quantity_point<mp_units::isq::altitude[mp_units::si::metre], mean_sea_level>;
|
|
||||||
|
|
||||||
// time
|
// time
|
||||||
using duration = mp_units::quantity<mp_units::isq::duration[mp_units::si::second]>;
|
using duration = mp_units::quantity<mp_units::isq::duration[mp_units::si::second]>;
|
||||||
@@ -72,29 +68,7 @@ using timestamp = mp_units::quantity_point<mp_units::isq::time[mp_units::si::sec
|
|||||||
using velocity = mp_units::quantity<mp_units::isq::speed[mp_units::si::kilo<mp_units::si::metre> / mp_units::si::hour]>;
|
using velocity = mp_units::quantity<mp_units::isq::speed[mp_units::si::kilo<mp_units::si::metre> / mp_units::si::hour]>;
|
||||||
using rate_of_climb = mp_units::quantity<rate_of_climb_speed[mp_units::si::metre / mp_units::si::second]>;
|
using rate_of_climb = mp_units::quantity<rate_of_climb_speed[mp_units::si::metre / mp_units::si::second]>;
|
||||||
|
|
||||||
// text output
|
|
||||||
template<class CharT, class Traits>
|
|
||||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const altitude& a)
|
|
||||||
{
|
|
||||||
return os << a.absolute() << " AMSL";
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace glide_computer
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct STD_FMT::formatter<glide_computer::altitude> :
|
|
||||||
formatter<mp_units::quantity<mp_units::isq::altitude[mp_units::si::metre]>> {
|
|
||||||
template<typename FormatContext>
|
|
||||||
auto format(const glide_computer::altitude& a, FormatContext& ctx)
|
|
||||||
{
|
|
||||||
formatter<mp_units::quantity<mp_units::isq::altitude[mp_units::si::metre]>>::format(a.absolute(), ctx);
|
|
||||||
return STD_FMT::format_to(ctx.out(), " AMSL");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// definition of glide computer databases and utilities
|
// definition of glide computer databases and utilities
|
||||||
namespace glide_computer {
|
|
||||||
|
|
||||||
struct glider {
|
struct glider {
|
||||||
struct polar_point {
|
struct polar_point {
|
||||||
velocity v;
|
velocity v;
|
||||||
@@ -118,7 +92,7 @@ struct weather {
|
|||||||
struct waypoint {
|
struct waypoint {
|
||||||
std::string name;
|
std::string name;
|
||||||
geographic::position<long double> pos;
|
geographic::position<long double> pos;
|
||||||
altitude alt;
|
geographic::msl_altitude alt;
|
||||||
};
|
};
|
||||||
|
|
||||||
class task {
|
class task {
|
||||||
@@ -184,14 +158,17 @@ struct aircraft_tow {
|
|||||||
|
|
||||||
struct flight_point {
|
struct flight_point {
|
||||||
timestamp ts;
|
timestamp ts;
|
||||||
altitude alt;
|
geographic::msl_altitude alt;
|
||||||
std::size_t leg_idx = 0;
|
std::size_t leg_idx = 0;
|
||||||
distance dist{};
|
distance dist{};
|
||||||
};
|
};
|
||||||
|
|
||||||
altitude terrain_level_alt(const task& t, const flight_point& pos);
|
geographic::msl_altitude terrain_level_alt(const task& t, const flight_point& pos);
|
||||||
|
|
||||||
constexpr height agl(altitude glider_alt, altitude terrain_level) { return glider_alt - terrain_level; }
|
constexpr height agl(geographic::msl_altitude glider_alt, geographic::msl_altitude terrain_level)
|
||||||
|
{
|
||||||
|
return glider_alt - terrain_level;
|
||||||
|
}
|
||||||
|
|
||||||
inline mp_units::quantity<mp_units::isq::length[mp_units::si::kilo<mp_units::si::metre>]> length_3d(distance dist,
|
inline mp_units::quantity<mp_units::isq::length[mp_units::si::kilo<mp_units::si::metre>]> length_3d(distance dist,
|
||||||
height h)
|
height h)
|
||||||
@@ -199,7 +176,8 @@ inline mp_units::quantity<mp_units::isq::length[mp_units::si::kilo<mp_units::si:
|
|||||||
return hypot(dist, h);
|
return hypot(dist, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt);
|
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s,
|
||||||
|
geographic::msl_altitude ground_alt);
|
||||||
|
|
||||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s,
|
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s,
|
||||||
const aircraft_tow& at);
|
const aircraft_tow& at);
|
||||||
|
@@ -36,8 +36,8 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using namespace geographic;
|
||||||
using namespace glide_computer;
|
using namespace glide_computer;
|
||||||
|
|
||||||
using namespace mp_units;
|
using namespace mp_units;
|
||||||
|
|
||||||
auto get_gliders()
|
auto get_gliders()
|
||||||
@@ -67,8 +67,8 @@ auto get_waypoints()
|
|||||||
using namespace geographic::literals;
|
using namespace geographic::literals;
|
||||||
using namespace mp_units::international::unit_symbols;
|
using namespace mp_units::international::unit_symbols;
|
||||||
static const std::array waypoints = {
|
static const std::array waypoints = {
|
||||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude{16. * ft}}, // N54°14'51.8" E18°40'28.2"
|
waypoint{"EPPR", {54.24772_N, 18.6745_E}, msl_altitude{16. * ft}}, // N54°14'51.8" E18°40'28.2"
|
||||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude{115. * ft}} // N53°31'27.9" E18°50'58.1"
|
waypoint{"EPGI", {53.52442_N, 18.84947_E}, msl_altitude{115. * ft}} // N53°31'27.9" E18°50'58.1"
|
||||||
};
|
};
|
||||||
return waypoints;
|
return waypoints;
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +24,10 @@
|
|||||||
|
|
||||||
#include "ranged_representation.h"
|
#include "ranged_representation.h"
|
||||||
#include <mp_units/bits/fmt_hacks.h>
|
#include <mp_units/bits/fmt_hacks.h>
|
||||||
|
#include <mp_units/format.h>
|
||||||
#include <mp_units/math.h>
|
#include <mp_units/math.h>
|
||||||
#include <mp_units/quantity.h>
|
#include <mp_units/quantity.h>
|
||||||
|
#include <mp_units/quantity_point.h>
|
||||||
#include <mp_units/systems/isq/space_and_time.h>
|
#include <mp_units/systems/isq/space_and_time.h>
|
||||||
#include <mp_units/systems/si/units.h>
|
#include <mp_units/systems/si/units.h>
|
||||||
#include <compare>
|
#include <compare>
|
||||||
@@ -35,6 +37,33 @@
|
|||||||
|
|
||||||
namespace geographic {
|
namespace geographic {
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
inline constexpr struct mean_sea_level : mp_units::absolute_point_origin<mp_units::isq::altitude> {} mean_sea_level;
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
using msl_altitude = mp_units::quantity_point<mp_units::isq::altitude[mp_units::si::metre], mean_sea_level>;
|
||||||
|
|
||||||
|
// text output
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const msl_altitude& a)
|
||||||
|
{
|
||||||
|
return os << a.absolute() << " AMSL";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace geographic
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct STD_FMT::formatter<geographic::msl_altitude> : formatter<geographic::msl_altitude::quantity_type> {
|
||||||
|
template<typename FormatContext>
|
||||||
|
auto format(const geographic::msl_altitude& a, FormatContext& ctx)
|
||||||
|
{
|
||||||
|
formatter<geographic::msl_altitude::quantity_type>::format(a.absolute(), ctx);
|
||||||
|
return STD_FMT::format_to(ctx.out(), " AMSL");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace geographic {
|
||||||
|
|
||||||
template<typename T = double>
|
template<typename T = double>
|
||||||
using latitude =
|
using latitude =
|
||||||
mp_units::quantity<mp_units::isq::angular_measure[mp_units::si::degree], ranged_representation<T, -90, 90>>;
|
mp_units::quantity<mp_units::isq::angular_measure[mp_units::si::degree], ranged_representation<T, -90, 90>>;
|
Reference in New Issue
Block a user