]> git.mxchange.org Git - flightgear.git/commitdiff
Added support for calibration properties.
authorcurt <curt>
Thu, 12 Sep 2002 03:15:27 +0000 (03:15 +0000)
committercurt <curt>
Thu, 12 Sep 2002 03:15:27 +0000 (03:15 +0000)
src/Network/atc610x.cxx
src/Network/atc610x.hxx

index 1541814eddd37ee5c444b2749f7f1181a65d634d..8deae3498c94be6104eb71cddd35f81a4c3fe11a 100644 (file)
@@ -44,6 +44,7 @@
 #include <simgear/io/iochannel.hxx>
 #include <simgear/math/sg_types.hxx>
 #include <simgear/misc/props.hxx>
+#include <simgear/misc/sg_path.hxx>
 
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
@@ -204,6 +205,19 @@ void ATC610xSetLamp( int fd, int channel, bool value ) {
 }
 
 
+void FGATC610x::init_config() {
+#if defined( unix ) || defined( __CYGWIN__ )
+    // Next check home directory for .fgfsrc.hostname file
+    char *envp = ::getenv( "HOME" );
+    if ( envp != NULL ) {
+        SGPath atc610x_config( envp );
+        atc610x_config.append( ".fgfs-atc610x.xml" );
+        readProperties( atc610x_config.str(), globals->get_props() );
+    }
+#endif
+}
+
+
 // Open and initialize ATC 610x hardware
 bool FGATC610x::open() {
     if ( is_enabled() ) {
@@ -212,6 +226,9 @@ bool FGATC610x::open() {
        return false;
     }
 
+    // This loads the config parameters generated by "simcal"
+    init_config();
+
     SG_LOG( SG_IO, SG_ALERT,
            "Initializing ATC 610x hardware, please wait ..." );
 
@@ -434,6 +451,34 @@ bool FGATC610x::open() {
     xpdr_sby_ann = fgGetNode( "/radios/kt-70/annunciators/sby", true );
     xpdr_reply_ann = fgGetNode( "/radios/kt-70/annunciators/reply", true );
 
+    elevator_center = fgGetNode( "/input/atc610x/elevator/center", 0 );
+    elevator_min = fgGetNode( "/input/atc610x/elevator/min", 0 );
+    elevator_max = fgGetNode( "/input/atc610x/elevator/max", 0 );
+
+    ailerons_center = fgGetNode( "/input/atc610x/ailerons/center", 0 );
+    ailerons_min = fgGetNode( "/input/atc610x/ailerons/min", 0 );
+    ailerons_max = fgGetNode( "/input/atc610x/ailerons/max", 0 );
+
+    rudder_center = fgGetNode( "/input/atc610x/rudder/center", 0 );
+    rudder_min = fgGetNode( "/input/atc610x/rudder/min", 0 );
+    rudder_max = fgGetNode( "/input/atc610x/rudder/max", 0 );
+
+    throttle_min = fgGetNode( "/input/atc610x/throttle/min", 0 );
+    throttle_max = fgGetNode( "/input/atc610x/throttle/max", 0 );
+
+    mixture_min = fgGetNode( "/input/atc610x/mixture/min", 0 );
+    mixture_max = fgGetNode( "/input/atc610x/mixture/max", 0 );
+
+    trim_center = fgGetNode( "/input/atc610x/trim/center", 0 );
+    trim_min = fgGetNode( "/input/atc610x/trim/min", 0 );
+    trim_max = fgGetNode( "/input/atc610x/trim/max", 0 );
+
+    nav1vol_min = fgGetNode( "/input/atc610x/nav1vol/min", 0 );
+    nav1vol_max = fgGetNode( "/input/atc610x/nav1vol/max", 0 );
+
+    nav2vol_min = fgGetNode( "/input/atc610x/nav2vol/min", 0 );
+    nav2vol_max = fgGetNode( "/input/atc610x/nav2vol/max", 0 );
+
     return true;
 }
 
@@ -447,6 +492,48 @@ bool FGATC610x::open() {
 #define ATC_ELEVATOR_CENTER 543
 #define ATC_RUDDER_CENTER 519
 
+// scale a number between min and max (with center defined) to a scale
+// from -1.0 to 1.0
+static double scale( int center, int min, int max, int value ) {
+    // cout << center << " " << min << " " << max << " " << value << " ";
+    double result;
+    double range;
+
+    if ( value <= center ) {
+        range = center - min;
+        result = (value - center) / range;
+    } else {
+        range = max - center;
+        result = (value - center) / range;            
+    }
+
+    if ( result < -1.0 ) result = -1.0;
+    if ( result > 1.0 ) result = 1.0;
+
+    // cout << result << endl;
+
+    return result;
+}
+
+
+// scale a number between min and max to a scale from 0.0 to 1.0
+static double scale( int min, int max, int value ) {
+    // cout << center << " " << min << " " << max << " " << value << " ";
+    double result;
+    double range;
+
+    range = max - min;
+    result = (value - min) / range;
+
+    if ( result < 0.0 ) result = 0.0;
+    if ( result > 1.0 ) result = 1.0;
+
+    // cout << result << endl;
+
+    return result;
+}
+
+
 bool FGATC610x::do_analog_in() {
     // Read raw data in byte form
     ATC610xReadAnalogInputs( analog_in_fd, analog_in_bytes );
@@ -464,33 +551,39 @@ bool FGATC610x::do_analog_in() {
     float tmp, tmp1, tmp2;
 
     // aileron
-    tmp = (float)(analog_in_data[0] - ATC_AILERON_CENTER) / 256.0f;
+    tmp = scale( ailerons_center->getIntValue(), ailerons_min->getIntValue(),
+                 ailerons_max->getIntValue(), analog_in_data[0] );
     fgSetFloat( "/controls/aileron", tmp );
     // cout << "aileron = " << analog_in_data[0] << " = " << tmp;
 
     // elevator
-    tmp = (float)(analog_in_data[4] - ATC_ELEVATOR_TRIM_CENTER) / 512.0f;
-    fgSetFloat( "/controls/elevator-trim", tmp );
+    tmp = -scale( elevator_center->getIntValue(), elevator_min->getIntValue(),
+                  elevator_max->getIntValue(), analog_in_data[5] );
+    fgSetFloat( "/controls/elevator", tmp );
     // cout << "trim = " << analog_in_data[4] << " = " << tmp;
 
-    // trim
-    tmp = (float)(ATC_ELEVATOR_CENTER - analog_in_data[5]) / 100.0f;
-    fgSetFloat( "/controls/elevator", tmp );
+    // elevator trim
+    tmp = scale( trim_center->getIntValue(), trim_min->getIntValue(),
+                 trim_max->getIntValue(), analog_in_data[4] );
+    fgSetFloat( "/controls/elevator-trim", tmp );
     // cout << " elev = " << analog_in_data[5] << " = " << tmp << endl;
 
     // mixture
-    tmp = (float)analog_in_data[7] / 680.0f;
+    tmp = scale( mixture_min->getIntValue(), mixture_max->getIntValue(),
+                 analog_in_data[7] );
     fgSetFloat( "/controls/mixture[0]", tmp );
     fgSetFloat( "/controls/mixture[1]", tmp );
 
     // throttle
-    tmp = ((float)analog_in_data[8] - 141.0) / 632.0f;
+    tmp = scale( mixture_min->getIntValue(), mixture_max->getIntValue(),
+                 analog_in_data[8] );
     fgSetFloat( "/controls/throttle[0]", tmp );
     fgSetFloat( "/controls/throttle[1]", tmp );
 
 #if 0
     // rudder
-    tmp = (float)(ATC_RUDDER_CENTER - analog_in_data[10]) / 145.0f;
+    tmp = scale( rudder_center->getIntValue(), rudder_min->getIntValue(),
+                 rudder_max->getIntValue(), analog_in_data[10] );
     fgSetFloat( "/controls/rudder", tmp );
 #endif
 
index 5adf18b7042dd87663e5aded1bceab333dc77784..64b89d4021e57dac02260b3bbb406a3c143669e2 100644 (file)
@@ -70,6 +70,7 @@ class FGATC610x : public FGProtocol {
     unsigned char switch_data[ATC_SWITCH_BYTES];
 
     float compass_position;
+
     SGPropertyNode *mag_compass;
     SGPropertyNode *dme_min, *dme_kt, *dme_nm;
     SGPropertyNode *com1_freq, *com1_stby_freq;
@@ -90,6 +91,16 @@ class FGATC610x : public FGProtocol {
     SGPropertyNode *xpdr_fl_ann, *xpdr_alt_ann, *xpdr_gnd_ann, *xpdr_on_ann;
     SGPropertyNode *xpdr_sby_ann, *xpdr_reply_ann;
 
+    // configuration values
+    SGPropertyNode *elevator_center, *elevator_min, *elevator_max;
+    SGPropertyNode *ailerons_center, *ailerons_min, *ailerons_max;
+    SGPropertyNode *rudder_center, *rudder_min, *rudder_max;
+    SGPropertyNode *throttle_min, *throttle_max;
+    SGPropertyNode *mixture_min, *mixture_max;
+    SGPropertyNode *trim_center, *trim_min, *trim_max;
+    SGPropertyNode *nav1vol_min, *nav1vol_max;
+    SGPropertyNode *nav2vol_min, *nav2vol_max;
+
     int dme_switch;
 
     bool do_analog_in();
@@ -106,6 +117,7 @@ public:
     ~FGATC610x() { }
 
     bool open();
+    void init_config();
 
     bool process();