fgfcs.cpp
来自「6 DOF Missle Simulation」· C++ 代码 · 共 992 行 · 第 1/3 页
CPP
992 行
return LeftBrake; case FGLGear::bgRight: return RightBrake; case FGLGear::bgCenter: return CenterBrake; default: cerr << "GetBrake asked to return a bogus brake value" << endl; } return 0.0;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%string FGFCS::FindSystemFullPathname(string system_filename){ string fullpath, localpath; string systemPath = FDMExec->GetSystemsPath(); string aircraftPath = FDMExec->GetFullAircraftPath(); ifstream system_file; string separator = "/"; fullpath = systemPath + separator; localpath = aircraftPath + separator + "Systems" + separator; system_file.open(string(fullpath + system_filename + ".xml").c_str()); if ( !system_file.is_open()) { system_file.open(string(localpath + system_filename + ".xml").c_str()); if ( !system_file.is_open()) { cerr << " Could not open system file: " << system_filename << " in path " << fullpath << " or " << localpath << endl; return string(""); } else { return string(localpath + system_filename + ".xml"); } } return string(fullpath + system_filename + ".xml");}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ifstream* FGFCS::FindSystemFile(string system_filename){ string fullpath, localpath; string systemPath = FDMExec->GetSystemsPath(); string aircraftPath = FDMExec->GetFullAircraftPath(); ifstream* system_file = new ifstream(); string separator = "/"; fullpath = systemPath + separator; localpath = aircraftPath + separator + "Systems" + separator; system_file->open(string(fullpath + system_filename + ".xml").c_str()); if ( !system_file->is_open()) { system_file->open(string(localpath + system_filename + ".xml").c_str()); if ( !system_file->is_open()) { cerr << " Could not open system file: " << system_filename << " in path " << fullpath << " or " << localpath << endl; } } return system_file;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%string FGFCS::GetComponentStrings(string delimeter){ unsigned int comp; string CompStrings = ""; bool firstime = true; int total_count=0; for (unsigned int i=0; i<Systems.size(); i++) { if (firstime) firstime = false; else CompStrings += delimeter; CompStrings += Systems[i]->GetName(); total_count++; } for (comp = 0; comp < APComponents.size(); comp++) { if (firstime) firstime = false; else CompStrings += delimeter; CompStrings += APComponents[comp]->GetName(); total_count++; } for (comp = 0; comp < FCSComponents.size(); comp++) { if (firstime) firstime = false; else CompStrings += delimeter; CompStrings += FCSComponents[comp]->GetName(); total_count++; } return CompStrings;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%string FGFCS::GetComponentValues(string delimeter){ unsigned int comp; string CompValues = ""; char buffer[100]; bool firstime = true; int total_count=0; for (unsigned int i=0; i<Systems.size(); i++) { if (firstime) firstime = false; else CompValues += delimeter; snprintf(buffer, 100, "%9.6f", Systems[i]->GetOutput()); CompValues += string(buffer); total_count++; } for (comp = 0; comp < APComponents.size(); comp++) { if (firstime) firstime = false; else CompValues += delimeter; sprintf(buffer, "%9.6f", APComponents[comp]->GetOutput()); CompValues += string(buffer); total_count++; } for (comp = 0; comp < FCSComponents.size(); comp++) { if (firstime) firstime = false; else CompValues += delimeter; sprintf(buffer, "%9.6f", FCSComponents[comp]->GetOutput()); CompValues += string(buffer); total_count++; } CompValues += "\0"; return CompValues;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::AddThrottle(void){ ThrottleCmd.push_back(0.0); ThrottlePos.push_back(0.0); MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled MixturePos.push_back(0.0); PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled PropAdvance.push_back(0.0); PropFeatherCmd.push_back(false); PropFeather.push_back(false); unsigned int num = (unsigned int)ThrottleCmd.size()-1; bindThrottle(num);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::AddGear(void){ SteerPosDeg.push_back(0.0);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%double FGFCS::GetDt(void){ return FDMExec->GetDeltaT()*rate;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::bind(void){ PropertyManager->Tie("fcs/aileron-cmd-norm", this, &FGFCS::GetDaCmd, &FGFCS::SetDaCmd); PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd); PropertyManager->Tie("fcs/rudder-cmd-norm", this, &FGFCS::GetDrCmd, &FGFCS::SetDrCmd); PropertyManager->Tie("fcs/flap-cmd-norm", this, &FGFCS::GetDfCmd, &FGFCS::SetDfCmd); PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, &FGFCS::GetDsbCmd, &FGFCS::SetDsbCmd); PropertyManager->Tie("fcs/spoiler-cmd-norm", this, &FGFCS::GetDspCmd, &FGFCS::SetDspCmd); PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, &FGFCS::GetPitchTrimCmd, &FGFCS::SetPitchTrimCmd); PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, &FGFCS::GetRollTrimCmd, &FGFCS::SetRollTrimCmd); PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, &FGFCS::GetYawTrimCmd, &FGFCS::SetYawTrimCmd); PropertyManager->Tie("fcs/left-aileron-pos-rad", this, ofRad, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos); PropertyManager->Tie("fcs/left-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos); PropertyManager->Tie("fcs/left-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos); PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this, ofMag, &FGFCS::GetDaLPos); PropertyManager->Tie("fcs/right-aileron-pos-rad", this, ofRad, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos); PropertyManager->Tie("fcs/right-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos); PropertyManager->Tie("fcs/right-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos); PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this, ofMag, &FGFCS::GetDaRPos); PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, &FGFCS::GetDePos, &FGFCS::SetDePos); PropertyManager->Tie("fcs/elevator-pos-deg", this, ofDeg, &FGFCS::GetDePos, &FGFCS::SetDePos); PropertyManager->Tie("fcs/elevator-pos-norm", this, ofNorm, &FGFCS::GetDePos, &FGFCS::SetDePos); PropertyManager->Tie("fcs/mag-elevator-pos-rad", this, ofMag, &FGFCS::GetDePos); PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, &FGFCS::GetDrPos, &FGFCS::SetDrPos); PropertyManager->Tie("fcs/rudder-pos-deg", this,ofDeg, &FGFCS::GetDrPos, &FGFCS::SetDrPos); PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, &FGFCS::GetDrPos, &FGFCS::SetDrPos); PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, &FGFCS::GetDrPos); PropertyManager->Tie("fcs/flap-pos-rad", this,ofRad, &FGFCS::GetDfPos, &FGFCS::SetDfPos); PropertyManager->Tie("fcs/flap-pos-deg", this,ofDeg, &FGFCS::GetDfPos, &FGFCS::SetDfPos); PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, &FGFCS::GetDfPos, &FGFCS::SetDfPos); PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos); PropertyManager->Tie("fcs/speedbrake-pos-deg", this,ofDeg, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos); PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos); PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, &FGFCS::GetDsbPos); PropertyManager->Tie("fcs/spoiler-pos-rad", this, ofRad, &FGFCS::GetDspPos, &FGFCS::SetDspPos); PropertyManager->Tie("fcs/spoiler-pos-deg", this, ofDeg, &FGFCS::GetDspPos, &FGFCS::SetDspPos); PropertyManager->Tie("fcs/spoiler-pos-norm", this, ofNorm, &FGFCS::GetDspPos, &FGFCS::SetDspPos); PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this, ofMag, &FGFCS::GetDspPos); PropertyManager->Tie("gear/gear-pos-norm", this, &FGFCS::GetGearPos, &FGFCS::SetGearPos); PropertyManager->Tie("gear/gear-cmd-norm", this, &FGFCS::GetGearCmd, &FGFCS::SetGearCmd); PropertyManager->Tie("fcs/left-brake-cmd-norm", this, &FGFCS::GetLBrake, &FGFCS::SetLBrake); PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake); PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake); PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd); PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos); PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%// Technically, this function should probably bind propulsion type specific controls// rather than mixture and prop-advance.//void FGFCS::bindThrottle(unsigned int num){ char tmp[80]; snprintf(tmp, 80, "fcs/throttle-cmd-norm[%u]",num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottleCmd, &FGFCS::SetThrottleCmd); snprintf(tmp, 80, "fcs/throttle-pos-norm[%u]",num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottlePos, &FGFCS::SetThrottlePos); snprintf(tmp, 80, "fcs/mixture-cmd-norm[%u]",num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixtureCmd, &FGFCS::SetMixtureCmd); snprintf(tmp, 80, "fcs/mixture-pos-norm[%u]",num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixturePos, &FGFCS::SetMixturePos); snprintf(tmp, 80, "fcs/advance-cmd-norm[%u]",num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvanceCmd, &FGFCS::SetPropAdvanceCmd); snprintf(tmp, 80, "fcs/advance-pos-norm[%u]", num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvance, &FGFCS::SetPropAdvance); snprintf(tmp, 80, "fcs/feather-cmd-norm[%u]", num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetFeatherCmd, &FGFCS::SetFeatherCmd); snprintf(tmp, 80, "fcs/feather-pos-norm[%u]", num); PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropFeather, &FGFCS::SetPropFeather);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%void FGFCS::bindModel(void){ unsigned int i; char tmp[80]; for (i=0; i<SteerPosDeg.size(); i++) { if (GroundReactions->GetGearUnit(i)->GetSteerable()) { snprintf(tmp,80,"fcs/steer-pos-deg[%u]",i); PropertyManager->Tie( tmp, this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg); } }}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%// The bitmasked value choices are as follows:// unset: In this case (the default) JSBSim would only print// out the normally expected messages, essentially echoing// the config files as they are read. If the environment// variable is not set, debug_lvl is set to 1 internally// 0: This requests JSBSim not to output any messages// whatsoever.// 1: This value explicity requests the normal JSBSim// startup messages// 2: This value asks for a message to be printed out when// a class is instantiated// 4: When this value is set, a message is displayed when a// FGModel object executes its Run() method// 8: When this value is set, various runtime state variables// are printed out periodically// 16: When set various parameters are sanity checked and// a message is printed out when they go out of boundsvoid FGFCS::Debug(int from){ if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output if (from == 2) { // Loader cout << endl << " Flight Control (" << Name << ")" << endl; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification if (from == 0) cout << "Instantiated: FGFCS" << endl; if (from == 1) cout << "Destroyed: FGFCS" << endl; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } if (debug_lvl & 8 ) { // Runtime state variables } if (debug_lvl & 16) { // Sanity checking } if (debug_lvl & 64) { if (from == 0) { // Constructor cout << IdSrc << endl; cout << IdHdr << endl; } }}}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?