forked from mpusz/mp-units
refactor(example): glide computer refactored for V2
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
namespace glide_computer {
|
||||
|
||||
using namespace units::isq;
|
||||
using namespace units;
|
||||
|
||||
task::legs task::make_legs(const waypoints& wpts)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ altitude terrain_level_alt(const task& t, const flight_point& pos)
|
||||
{
|
||||
const task::leg& l = t.get_legs()[pos.leg_idx];
|
||||
const height alt_diff = l.end().alt - l.begin().alt;
|
||||
return l.begin().alt + alt_diff * ((pos.dist - t.get_leg_dist_offset(pos.leg_idx)) / l.get_length()).common();
|
||||
return l.begin().alt + alt_diff * ((pos.dist - t.get_leg_dist_offset(pos.leg_idx)) / l.get_length());
|
||||
}
|
||||
|
||||
// Returns `x` of the intersection of a glide line and a terrain line.
|
||||
@@ -61,7 +61,7 @@ altitude terrain_level_alt(const task& t, const flight_point& pos)
|
||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt)
|
||||
{
|
||||
const auto dist_to_finish = t.get_length() - pos.dist;
|
||||
return distance((ground_alt + s.min_agl_height - pos.alt).common() /
|
||||
return distance((ground_alt + s.min_agl_height - pos.alt) /
|
||||
((ground_alt - t.get_finish().alt) / dist_to_finish - 1 / glide_ratio(g.polar[0])));
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ flight_point takeoff(timestamp start_ts, const task& t) { return {start_ts, t.ge
|
||||
|
||||
flight_point tow(timestamp start_ts, const flight_point& pos, const aircraft_tow& at)
|
||||
{
|
||||
const duration d = (at.height_agl / at.performance).common();
|
||||
const duration d = (at.height_agl / at.performance);
|
||||
const flight_point new_pos{pos.ts + d, pos.alt + at.height_agl, pos.leg_idx, pos.dist};
|
||||
|
||||
print("Tow", start_ts, pos, new_pos);
|
||||
@@ -98,7 +98,7 @@ flight_point circle(timestamp start_ts, const flight_point& pos, const glider& g
|
||||
const height h_agl = agl(pos.alt, terrain_level_alt(t, pos));
|
||||
const height circling_height = std::min(w.cloud_base - h_agl, height_to_gain);
|
||||
const rate_of_climb circling_rate = w.thermal_strength + g.polar[0].climb;
|
||||
const duration d = (circling_height / circling_rate).common();
|
||||
const duration d = (circling_height / circling_rate);
|
||||
const flight_point new_pos{pos.ts + d, pos.alt + circling_height, pos.leg_idx, pos.dist};
|
||||
|
||||
height_to_gain -= circling_height;
|
||||
@@ -114,7 +114,7 @@ flight_point glide(timestamp start_ts, const flight_point& pos, const glider& g,
|
||||
const auto new_distance = pos.dist + dist;
|
||||
const auto alt = ground_alt + s.min_agl_height;
|
||||
const auto l3d = length_3d(dist, pos.alt - alt);
|
||||
const duration d = l3d / g.polar[0].v.common();
|
||||
const duration d = l3d / g.polar[0].v;
|
||||
const flight_point new_pos{pos.ts + d, terrain_level_alt(t, pos) + s.min_agl_height, t.get_leg_index(new_distance),
|
||||
new_distance};
|
||||
|
||||
@@ -126,7 +126,7 @@ flight_point final_glide(timestamp start_ts, const flight_point& pos, const glid
|
||||
{
|
||||
const auto dist = t.get_length() - pos.dist;
|
||||
const auto l3d = length_3d(dist, pos.alt - t.get_finish().alt);
|
||||
const duration d = l3d / g.polar[0].v.common();
|
||||
const duration d = l3d / g.polar[0].v;
|
||||
const flight_point new_pos{pos.ts + d, t.get_finish().alt, t.get_legs().size() - 1, pos.dist + dist};
|
||||
|
||||
print("Final Glide", start_ts, pos, new_pos);
|
||||
@@ -151,7 +151,7 @@ void estimate(timestamp start_ts, const glider& g, const weather& w, const task&
|
||||
pos = tow(start_ts, pos, at);
|
||||
|
||||
// estimate the altitude needed to reach the finish line from this place
|
||||
const altitude final_glide_alt = t.get_finish().alt + height(t.get_length().common() / glide_ratio(g.polar[0]));
|
||||
const altitude final_glide_alt = t.get_finish().alt + height(t.get_length() / glide_ratio(g.polar[0]));
|
||||
|
||||
// how much height we still need to gain in the thermalls to reach the destination?
|
||||
height height_to_gain = final_glide_alt - pos.alt;
|
||||
|
||||
Reference in New Issue
Block a user