1
0
Fork 0

Work on nav2_obs tuner.

This commit is contained in:
curt 2002-12-14 14:38:19 +00:00
parent 339f39f235
commit 51c5b9bf09
2 changed files with 78 additions and 3 deletions

View file

@ -422,10 +422,12 @@ bool FGATC610x::open() {
nav1_freq = fgGetNode( "/radios/nav[0]/frequencies/selected-mhz", true );
nav1_stby_freq
= fgGetNode( "/radios/nav[0]/frequencies/standby-mhz", true );
nav1_obs = fgGetNode( "/radios/nav[0]/radials/selected-deg", true );
nav2_freq = fgGetNode( "/radios/nav[1]/frequencies/selected-mhz", true );
nav2_stby_freq
= fgGetNode( "/radios/nav[1]/frequencies/standby-mhz", true );
nav2_obs = fgGetNode( "/radios/nav[1]/radials/selected-deg", true );
adf_power_btn = fgGetNode( "/radios/kr-87/inputs/power-btn", true );
adf_vol = fgGetNode( "/radios/kr-87/inputs/volume", true );
@ -610,7 +612,80 @@ bool FGATC610x::do_analog_in() {
fgSetFloat( "/radios/kr-87/inputs/volume", tmp );
// nav2 obs tuner
tmp = (float)analog_in_data[29] * 360.0f / 1024.0f;
static int last_obs2 = analog_in_data[29];
static double diff_ave = 0.0;
int diff = 0;
// cout << "val = " << analog_in_data[29] << " last_obs = " << last_obs2;
#define FG_SECOND_TRY
#if defined( FG_FIRST_TRY )
if ( analog_in_data[29] < 150 || analog_in_data[29] > 990 ) {
if ( last_obs2 > 512 && last_obs2 <= 990 ) {
diff = 1;
} else if ( last_obs2 >= 150 && last_obs2 <= 990 ) {
diff = -1;
}
} else if ( last_obs2 < 150 || last_obs2 > 990 ) {
if ( analog_in_data[29] > 512 && analog_in_data[29] <= 990 ) {
diff = -1;
} else if ( analog_in_data[29] >= 150 && analog_in_data[29] <= 990 ) {
diff = 1;
}
} else {
diff = analog_in_data[29] - last_obs2;
}
#elif defined( FG_SECOND_TRY )
if ( analog_in_data[29] < 20 ) {
if ( last_obs2 >= 110 && last_obs2 < 512 ) {
diff = -1;
} else if ( last_obs2 >= 512 ) {
diff = 1;
}
last_obs2 = analog_in_data[29];
} else if ( analog_in_data[29] < 110 ) {
// do nothing
} else if ( last_obs2 < 20 ) {
if ( analog_in_data[29] >= 110 && analog_in_data[29] < 512 ) {
diff = 1;
} else if ( analog_in_data[29] >= 512 ) {
diff = -1;
}
last_obs2 = analog_in_data[29];
} else {
diff = analog_in_data[29] - last_obs2;
if ( abs(diff) > 200 ) {
// ignore
diff = 0;
}
last_obs2 = analog_in_data[29];
}
#elif defined( FG_THIRD_TRY )
static bool ignore_next = false;
diff = analog_in_data[29] - last_obs2;
if ( abs(diff) > 200 ) {
// ignore
diff = 0;
ignore_next = true;
} else if ( ignore_next ) {
diff = 0;
ignore_next = false;
}
last_obs2 = analog_in_data[29];
#endif
// cout << " diff = " << diff << endl;
if ( diff < -500 ) { diff += 1024; }
if ( diff > 500 ) { diff -= 1024; }
if ( fabs(diff_ave - diff) < 200 || fabs(diff) < fabs(diff_ave) ) {
diff_ave = (2.0/3.0) * diff_ave + (1.0/3.0) * diff;
}
tmp = nav2_obs->getDoubleValue() + (diff_ave * (60.0/914.0) );
while ( tmp >= 360.0 ) { tmp -= 360.0; }
while ( tmp < 0.0 ) { tmp += 360.0; }
fgSetFloat( "/radios/nav[1]/radials/selected-deg", tmp );
// nav1 obs tuner

View file

@ -79,8 +79,8 @@ class FGATC610x : public FGProtocol {
SGPropertyNode *navcom1_power_btn, *navcom2_power_btn;
SGPropertyNode *com1_freq, *com1_stby_freq;
SGPropertyNode *com2_freq, *com2_stby_freq;
SGPropertyNode *nav1_freq, *nav1_stby_freq;
SGPropertyNode *nav2_freq, *nav2_stby_freq;
SGPropertyNode *nav1_freq, *nav1_stby_freq, *nav1_obs;
SGPropertyNode *nav2_freq, *nav2_stby_freq, *nav2_obs;
SGPropertyNode *adf_adf_btn, *adf_bfo_btn;
SGPropertyNode *adf_power_btn, *adf_vol;
SGPropertyNode *adf_freq, *adf_stby_freq;