Add support for a simple deadband.
This commit is contained in:
parent
c6c094034c
commit
61ed285d06
1 changed files with 15 additions and 8 deletions
|
@ -223,17 +223,17 @@ bool FGATCInput::open() {
|
||||||
|
|
||||||
// scale a number between min and max (with center defined) to a scale
|
// scale a number between min and max (with center defined) to a scale
|
||||||
// from -1.0 to 1.0
|
// from -1.0 to 1.0
|
||||||
static double scale( int center, int min, int max, int value ) {
|
static double scale( int center, int deadband, int min, int max, int value ) {
|
||||||
// cout << center << " " << min << " " << max << " " << value << " ";
|
// cout << center << " " << min << " " << max << " " << value << " ";
|
||||||
double result;
|
double result;
|
||||||
double range;
|
double range;
|
||||||
|
|
||||||
if ( value <= center ) {
|
if ( value <= (center - deadband) ) {
|
||||||
range = center - min;
|
range = (center - deadband) - min;
|
||||||
result = (value - center) / range;
|
result = (value - (center - deadband)) / range;
|
||||||
} else {
|
} else {
|
||||||
range = max - center;
|
range = max - (center + deadband);
|
||||||
result = (value - center) / range;
|
result = (value - (center + deadband)) / range;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( result < -1.0 ) result = -1.0;
|
if ( result < -1.0 ) result = -1.0;
|
||||||
|
@ -401,6 +401,7 @@ bool FGATCInput::do_analog_in() {
|
||||||
int center = -1;
|
int center = -1;
|
||||||
int min = 0;
|
int min = 0;
|
||||||
int max = 1023;
|
int max = 1023;
|
||||||
|
int deadband = 0;
|
||||||
float factor = 1.0;
|
float factor = 1.0;
|
||||||
if ( cname == "channel" ) {
|
if ( cname == "channel" ) {
|
||||||
SGPropertyNode *prop;
|
SGPropertyNode *prop;
|
||||||
|
@ -435,6 +436,10 @@ bool FGATCInput::do_analog_in() {
|
||||||
if ( prop != NULL ) {
|
if ( prop != NULL ) {
|
||||||
max = prop->getIntValue();
|
max = prop->getIntValue();
|
||||||
}
|
}
|
||||||
|
prop = child->getChild( "deadband" );
|
||||||
|
if ( prop != NULL ) {
|
||||||
|
deadband = prop->getIntValue();
|
||||||
|
}
|
||||||
prop = child->getChild( "factor" );
|
prop = child->getChild( "factor" );
|
||||||
if ( prop != NULL ) {
|
if ( prop != NULL ) {
|
||||||
factor = prop->getFloatValue();
|
factor = prop->getFloatValue();
|
||||||
|
@ -456,7 +461,8 @@ bool FGATCInput::do_analog_in() {
|
||||||
// "Cook" the raw value
|
// "Cook" the raw value
|
||||||
float scaled_value = 0.0f;
|
float scaled_value = 0.0f;
|
||||||
if ( center >= 0 ) {
|
if ( center >= 0 ) {
|
||||||
scaled_value = scale( center, min, max, raw_value );
|
scaled_value = scale( center, deadband,
|
||||||
|
min, max, raw_value );
|
||||||
} else {
|
} else {
|
||||||
scaled_value = scale( min, max, raw_value );
|
scaled_value = scale( min, max, raw_value );
|
||||||
}
|
}
|
||||||
|
@ -471,7 +477,8 @@ bool FGATCInput::do_analog_in() {
|
||||||
// "Cook" the raw value
|
// "Cook" the raw value
|
||||||
float scaled_value = 0.0f;
|
float scaled_value = 0.0f;
|
||||||
if ( center >= 0 ) {
|
if ( center >= 0 ) {
|
||||||
scaled_value = scale( center, min, max, raw_value );
|
scaled_value = scale( center, deadband,
|
||||||
|
min, max, raw_value );
|
||||||
} else {
|
} else {
|
||||||
scaled_value = scale( min, max, raw_value );
|
scaled_value = scale( min, max, raw_value );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue