fgfcs.cpp

来自「6 DOF Missle Simulation」· C++ 代码 · 共 992 行 · 第 1/3 页

CPP
992
字号
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Module:       FGFCS.cpp  Author:       Jon Berndt Date started: 12/12/98 Purpose:      Model the flight controls Called by:    FDMExec ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. Further information about the GNU Lesser General Public License can also be found on the world wide web at http://www.gnu.org.FUNCTIONAL DESCRIPTION--------------------------------------------------------------------------------This class models the flight controls for a specific airplaneHISTORY--------------------------------------------------------------------------------12/12/98   JSB   Created%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%INCLUDES%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#include "FGFCS.h"#include <FGFDMExec.h>#include <input_output/FGPropertyManager.h>#include <fstream>#include <models/flight_control/FGFilter.h>#include <models/flight_control/FGDeadBand.h>#include <models/flight_control/FGGain.h>#include <models/flight_control/FGPID.h>#include <models/flight_control/FGGradient.h>#include <models/flight_control/FGSwitch.h>#include <models/flight_control/FGSummer.h>#include <models/flight_control/FGKinemat.h>#include <models/flight_control/FGFCSFunction.h>#include <models/flight_control/FGSensor.h>#include <models/flight_control/FGActuator.h>namespace JSBSim {static const char *IdSrc = "$Id$";static const char *IdHdr = ID_FCS;#if defined(WIN32) && !defined(__CYGWIN__)#define snprintf _snprintf#endif/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CLASS IMPLEMENTATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex){  int i;  Name = "FGFCS";  DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;  PTrimCmd = YTrimCmd = RTrimCmd = 0.0;  GearCmd = GearPos = 1; // default to gear down  LeftBrake = RightBrake = CenterBrake = 0.0;  TailhookPos = WingFoldPos = 0.0;   bind();  for (i=0;i<NForms;i++) {    DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;    DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;  }  Debug(0);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FGFCS::~FGFCS(){  ThrottleCmd.clear();  ThrottlePos.clear();  MixtureCmd.clear();  MixturePos.clear();  PropAdvanceCmd.clear();  PropAdvance.clear();  SteerPosDeg.clear();  PropFeatherCmd.clear();  PropFeather.clear();  unsigned int i;  for (i=0;i<sensors.size();i++) delete sensors[i];  sensors.clear();  for (i=0;i<APComponents.size();i++) delete APComponents[i];  APComponents.clear();  for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];  FCSComponents.clear();  for (i=0;i<Systems.size();i++) delete Systems[i];  Systems.clear();  for (unsigned int i=0; i<interface_properties.size(); i++) delete interface_properties[i];  interface_properties.clear();  Debug(1);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%bool FGFCS::InitModel(void){  unsigned int i;  if (!FGModel::InitModel()) return false;  for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = 0.0;  for (i=0; i<MixturePos.size(); i++) MixturePos[i] = 0.0;  for (i=0; i<ThrottleCmd.size(); i++) ThrottleCmd[i] = 0.0;  for (i=0; i<MixtureCmd.size(); i++) MixtureCmd[i] = 0.0;  for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = 0.0;  for (i=0; i<PropFeather.size(); i++) PropFeather[i] = 0.0;  DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;  PTrimCmd = YTrimCmd = RTrimCmd = 0.0;  TailhookPos = WingFoldPos = 0.0;  for (i=0;i<NForms;i++) {    DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;    DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;  }  return true;}  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%// Notes: In this logic the default engine commands are set. This is simply a// sort of safe-mode method in case the user has not defined control laws for// throttle, mixture, and prop-advance. The throttle, mixture, and prop advance// positions are set equal to the respective commands. Any control logic that is// actually present in the flight_control or autopilot section will override// these simple assignments.bool FGFCS::Run(void){  unsigned int i;  if (FGModel::Run()) return true; // fast exit if nothing to do  if (FDMExec->Holding()) return false;  for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];  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<PropFeather.size(); i++) PropFeather[i] = PropFeatherCmd[i];  // Set the default steering angle  for (i=0; i<SteerPosDeg.size(); i++) {    FGLGear* gear = GroundReactions->GetGearUnit(i);    SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );  }  // Cycle through the sensor, systems, autopilot, and flight control components  // Execute Sensors  for (i=0; i<sensors.size(); i++) sensors[i]->Run();  // Execute Systems in order  for (i=0; i<Systems.size(); i++) Systems[i]->Run();  // Execute Autopilot  for (i=0; i<APComponents.size(); i++) APComponents[i]->Run();  // Execute Flight Control System  for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();  return false;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDaLPos( int form , double pos ){  switch(form) {  case ofRad:    DaLPos[ofRad] = pos;    DaLPos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DaLPos[ofRad] = pos*degtorad;    DaLPos[ofDeg] = pos;    break;  case ofNorm:    DaLPos[ofNorm] = pos;  }  DaLPos[ofMag] = fabs(DaLPos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDaRPos( int form , double pos ){  switch(form) {  case ofRad:    DaRPos[ofRad] = pos;    DaRPos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DaRPos[ofRad] = pos*degtorad;    DaRPos[ofDeg] = pos;    break;  case ofNorm:    DaRPos[ofNorm] = pos;  }  DaRPos[ofMag] = fabs(DaRPos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDePos( int form , double pos ){  switch(form) {  case ofRad:    DePos[ofRad] = pos;    DePos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DePos[ofRad] = pos*degtorad;    DePos[ofDeg] = pos;    break;  case ofNorm:    DePos[ofNorm] = pos;  }  DePos[ofMag] = fabs(DePos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDrPos( int form , double pos ){  switch(form) {  case ofRad:    DrPos[ofRad] = pos;    DrPos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DrPos[ofRad] = pos*degtorad;    DrPos[ofDeg] = pos;    break;  case ofNorm:    DrPos[ofNorm] = pos;  }  DrPos[ofMag] = fabs(DrPos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDfPos( int form , double pos ){  switch(form) {  case ofRad:    DfPos[ofRad] = pos;    DfPos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DfPos[ofRad] = pos*degtorad;    DfPos[ofDeg] = pos;    break;  case ofNorm:    DfPos[ofNorm] = pos;  }  DfPos[ofMag] = fabs(DfPos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDsbPos( int form , double pos ){  switch(form) {  case ofRad:    DsbPos[ofRad] = pos;    DsbPos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DsbPos[ofRad] = pos*degtorad;    DsbPos[ofDeg] = pos;    break;  case ofNorm:    DsbPos[ofNorm] = pos;  }  DsbPos[ofMag] = fabs(DsbPos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetDspPos( int form , double pos ){  switch(form) {  case ofRad:    DspPos[ofRad] = pos;    DspPos[ofDeg] = pos*radtodeg;    break;  case ofDeg:    DspPos[ofRad] = pos*degtorad;    DspPos[ofDeg] = pos;    break;  case ofNorm:    DspPos[ofNorm] = pos;  }  DspPos[ofMag] = fabs(DspPos[ofRad]);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::SetThrottleCmd(int engineNum, double setting){  unsigned int ctr;  if (engineNum < (int)ThrottlePos.size()) {    if (engineNum < 0) {      for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?