From 4e043de1f14a82a0603467ca31ac9601c57e6742 Mon Sep 17 00:00:00 2001 From: curt Date: Sun, 10 Oct 1999 16:47:21 +0000 Subject: [PATCH] Added "ETA" to display. --- src/Autopilot/autopilot.cxx | 26 +++++++++++++++++++++++++- src/Autopilot/autopilot.hxx | 34 +++++++++++++++++----------------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Autopilot/autopilot.cxx b/src/Autopilot/autopilot.cxx index 90d7397e1..2226f5e19 100644 --- a/src/Autopilot/autopilot.cxx +++ b/src/Autopilot/autopilot.cxx @@ -140,6 +140,14 @@ extern char *coord_format_lat(float); extern char *coord_format_lon(float); +static inline double get_ground_speed( void ) { + // starts in ft/s so we convert to kts + double ft_s = current_aircraft.fdm_state->get_V_ground_speed() + * current_options.get_speed_up();; + double kts = ft_s * FEET_TO_METER * 3600 * METER_TO_NM; + return kts; +} + // The below routines were copied right from hud.c ( I hate reinventing // the wheel more than necessary) @@ -165,7 +173,23 @@ static void MakeTargetHeadingStr( fgAPDataPtr APData, double bearing ) { } static inline void MakeTargetDistanceStr( fgAPDataPtr APData, double distance ) { - sprintf(APData->TargetDistanceStr, "APDistance %.2f NM", distance*METER_TO_NM); + double eta = distance*METER_TO_NM / get_ground_speed(); + if ( eta >= 100.0 ) { eta = 99.999; } + int major, minor; + if ( eta < (1.0/6.0) ) { + // within 10 minutes, bump up to min/secs + eta *= 60.0; + } + major = (int)eta; + minor = (int)((eta - (int)eta) * 60.0); + sprintf(APData->TargetDistanceStr, "APDistance %.2f NM ETA %d:%02d", + distance*METER_TO_NM, major, minor); + // cout << "distance = " << distance*METER_TO_NM + // << " gndsp = " << get_ground_speed() + // << " time = " << eta + // << " major = " << major + // << " minor = " << minor + // << endl; } static inline void MakeTargetAltitudeStr( fgAPDataPtr APData, double altitude ) { diff --git a/src/Autopilot/autopilot.hxx b/src/Autopilot/autopilot.hxx index 0dd777c8b..bae1b9c1c 100644 --- a/src/Autopilot/autopilot.hxx +++ b/src/Autopilot/autopilot.hxx @@ -73,23 +73,23 @@ typedef struct { double old_elevator_trim; double old_rudder; - // manual controls override beyond this value - double disengage_threshold; - - // For future cross track error adjust - double old_lat; - double old_lon; - - // keeping these locally to save work inside main loop - char TargetLatitudeStr[32]; - char TargetLongitudeStr[32]; - char TargetLatLonStr[32]; - char TargetDistanceStr[32]; - char TargetHeadingStr[32]; - char TargetAltitudeStr[32]; -// char jnk[32]; - // using current_options.airport_id for now -// string tgt_airport_id; // ID of initial starting airport + // manual controls override beyond this value + double disengage_threshold; + + // For future cross track error adjust + double old_lat; + double old_lon; + + // keeping these locally to save work inside main loop + char TargetLatitudeStr[64]; + char TargetLongitudeStr[64]; + char TargetLatLonStr[64]; + char TargetDistanceStr[64]; + char TargetHeadingStr[64]; + char TargetAltitudeStr[64]; + // char jnk[32]; + // using current_options.airport_id for now + // string tgt_airport_id; // ID of initial starting airport } fgAPData, *fgAPDataPtr ; -- 2.39.5