From 1e5e2eb36e61ad81b4a7394a972fd8777d4a35cb Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 11 Oct 2000 00:18:26 +0000 Subject: [PATCH] Changes to support new simgear waypoint module. --- src/Autopilot/auto_gui.cxx | 6 ++- src/Autopilot/newauto.cxx | 95 ++++++++++++++++---------------------- src/Autopilot/newauto.hxx | 25 +++++++--- src/Main/Makefile.am | 4 +- src/Main/bfi.cxx | 20 ++++++-- src/Main/bfi.hxx | 5 +- 6 files changed, 86 insertions(+), 69 deletions(-) diff --git a/src/Autopilot/auto_gui.cxx b/src/Autopilot/auto_gui.cxx index 56943208a..862167b88 100644 --- a/src/Autopilot/auto_gui.cxx +++ b/src/Autopilot/auto_gui.cxx @@ -609,8 +609,10 @@ void TgtAptDialog_OK (puObject *) current_options.set_airport_id( TgtAptId.c_str() ); sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() ); - current_autopilot->set_TargetLatitude( a.latitude ); - current_autopilot->set_TargetLongitude( a.longitude ); + current_autopilot->set_WayPoint( a.longitude, a.latitude, + TgtAptId ); + // current_autopilot->set_TargetLatitude( a.latitude ); + // current_autopilot->set_TargetLongitude( a.longitude ); current_autopilot->MakeTargetLatLonStr( current_autopilot->get_TargetLatitude(), current_autopilot->get_TargetLongitude() ); diff --git a/src/Autopilot/newauto.cxx b/src/Autopilot/newauto.cxx index 6a99e0570..9955b6b21 100644 --- a/src/Autopilot/newauto.cxx +++ b/src/Autopilot/newauto.cxx @@ -67,8 +67,8 @@ extern char *coord_format_lon(float); void FGAutopilot::MakeTargetLatLonStr( double lat, double lon ) { - sprintf( TargetLatitudeStr , "%s", coord_format_lat(TargetLatitude) ); - sprintf( TargetLongitudeStr, "%s", coord_format_lon(TargetLongitude) ); + sprintf( TargetLatitudeStr , "%s", coord_format_lat(get_TargetLatitude())); + sprintf( TargetLongitudeStr, "%s", coord_format_lon(get_TargetLongitude())); sprintf( TargetLatLonStr, "%s %s", TargetLatitudeStr, TargetLongitudeStr ); } @@ -144,10 +144,11 @@ void FGAutopilot::init() { auto_throttle = false ; // turn the auto throttle off // Initialize target location to startup location - old_lat = TargetLatitude = FGBFI::getLatitude(); - old_lon = TargetLongitude = FGBFI::getLongitude(); + old_lat = FGBFI::getLatitude(); + old_lon = FGBFI::getLongitude(); + set_WayPoint( old_lon, old_lat, "default" ); - MakeTargetLatLonStr( TargetLatitude, TargetLongitude); + MakeTargetLatLonStr( get_TargetLatitude(), get_TargetLongitude() ); TargetHeading = 0.0; // default direction, due north TargetAltitude = 3000; // default altitude in meters @@ -212,9 +213,11 @@ void FGAutopilot::reset() { sprintf( NewTgtAirportId, "%s", current_options.get_airport_id().c_str() ); - TargetLatitude = FGBFI::getLatitude(); - TargetLongitude = FGBFI::getLongitude(); - MakeTargetLatLonStr( TargetLatitude, TargetLongitude ); + // TargetLatitude = FGBFI::getLatitude(); + // TargetLongitude = FGBFI::getLongitude(); + set_WayPoint( FGBFI::getLongitude(), FGBFI::getLatitude(), "reset" ); + + MakeTargetLatLonStr( get_TargetLatitude(), get_TargetLongitude() ); } @@ -330,7 +333,7 @@ int FGAutopilot::run() { } else if ( heading_mode == FG_HEADING_WAYPOINT ) { // update target heading to waypoint - double wp_course, wp_reverse, wp_distance; + double wp_course, /*wp_reverse,*/ wp_distance; #ifdef DO_fgAP_CORRECTED_COURSE // compute course made good @@ -349,39 +352,31 @@ int FGAutopilot::run() { // compute course to way_point // need to test for iter - if( ! geo_inverse_wgs_84( 0, //fgAPget_altitude(), - lat, - lon, - TargetLatitude, - TargetLongitude, - &wp_course, - &wp_reverse, - &wp_distance ) ) { - + waypoint.CourseAndDistance( lon, lat, &wp_course, &wp_distance ); + #ifdef DO_fgAP_CORRECTED_COURSE - corrected_course = course - wp_course; - if( fabs(corrected_course) > 0.1 ) - printf("fgAP: course %f wp_course %f %f %f\n", - course, wp_course, fabs(corrected_course), - distance ); + corrected_course = course - wp_course; + if( fabs(corrected_course) > 0.1 ) + printf("fgAP: course %f wp_course %f %f %f\n", + course, wp_course, fabs(corrected_course), + distance ); #endif // DO_fgAP_CORRECTED_COURSE - if ( wp_distance > 100 ) { - // corrected_course = course - wp_course; - TargetHeading = NormalizeDegrees(wp_course); - } else { - printf("distance(%f) to close\n", wp_distance); - // Real Close -- set heading hold to current heading - // and Ring the arival bell !! - heading_mode = FG_HEADING_LOCK; - // use current heading - TargetHeading = FGBFI::getHeading(); - } - MakeTargetHeadingStr( TargetHeading ); - // Force this just in case - TargetDistance = wp_distance; - MakeTargetDistanceStr( wp_distance ); + if ( wp_distance > 100 ) { + // corrected_course = course - wp_course; + TargetHeading = NormalizeDegrees(wp_course); + } else { + printf("distance(%f) to close\n", wp_distance); + // Real Close -- set heading hold to current heading + // and Ring the arival bell !! + heading_mode = FG_HEADING_LOCK; + // use current heading + TargetHeading = FGBFI::getHeading(); } + MakeTargetHeadingStr( TargetHeading ); + // Force this just in case + TargetDistance = wp_distance; + MakeTargetDistanceStr( wp_distance ); } double RelHeading; @@ -628,29 +623,21 @@ void FGAutopilot::set_HeadingMode( fgAutoHeadingMode mode ) { // set heading hold to current heading TargetHeading = FGBFI::getHeading(); } else if ( heading_mode == FG_HEADING_WAYPOINT ) { - double course, reverse, distance; + double course, /*reverse,*/ distance; // turn on location hold // turn on heading hold old_lat = FGBFI::getLatitude(); old_lon = FGBFI::getLongitude(); - // need to test for iter - if( !geo_inverse_wgs_84( FGBFI::getAltitude() * FEET_TO_METER, - FGBFI::getLatitude(), - FGBFI::getLongitude(), - TargetLatitude, - TargetLongitude, - &course, - &reverse, - &distance ) ) { - TargetHeading = course; - TargetDistance = distance; - MakeTargetDistanceStr( distance ); - } + waypoint.CourseAndDistance( FGBFI::getLongitude(), FGBFI::getLatitude(), + &course, &distance ); + TargetHeading = course; + TargetDistance = distance; + MakeTargetDistanceStr( distance ); FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetLocation: ( " - << TargetLatitude << " " - << TargetLongitude << " ) " + << get_TargetLatitude() << " " + << get_TargetLongitude() << " ) " ); } diff --git a/src/Autopilot/newauto.hxx b/src/Autopilot/newauto.hxx index 334e2b26c..5ec7c924a 100644 --- a/src/Autopilot/newauto.hxx +++ b/src/Autopilot/newauto.hxx @@ -27,6 +27,9 @@ #define _NEWAUTO_HXX +#include + + // Structures class FGAutopilot { @@ -55,8 +58,10 @@ private: fgAutoHeadingMode heading_mode; fgAutoAltitudeMode altitude_mode; - double TargetLatitude; // the latitude the AP should steer to. - double TargetLongitude; // the longitude the AP should steer to. + SGWayPoint waypoint; // the waypoint the AP should steer to. + + // double TargetLatitude; // the latitude the AP should steer to. + // double TargetLongitude; // the longitude the AP should steer to. double TargetDistance; // the distance to Target. double TargetHeading; // the heading the AP should steer to. double TargetAltitude; // altitude to hold @@ -130,11 +135,19 @@ public: inline bool get_AutoThrottleEnabled() const { return auto_throttle; } void set_AutoThrottleEnabled( bool value ); - inline double get_TargetLatitude() const { return TargetLatitude; } - inline void set_TargetLatitude( double val ) { TargetLatitude = val; } + inline void set_WayPoint( const double lon, const double lat, + const string s ) { + waypoint = SGWayPoint( lon, lat, SGWayPoint::WGS84, "Current WP" ); + } + inline double get_TargetLatitude() const { + return waypoint.get_target_lat(); + } + inline double get_TargetLongitude() const { + return waypoint.get_target_lon(); + } + // inline void set_TargetLatitude( double val ) { TargetLatitude = val; } + // inline void set_TargetLongitude( double val ) { TargetLongitude = val; } inline void set_old_lat( double val ) { old_lat = val; } - inline double get_TargetLongitude() const { return TargetLongitude; } - inline void set_TargetLongitude( double val ) { TargetLongitude = val; } inline void set_old_lon( double val ) { old_lon = val; } inline double get_TargetHeading() const { return TargetHeading; } inline void set_TargetHeading( double val ) { TargetHeading = val; } diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 37bce676a..61525a3f4 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -65,8 +65,8 @@ fgfs_LDADD = \ $(top_builddir)/src/Time/libTime.a \ $(WEATHER_LIBS) \ $(top_builddir)/src/Joystick/libJoystick.a \ - -lsgsky -lsgephem -lsgtiming -lsgio -lsgscreen -lsgmath -lsgbucket \ - -lsgdebug -lsgmagvar -lsgmisc -lsgxml \ + -lsgroute -lsgsky -lsgephem -lsgtiming -lsgio -lsgscreen -lsgmath \ + -lsgbucket -lsgdebug -lsgmagvar -lsgmisc -lsgxml \ $(SERIAL_LIBS) \ -lplibpu -lplibfnt -lplibssg -lplibsg \ -lmk4 -lz \ diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index ac50f56e3..351792f90 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -314,8 +314,9 @@ FGBFI::reinit () setAPAltitude(apAltitude); setTargetAirport(targetAirport); setGPSLock(gpsLock); - setGPSTargetLatitude(gpsLatitude); - setGPSTargetLongitude(gpsLongitude); + // setGPSTargetLatitude(gpsLatitude); + // setGPSTargetLongitude(gpsLongitude); + setGPSTargetWayPoint(gpsLatitude, gpsLongitude); _needReinit = false; @@ -1556,6 +1557,17 @@ FGBFI::getGPSTargetLatitude () } +/** + * Set the GPS target waypoint + */ +void +FGBFI::setGPSTargetWayPoint (double latitude, double longitude) +{ + current_autopilot->set_WayPoint( longitude, latitude, "reload" ); +} + + +#if 0 /** * Set the GPS target latitude in degrees (negative for south). */ @@ -1564,6 +1576,7 @@ FGBFI::setGPSTargetLatitude (double latitude) { current_autopilot->set_TargetLatitude( latitude ); } +#endif /** @@ -1575,7 +1588,7 @@ FGBFI::getGPSTargetLongitude () return current_autopilot->get_TargetLongitude(); } - +#if 0 /** * Set the GPS target longitude in degrees (negative for west). */ @@ -1584,6 +1597,7 @@ FGBFI::setGPSTargetLongitude (double longitude) { current_autopilot->set_TargetLongitude( longitude ); } +#endif diff --git a/src/Main/bfi.hxx b/src/Main/bfi.hxx index 851dd0d4f..8f26d8855 100644 --- a/src/Main/bfi.hxx +++ b/src/Main/bfi.hxx @@ -197,8 +197,9 @@ public: static void setTargetAirport (const string &targetAirport); static void setGPSLock (bool lock); - static void setGPSTargetLatitude (double latitude); - static void setGPSTargetLongitude (double longitude); + // static void setGPSTargetLatitude (double latitude); + // static void setGPSTargetLongitude (double longitude); + static void setGPSTargetWayPoint (double latitude, double longitude); // Weather -- 2.39.5