Changes to support new simgear waypoint module.
This commit is contained in:
parent
7c38f172d9
commit
1e5e2eb36e
6 changed files with 86 additions and 69 deletions
|
@ -609,8 +609,10 @@ void TgtAptDialog_OK (puObject *)
|
||||||
current_options.set_airport_id( TgtAptId.c_str() );
|
current_options.set_airport_id( TgtAptId.c_str() );
|
||||||
sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
|
sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
|
||||||
|
|
||||||
current_autopilot->set_TargetLatitude( a.latitude );
|
current_autopilot->set_WayPoint( a.longitude, a.latitude,
|
||||||
current_autopilot->set_TargetLongitude( a.longitude );
|
TgtAptId );
|
||||||
|
// current_autopilot->set_TargetLatitude( a.latitude );
|
||||||
|
// current_autopilot->set_TargetLongitude( a.longitude );
|
||||||
current_autopilot->MakeTargetLatLonStr(
|
current_autopilot->MakeTargetLatLonStr(
|
||||||
current_autopilot->get_TargetLatitude(),
|
current_autopilot->get_TargetLatitude(),
|
||||||
current_autopilot->get_TargetLongitude() );
|
current_autopilot->get_TargetLongitude() );
|
||||||
|
|
|
@ -67,8 +67,8 @@ extern char *coord_format_lon(float);
|
||||||
|
|
||||||
|
|
||||||
void FGAutopilot::MakeTargetLatLonStr( double lat, double lon ) {
|
void FGAutopilot::MakeTargetLatLonStr( double lat, double lon ) {
|
||||||
sprintf( TargetLatitudeStr , "%s", coord_format_lat(TargetLatitude) );
|
sprintf( TargetLatitudeStr , "%s", coord_format_lat(get_TargetLatitude()));
|
||||||
sprintf( TargetLongitudeStr, "%s", coord_format_lon(TargetLongitude) );
|
sprintf( TargetLongitudeStr, "%s", coord_format_lon(get_TargetLongitude()));
|
||||||
sprintf( TargetLatLonStr, "%s %s", TargetLatitudeStr, TargetLongitudeStr );
|
sprintf( TargetLatLonStr, "%s %s", TargetLatitudeStr, TargetLongitudeStr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,10 +144,11 @@ void FGAutopilot::init() {
|
||||||
auto_throttle = false ; // turn the auto throttle off
|
auto_throttle = false ; // turn the auto throttle off
|
||||||
|
|
||||||
// Initialize target location to startup location
|
// Initialize target location to startup location
|
||||||
old_lat = TargetLatitude = FGBFI::getLatitude();
|
old_lat = FGBFI::getLatitude();
|
||||||
old_lon = TargetLongitude = FGBFI::getLongitude();
|
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
|
TargetHeading = 0.0; // default direction, due north
|
||||||
TargetAltitude = 3000; // default altitude in meters
|
TargetAltitude = 3000; // default altitude in meters
|
||||||
|
@ -212,9 +213,11 @@ void FGAutopilot::reset() {
|
||||||
|
|
||||||
sprintf( NewTgtAirportId, "%s", current_options.get_airport_id().c_str() );
|
sprintf( NewTgtAirportId, "%s", current_options.get_airport_id().c_str() );
|
||||||
|
|
||||||
TargetLatitude = FGBFI::getLatitude();
|
// TargetLatitude = FGBFI::getLatitude();
|
||||||
TargetLongitude = FGBFI::getLongitude();
|
// TargetLongitude = FGBFI::getLongitude();
|
||||||
MakeTargetLatLonStr( TargetLatitude, TargetLongitude );
|
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 ) {
|
} else if ( heading_mode == FG_HEADING_WAYPOINT ) {
|
||||||
// update target heading to 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
|
#ifdef DO_fgAP_CORRECTED_COURSE
|
||||||
// compute course made good
|
// compute course made good
|
||||||
|
@ -349,39 +352,31 @@ int FGAutopilot::run() {
|
||||||
|
|
||||||
// compute course to way_point
|
// compute course to way_point
|
||||||
// need to test for iter
|
// need to test for iter
|
||||||
if( ! geo_inverse_wgs_84( 0, //fgAPget_altitude(),
|
waypoint.CourseAndDistance( lon, lat, &wp_course, &wp_distance );
|
||||||
lat,
|
|
||||||
lon,
|
|
||||||
TargetLatitude,
|
|
||||||
TargetLongitude,
|
|
||||||
&wp_course,
|
|
||||||
&wp_reverse,
|
|
||||||
&wp_distance ) ) {
|
|
||||||
|
|
||||||
#ifdef DO_fgAP_CORRECTED_COURSE
|
#ifdef DO_fgAP_CORRECTED_COURSE
|
||||||
corrected_course = course - wp_course;
|
corrected_course = course - wp_course;
|
||||||
if( fabs(corrected_course) > 0.1 )
|
if( fabs(corrected_course) > 0.1 )
|
||||||
printf("fgAP: course %f wp_course %f %f %f\n",
|
printf("fgAP: course %f wp_course %f %f %f\n",
|
||||||
course, wp_course, fabs(corrected_course),
|
course, wp_course, fabs(corrected_course),
|
||||||
distance );
|
distance );
|
||||||
#endif // DO_fgAP_CORRECTED_COURSE
|
#endif // DO_fgAP_CORRECTED_COURSE
|
||||||
|
|
||||||
if ( wp_distance > 100 ) {
|
if ( wp_distance > 100 ) {
|
||||||
// corrected_course = course - wp_course;
|
// corrected_course = course - wp_course;
|
||||||
TargetHeading = NormalizeDegrees(wp_course);
|
TargetHeading = NormalizeDegrees(wp_course);
|
||||||
} else {
|
} else {
|
||||||
printf("distance(%f) to close\n", wp_distance);
|
printf("distance(%f) to close\n", wp_distance);
|
||||||
// Real Close -- set heading hold to current heading
|
// Real Close -- set heading hold to current heading
|
||||||
// and Ring the arival bell !!
|
// and Ring the arival bell !!
|
||||||
heading_mode = FG_HEADING_LOCK;
|
heading_mode = FG_HEADING_LOCK;
|
||||||
// use current heading
|
// use current heading
|
||||||
TargetHeading = FGBFI::getHeading();
|
TargetHeading = FGBFI::getHeading();
|
||||||
}
|
|
||||||
MakeTargetHeadingStr( TargetHeading );
|
|
||||||
// Force this just in case
|
|
||||||
TargetDistance = wp_distance;
|
|
||||||
MakeTargetDistanceStr( wp_distance );
|
|
||||||
}
|
}
|
||||||
|
MakeTargetHeadingStr( TargetHeading );
|
||||||
|
// Force this just in case
|
||||||
|
TargetDistance = wp_distance;
|
||||||
|
MakeTargetDistanceStr( wp_distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
double RelHeading;
|
double RelHeading;
|
||||||
|
@ -628,29 +623,21 @@ void FGAutopilot::set_HeadingMode( fgAutoHeadingMode mode ) {
|
||||||
// set heading hold to current heading
|
// set heading hold to current heading
|
||||||
TargetHeading = FGBFI::getHeading();
|
TargetHeading = FGBFI::getHeading();
|
||||||
} else if ( heading_mode == FG_HEADING_WAYPOINT ) {
|
} else if ( heading_mode == FG_HEADING_WAYPOINT ) {
|
||||||
double course, reverse, distance;
|
double course, /*reverse,*/ distance;
|
||||||
// turn on location hold
|
// turn on location hold
|
||||||
// turn on heading hold
|
// turn on heading hold
|
||||||
old_lat = FGBFI::getLatitude();
|
old_lat = FGBFI::getLatitude();
|
||||||
old_lon = FGBFI::getLongitude();
|
old_lon = FGBFI::getLongitude();
|
||||||
|
|
||||||
// need to test for iter
|
waypoint.CourseAndDistance( FGBFI::getLongitude(), FGBFI::getLatitude(),
|
||||||
if( !geo_inverse_wgs_84( FGBFI::getAltitude() * FEET_TO_METER,
|
&course, &distance );
|
||||||
FGBFI::getLatitude(),
|
TargetHeading = course;
|
||||||
FGBFI::getLongitude(),
|
TargetDistance = distance;
|
||||||
TargetLatitude,
|
MakeTargetDistanceStr( distance );
|
||||||
TargetLongitude,
|
|
||||||
&course,
|
|
||||||
&reverse,
|
|
||||||
&distance ) ) {
|
|
||||||
TargetHeading = course;
|
|
||||||
TargetDistance = distance;
|
|
||||||
MakeTargetDistanceStr( distance );
|
|
||||||
}
|
|
||||||
|
|
||||||
FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetLocation: ( "
|
FG_LOG( FG_COCKPIT, FG_INFO, " fgAPSetLocation: ( "
|
||||||
<< TargetLatitude << " "
|
<< get_TargetLatitude() << " "
|
||||||
<< TargetLongitude << " ) "
|
<< get_TargetLongitude() << " ) "
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
#define _NEWAUTO_HXX
|
#define _NEWAUTO_HXX
|
||||||
|
|
||||||
|
|
||||||
|
#include <simgear/route/waypoint.hxx>
|
||||||
|
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
class FGAutopilot {
|
class FGAutopilot {
|
||||||
|
|
||||||
|
@ -55,8 +58,10 @@ private:
|
||||||
fgAutoHeadingMode heading_mode;
|
fgAutoHeadingMode heading_mode;
|
||||||
fgAutoAltitudeMode altitude_mode;
|
fgAutoAltitudeMode altitude_mode;
|
||||||
|
|
||||||
double TargetLatitude; // the latitude the AP should steer to.
|
SGWayPoint waypoint; // the waypoint the AP should steer to.
|
||||||
double TargetLongitude; // the longitude 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 TargetDistance; // the distance to Target.
|
||||||
double TargetHeading; // the heading the AP should steer to.
|
double TargetHeading; // the heading the AP should steer to.
|
||||||
double TargetAltitude; // altitude to hold
|
double TargetAltitude; // altitude to hold
|
||||||
|
@ -130,11 +135,19 @@ public:
|
||||||
inline bool get_AutoThrottleEnabled() const { return auto_throttle; }
|
inline bool get_AutoThrottleEnabled() const { return auto_throttle; }
|
||||||
void set_AutoThrottleEnabled( bool value );
|
void set_AutoThrottleEnabled( bool value );
|
||||||
|
|
||||||
inline double get_TargetLatitude() const { return TargetLatitude; }
|
inline void set_WayPoint( const double lon, const double lat,
|
||||||
inline void set_TargetLatitude( double val ) { TargetLatitude = val; }
|
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 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 void set_old_lon( double val ) { old_lon = val; }
|
||||||
inline double get_TargetHeading() const { return TargetHeading; }
|
inline double get_TargetHeading() const { return TargetHeading; }
|
||||||
inline void set_TargetHeading( double val ) { TargetHeading = val; }
|
inline void set_TargetHeading( double val ) { TargetHeading = val; }
|
||||||
|
|
|
@ -65,8 +65,8 @@ fgfs_LDADD = \
|
||||||
$(top_builddir)/src/Time/libTime.a \
|
$(top_builddir)/src/Time/libTime.a \
|
||||||
$(WEATHER_LIBS) \
|
$(WEATHER_LIBS) \
|
||||||
$(top_builddir)/src/Joystick/libJoystick.a \
|
$(top_builddir)/src/Joystick/libJoystick.a \
|
||||||
-lsgsky -lsgephem -lsgtiming -lsgio -lsgscreen -lsgmath -lsgbucket \
|
-lsgroute -lsgsky -lsgephem -lsgtiming -lsgio -lsgscreen -lsgmath \
|
||||||
-lsgdebug -lsgmagvar -lsgmisc -lsgxml \
|
-lsgbucket -lsgdebug -lsgmagvar -lsgmisc -lsgxml \
|
||||||
$(SERIAL_LIBS) \
|
$(SERIAL_LIBS) \
|
||||||
-lplibpu -lplibfnt -lplibssg -lplibsg \
|
-lplibpu -lplibfnt -lplibssg -lplibsg \
|
||||||
-lmk4 -lz \
|
-lmk4 -lz \
|
||||||
|
|
|
@ -314,8 +314,9 @@ FGBFI::reinit ()
|
||||||
setAPAltitude(apAltitude);
|
setAPAltitude(apAltitude);
|
||||||
setTargetAirport(targetAirport);
|
setTargetAirport(targetAirport);
|
||||||
setGPSLock(gpsLock);
|
setGPSLock(gpsLock);
|
||||||
setGPSTargetLatitude(gpsLatitude);
|
// setGPSTargetLatitude(gpsLatitude);
|
||||||
setGPSTargetLongitude(gpsLongitude);
|
// setGPSTargetLongitude(gpsLongitude);
|
||||||
|
setGPSTargetWayPoint(gpsLatitude, gpsLongitude);
|
||||||
|
|
||||||
_needReinit = false;
|
_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).
|
* Set the GPS target latitude in degrees (negative for south).
|
||||||
*/
|
*/
|
||||||
|
@ -1564,6 +1576,7 @@ FGBFI::setGPSTargetLatitude (double latitude)
|
||||||
{
|
{
|
||||||
current_autopilot->set_TargetLatitude( latitude );
|
current_autopilot->set_TargetLatitude( latitude );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1575,7 +1588,7 @@ FGBFI::getGPSTargetLongitude ()
|
||||||
return current_autopilot->get_TargetLongitude();
|
return current_autopilot->get_TargetLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/**
|
/**
|
||||||
* Set the GPS target longitude in degrees (negative for west).
|
* Set the GPS target longitude in degrees (negative for west).
|
||||||
*/
|
*/
|
||||||
|
@ -1584,6 +1597,7 @@ FGBFI::setGPSTargetLongitude (double longitude)
|
||||||
{
|
{
|
||||||
current_autopilot->set_TargetLongitude( longitude );
|
current_autopilot->set_TargetLongitude( longitude );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -197,8 +197,9 @@ public:
|
||||||
|
|
||||||
static void setTargetAirport (const string &targetAirport);
|
static void setTargetAirport (const string &targetAirport);
|
||||||
static void setGPSLock (bool lock);
|
static void setGPSLock (bool lock);
|
||||||
static void setGPSTargetLatitude (double latitude);
|
// static void setGPSTargetLatitude (double latitude);
|
||||||
static void setGPSTargetLongitude (double longitude);
|
// static void setGPSTargetLongitude (double longitude);
|
||||||
|
static void setGPSTargetWayPoint (double latitude, double longitude);
|
||||||
|
|
||||||
|
|
||||||
// Weather
|
// Weather
|
||||||
|
|
Loading…
Add table
Reference in a new issue