]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFCS.cpp
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / JSBSim / FGFCS.cpp
index adcf66554548447cb3c5e622e5fdde556b1d500b..57e73bf8c0aa7411a16eb6ac214f9361351e4518 100644 (file)
@@ -60,6 +60,10 @@ INCLUDES
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_FCS;
 
+#if defined(WIN32) && !defined(__CYGWIN__)
+#define snprintf _snprintf
+#endif
+
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS IMPLEMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -76,12 +80,12 @@ FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
   DoNormalize=true;
   
   bind();
-  for(i=0;i<=NForms;i++) {
+  for (i=0;i<=NForms;i++) {
     DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
     DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
   }
     
-  for(i=0;i<NNorm;i++) { ToNormalize[i]=-1;}
+  for (i=0;i<NNorm;i++) { ToNormalize[i]=-1;}
   Debug(0);
 }
 
@@ -115,7 +119,7 @@ bool FGFCS::Run(void)
     for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
     for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
     for (i=0; i<Components.size(); i++)  Components[i]->Run();
-    if(DoNormalize) Normalize();
+    if (DoNormalize) Normalize();
   } else {
   }
 
@@ -162,7 +166,7 @@ void FGFCS::SetThrottlePos(int engineNum, double setting)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-double FGFCS::GetThrottleCmd(int engineNum)
+double FGFCS::GetThrottleCmd(int engineNum) const
 {
   if (engineNum < (int)ThrottlePos.size()) {
     if (engineNum < 0) {
@@ -180,7 +184,7 @@ double FGFCS::GetThrottleCmd(int engineNum)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-double FGFCS::GetThrottlePos(int engineNum)
+double FGFCS::GetThrottlePos(int engineNum) const
 {
   if (engineNum < (int)ThrottlePos.size()) {
     if (engineNum < 0) {
@@ -265,7 +269,7 @@ bool FGFCS::Load(FGConfigFile* AC_cfg)
   
   Name = Name + ":" + AC_cfg->GetValue("NAME");
   if (debug_lvl > 0) cout << "    Control System Name: " << Name << endl;
-  if( AC_cfg->GetValue("NORMALIZE") == "FALSE") {
+  if ( AC_cfg->GetValue("NORMALIZE") == "FALSE") {
       DoNormalize=false;
       cout << "    Automatic Control Surface Normalization Disabled" << endl;
   }    
@@ -306,36 +310,40 @@ bool FGFCS::Load(FGConfigFile* AC_cfg)
     }
   }
   //collect information for normalizing control surfaces
-  
-  for(i=0;i<Components.size();i++) {
+  string nodeName;
+  for (i=0;i<Components.size();i++) {
     
-    if(Components[i]->GetType() == "AEROSURFACE_SCALE" 
-        || Components[i]->GetType() == "KINEMAT"  ) {
-      if( Components[i]->GetOutputIdx() == FG_ELEVATOR_POS ) {
+    if ( (Components[i]->GetType() == "AEROSURFACE_SCALE" 
+          || Components[i]->GetType() == "KINEMAT")  
+                    && Components[i]->GetOutputNode() ) { 
+      nodeName= Components[i]->GetOutputNode()->GetName();  
+      if ( nodeName == "elevator-pos-rad" ) {
         ToNormalize[iDe]=i;
-      } else if ( Components[i]->GetOutputIdx() == FG_LEFT_AILERON_POS 
-                      || Components[i]->GetOutputIdx() == FG_AILERON_POS ) {
+      } else if ( nodeName  == "left-aileron-pos-rad" 
+                   || nodeName == "aileron-pos-rad" ) {
         ToNormalize[iDaL]=i;
-      } else if ( Components[i]->GetOutputIdx() == FG_RIGHT_AILERON_POS ) {
+      } else if ( nodeName == "right-aileron-pos-rad" ) {
         ToNormalize[iDaR]=i;
-      } else if ( Components[i]->GetOutputIdx() == FG_RUDDER_POS ) {
+      } else if ( nodeName == "rudder-pos-rad" ) {
         ToNormalize[iDr]=i;
-      } else if ( Components[i]->GetOutputIdx() == FG_SPDBRAKE_POS ) {
+      } else if ( nodeName == "speedbrake-pos-rad" ) {
         ToNormalize[iDsb]=i;
-      } else if ( Components[i]->GetOutputIdx() == FG_SPOILERS_POS ) {
+      } else if ( nodeName == "spoiler-pos-rad" ) {
         ToNormalize[iDsp]=i;
-      } else if ( Components[i]->GetOutputIdx() == FG_FLAPS_POS ) {
+      } else if ( nodeName == "flap-pos-deg" ) {
         ToNormalize[iDf]=i;
       }
     }
   }     
   
+  bindModel();
+  
   return true;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-double FGFCS::GetComponentOutput(eParam idx) {
+double FGFCS::GetComponentOutput(int idx) {
   return Components[idx]->GetOutput();
 }
 
@@ -420,31 +428,31 @@ void FGFCS::Normalize(void) {
   //those that are have an index >=0 in the ToNormalize array
   //ToNormalize is filled in Load()
   
-  if( ToNormalize[iDe] > -1 ) {
+  if ( ToNormalize[iDe] > -1 ) {
     DePos[ofNorm] = Components[ToNormalize[iDe]]->GetOutputPct();
   }
   
-  if( ToNormalize[iDaL] > -1 ) {
+  if ( ToNormalize[iDaL] > -1 ) {
     DaLPos[ofNorm] = Components[ToNormalize[iDaL]]->GetOutputPct();
   }
   
-  if( ToNormalize[iDaR] > -1 ) {
+  if ( ToNormalize[iDaR] > -1 ) {
     DaRPos[ofNorm] = Components[ToNormalize[iDaR]]->GetOutputPct();
   }
 
-  if( ToNormalize[iDr] > -1 ) {
+  if ( ToNormalize[iDr] > -1 ) {
     DrPos[ofNorm] = Components[ToNormalize[iDr]]->GetOutputPct();
   }
        
-  if( ToNormalize[iDsb] > -1 ) { 
+  if ( ToNormalize[iDsb] > -1 ) { 
     DsbPos[ofNorm] = Components[ToNormalize[iDsb]]->GetOutputPct();
   }
   
-  if( ToNormalize[iDsp] > -1 ) {
+  if ( ToNormalize[iDsp] > -1 ) {
     DspPos[ofNorm] = Components[ToNormalize[iDsp]]->GetOutputPct();
   }
   
-  if( ToNormalize[iDf] > -1 ) {
+  if ( ToNormalize[iDf] > -1 ) {
     DfPos[ofNorm] = Components[ToNormalize[iDf]]->GetOutputPct();
   }
   
@@ -460,7 +468,8 @@ void FGFCS::Normalize(void) {
     
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGFCS::bind(void){
+void FGFCS::bind(void)
+{
   PropertyManager->Tie("fcs/aileron-cmd-norm", this,
                        &FGFCS::GetDaCmd,
                        &FGFCS::SetDaCmd,
@@ -597,7 +606,53 @@ void FGFCS::bind(void){
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGFCS::unbind(void){
+void FGFCS::bindModel(void)
+{
+  unsigned i;
+  char tmp[80];
+  
+  for (i=0; i<ThrottleCmd.size(); i++) {
+    snprintf(tmp,80,"fcs/throttle-cmd-norm[%u]",i);
+    PropertyManager->Tie( tmp,this,i,
+                          &FGFCS::GetThrottleCmd,
+                          &FGFCS::SetThrottleCmd,
+                          true );
+    snprintf(tmp,80,"fcs/throttle-pos-norm[%u]",i);                      
+    PropertyManager->Tie( tmp,this,i,
+                          &FGFCS::GetThrottlePos,
+                          &FGFCS::SetThrottlePos,
+                          true );
+    if ( MixtureCmd.size() > i ) {
+      snprintf(tmp,80,"fcs/mixture-cmd-norm[%u]",i); 
+      PropertyManager->Tie( tmp,this,i,
+                            &FGFCS::GetMixtureCmd,
+                            &FGFCS::SetMixtureCmd,
+                            true );
+      snprintf(tmp,80,"fcs/mixture-pos-norm[%u]",i);                    
+      PropertyManager->Tie( tmp,this,i,
+                            &FGFCS::GetMixturePos,
+                            &FGFCS::SetMixturePos,
+                            true );
+    }
+    if ( PropAdvanceCmd.size() > i ) {
+      snprintf(tmp,80,"fcs/advance-cmd-norm[%u]",i); 
+      PropertyManager->Tie( tmp,this,i,
+                            &FGFCS::GetPropAdvanceCmd,
+                            &FGFCS::SetPropAdvanceCmd,
+                            true );
+      snprintf(tmp,80,"fcs/advance-pos-norm[%u]",i);                       
+      PropertyManager->Tie( tmp,this,i,
+                            &FGFCS::GetPropAdvance,
+                            &FGFCS::SetPropAdvance,
+                            true );
+    }
+  }
+}                            
+                          
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFCS::unbind(void)
+{
   PropertyManager->Untie("fcs/aileron-cmd-norm");
   PropertyManager->Untie("fcs/elevator-cmd-norm");
   PropertyManager->Untie("fcs/rudder-cmd-norm");
@@ -631,8 +686,6 @@ void FGFCS::unbind(void){
   PropertyManager->Untie("gear/gear-pos-norm");
 }
 
-
-
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 //    The bitmasked value choices are as follows:
 //    unset: In this case (the default) JSBSim would only print