1
0
Fork 0

- Oops, some name simplification led to overlapping variable names which caused

the adf needle to not point correctly, fixed.
- Make the code slightly smarter so ADF needle never takes the long way around
  to it's destination.
This commit is contained in:
curt 2002-07-02 22:35:15 +00:00
parent a28b35f3f2
commit aef1876858
2 changed files with 26 additions and 22 deletions

View file

@ -208,13 +208,13 @@ FGKR_87::unbind ()
void void
FGKR_87::update(double dt) FGKR_87::update(double dt)
{ {
double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; double acft_lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; double acft_lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER; double acft_elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
need_update = false; need_update = false;
Point3D aircraft = sgGeodToCart( Point3D( lon, lat, elev ) ); Point3D aircraft = sgGeodToCart( Point3D( acft_lon, acft_lat, acft_elev ) );
Point3D station; Point3D station;
double az1, az2, s; double az1, az2, s;
@ -298,15 +298,16 @@ FGKR_87::update(double dt)
dist = aircraft.distance3D( station ); dist = aircraft.distance3D( station );
// wgs84 heading // wgs84 heading
geo_inverse_wgs_84( elev, lat * SGD_RADIANS_TO_DEGREES, geo_inverse_wgs_84( acft_elev,
lon * SGD_RADIANS_TO_DEGREES, acft_lat * SGD_RADIANS_TO_DEGREES,
lat, lon, acft_lon * SGD_RADIANS_TO_DEGREES,
stn_lat, stn_lon,
&az1, &az2, &s ); &az1, &az2, &s );
heading = az1; heading = az1;
// cout << " heading = " << heading // cout << " heading = " << heading
// << " dist = " << dist << endl; // << " dist = " << dist << endl;
effective_range = kludgeRange(elev, elev, range); effective_range = kludgeRange(stn_elev, acft_elev, range);
if ( dist < effective_range * SG_NM_TO_METER ) { if ( dist < effective_range * SG_NM_TO_METER ) {
inrange = true; inrange = true;
} else if ( dist < 2 * effective_range * SG_NM_TO_METER ) { } else if ( dist < 2 * effective_range * SG_NM_TO_METER ) {
@ -334,7 +335,10 @@ FGKR_87::update(double dt)
elapsed_timer = 0.0; elapsed_timer = 0.0;
} }
cout << "goal = " << goal_needle_deg << "actual = " << needle_deg << endl;
double diff = goal_needle_deg - needle_deg; double diff = goal_needle_deg - needle_deg;
while ( diff < -180.0 ) { diff += 360.0; }
while ( diff > 180.0 ) { diff -= 360.0; }
needle_deg += diff * dt * 4; needle_deg += diff * dt * 4;
// cout << "flt = " << flight_timer << " et = " << elapsed_timer // cout << "flt = " << flight_timer << " et = " << elapsed_timer
@ -375,9 +379,9 @@ FGKR_87::update(double dt)
// Update current nav/adf radio stations based on current postition // Update current nav/adf radio stations based on current postition
void FGKR_87::search() void FGKR_87::search()
{ {
double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; double acft_lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; double acft_lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER; double acft_elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
// FIXME: the panel should handle this // FIXME: the panel should handle this
FGNav nav; FGNav nav;
@ -388,22 +392,22 @@ void FGKR_87::search()
// ADF. // ADF.
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
if ( current_navlist->query( lon, lat, elev, freq, &nav ) ) { if ( current_navlist->query( acft_lon, acft_lat, acft_elev, freq, &nav ) ) {
char sfreq[128]; char sfreq[128];
snprintf( sfreq, 10, "%.0f", freq ); snprintf( sfreq, 10, "%.0f", freq );
ident = sfreq; ident = sfreq;
ident += nav.get_ident(); ident += nav.get_ident();
// cout << "adf ident = " << ident << endl; cout << "adf ident = " << ident << endl;
valid = true; valid = true;
if ( last_ident != ident ) { if ( last_ident != ident ) {
last_ident = ident; last_ident = ident;
trans_ident = nav.get_trans_ident(); trans_ident = nav.get_trans_ident();
lon = nav.get_lon(); stn_lon = nav.get_lon();
lat = nav.get_lat(); stn_lat = nav.get_lat();
elev = nav.get_elev(); stn_elev = nav.get_elev();
range = nav.get_range(); range = nav.get_range();
effective_range = kludgeRange(elev, elev, range); effective_range = kludgeRange(stn_elev, acft_elev, range);
x = nav.get_x(); x = nav.get_x();
y = nav.get_y(); y = nav.get_y();
z = nav.get_z(); z = nav.get_z();

View file

@ -60,9 +60,9 @@ class FGKR_87 : public FGSubsystem
double freq; double freq;
double stby_freq; double stby_freq;
double rotation; double rotation;
double lon; double stn_lon;
double lat; double stn_lat;
double elev; double stn_elev;
double range; double range;
double effective_range; double effective_range;
double dist; double dist;
@ -134,8 +134,8 @@ public:
// Calculated values // Calculated values
inline bool get_inrange() const { return inrange; } inline bool get_inrange() const { return inrange; }
inline double get_lon() const { return lon; } inline double get_stn_lon() const { return stn_lon; }
inline double get_lat() const { return lat; } inline double get_stn_lat() const { return stn_lat; }
inline double get_heading() const { return heading; } inline double get_heading() const { return heading; }
inline double get_needle_deg() const { return needle_deg; } inline double get_needle_deg() const { return needle_deg; }
inline double get_flight_timer() const { return flight_timer; } inline double get_flight_timer() const { return flight_timer; }