-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-double FGState::GetParameter(eParam val_idx) {
- double scratch;
-
- switch(val_idx) {
- case FG_TIME:
- return sim_time;
- case FG_QBAR:
- return Translation->Getqbar();
- case FG_WINGAREA:
- return Aircraft->GetWingArea();
- case FG_WINGSPAN:
- return Aircraft->GetWingSpan();
- case FG_CBAR:
- return Aircraft->Getcbar();
- case FG_LBARH:
- return Aircraft->Getlbarh();
- case FG_LBARV:
- return Aircraft->Getvbarh();
- case FG_HTAILAREA:
- return Aircraft->GetHTailArea();
- case FG_VTAILAREA:
- return Aircraft->GetVTailArea();
- case FG_VBARH:
- return Aircraft->Getvbarh();
- case FG_VBARV:
- return Aircraft->Getvbarv();
- case FG_ALPHA:
- return Translation->Getalpha();
- case FG_ALPHAW:
- return Translation->Getalpha() + Aircraft->GetWingIncidence();
- case FG_ALPHADOT:
- return Translation->Getadot();
- case FG_BETA:
- return Translation->Getbeta();
- case FG_ABETA:
- return fabs(Translation->Getbeta());
- case FG_BETADOT:
- return Translation->Getbdot();
- case FG_PHI:
- return Rotation->Getphi();
- case FG_THT:
- return Rotation->Gettht();
- case FG_PSI:
- return Rotation->Getpsi();
- case FG_PITCHRATE:
- return Rotation->GetPQR(eQ);
- case FG_ROLLRATE:
- return Rotation->GetPQR(eP);
- case FG_YAWRATE:
- return Rotation->GetPQR(eR);
- case FG_AEROP:
- return Rotation->GetAeroPQR(eP);
- case FG_AEROQ:
- return Rotation->GetAeroPQR(eQ);
- case FG_AEROR:
- return Rotation->GetAeroPQR(eR);
- case FG_CL_SQRD:
- if (Translation->Getqbar() > 0.00)
- scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
- else
- scratch = 0.0;
- return scratch*scratch;
- case FG_ELEVATOR_POS:
- return FCS->GetDePos();
- case FG_AILERON_POS:
- return FCS->GetDaPos();
- case FG_RUDDER_POS:
- return FCS->GetDrPos();
- case FG_SPDBRAKE_POS:
- return FCS->GetDsbPos();
- case FG_SPOILERS_POS:
- return FCS->GetDspPos();
- case FG_FLAPS_POS:
- return FCS->GetDfPos();
- case FG_ELEVATOR_CMD:
- return FCS->GetDeCmd();
- case FG_AILERON_CMD:
- return FCS->GetDaCmd();
- case FG_RUDDER_CMD:
- return FCS->GetDrCmd();
- case FG_SPDBRAKE_CMD:
- return FCS->GetDsbCmd();
- case FG_SPOILERS_CMD:
- return FCS->GetDspCmd();
- case FG_FLAPS_CMD:
- return FCS->GetDfCmd();
- case FG_MACH:
- return Translation->GetMach();
- case FG_ALTITUDE:
- return Position->Geth();
- case FG_BI2VEL:
- if(Translation->GetVt() > 0)
- return Aircraft->GetWingSpan()/(2.0 * Translation->GetVt());
- else
- return 0;
- case FG_CI2VEL:
- if(Translation->GetVt() > 0)
- return Aircraft->Getcbar()/(2.0 * Translation->GetVt());
- else
- return 0;
- case FG_THROTTLE_CMD:
- if (ActiveEngine < 0) return FCS->GetThrottleCmd(0);
- else return FCS->GetThrottleCmd(ActiveEngine);
- case FG_THROTTLE_POS:
- if (ActiveEngine < 0) return FCS->GetThrottlePos(0);
- else return FCS->GetThrottlePos(ActiveEngine);
- case FG_MAGNETO_CMD:
- if (ActiveEngine < 0) return Propulsion->GetEngine(0)->GetMagnetos();
- else return Propulsion->GetEngine(ActiveEngine)->GetMagnetos();
- case FG_STARTER_CMD:
- if (ActiveEngine < 0) {
- if (Propulsion->GetEngine(0)->GetStarter()) return 1.0;
- else return 0.0;
- } else {
- if (Propulsion->GetEngine(ActiveEngine)->GetStarter()) return 1.0;
- else return 0.0;
- }
- case FG_MIXTURE_CMD:
- if (ActiveEngine < 0) return FCS->GetMixtureCmd(0);
- else return FCS->GetMixtureCmd(ActiveEngine);
- case FG_MIXTURE_POS:
- if (ActiveEngine < 0) return FCS->GetMixturePos(0);
- else return FCS->GetMixturePos(ActiveEngine);
- case FG_HOVERB:
- return Position->GetHOverBMAC();
- case FG_PITCH_TRIM_CMD:
- return FCS->GetPitchTrimCmd();
- case FG_YAW_TRIM_CMD:
- return FCS->GetYawTrimCmd();
- case FG_ROLL_TRIM_CMD:
- return FCS->GetRollTrimCmd();
- case FG_GEAR_CMD:
- return FCS->GetGearCmd();
- case FG_GEAR_POS:
- return FCS->GetGearPos();
- default:
- cerr << "FGState::GetParameter() - No handler for parameter " << paramdef[val_idx] << endl;
- return 0.0;
- }
- return 0;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-double FGState::GetParameter(string val_string) {
- return GetParameter(coeffdef[val_string]);
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-eParam FGState::GetParameterIndex(string val_string)
-{
- return coeffdef[val_string];
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGState::SetParameter(eParam val_idx, double val)
-{
- int i;
-
- switch(val_idx) {
- case FG_ELEVATOR_POS:
- FCS->SetDePos(val);
- break;
- case FG_AILERON_POS:
- FCS->SetDaPos(val);
- break;
- case FG_RUDDER_POS:
- FCS->SetDrPos(val);
- break;
- case FG_SPDBRAKE_POS:
- FCS->SetDsbPos(val);
- break;
- case FG_SPOILERS_POS:
- FCS->SetDspPos(val);
- break;
- case FG_FLAPS_POS:
- FCS->SetDfPos(val);
- break;
- case FG_THROTTLE_POS:
- if (ActiveEngine == -1) {
- for (i=0; i<Propulsion->GetNumEngines(); i++) {
- FCS->SetThrottlePos(i,val);
- }
- } else {
- FCS->SetThrottlePos(ActiveEngine,val);
- }
- break;
- case FG_MIXTURE_POS:
- if (ActiveEngine == -1) {
- for (i=0; i<Propulsion->GetNumEngines(); i++) {
- FCS->SetMixturePos(i,val);
- }
- } else {
- FCS->SetMixturePos(ActiveEngine,val);
- }
- break;
-
- case FG_ELEVATOR_CMD:
- FCS->SetDeCmd(val);
- break;
- case FG_AILERON_CMD:
- FCS->SetDaCmd(val);
- break;
- case FG_RUDDER_CMD:
- FCS->SetDrCmd(val);
- break;
- case FG_SPDBRAKE_CMD:
- FCS->SetDsbCmd(val);
- break;
- case FG_SPOILERS_CMD:
- FCS->SetDspCmd(val);
- break;
- case FG_FLAPS_CMD:
- FCS->SetDfCmd(val);
- break;
- case FG_THROTTLE_CMD:
- if (ActiveEngine == -1) {
- for (i=0; i<Propulsion->GetNumEngines(); i++) {
- FCS->SetThrottleCmd(i,val);
- }
- } else {
- FCS->SetThrottleCmd(ActiveEngine,val);
- }
- break;
- case FG_MIXTURE_CMD:
- if (ActiveEngine == -1) {
- for (i=0; i<Propulsion->GetNumEngines(); i++) {
- FCS->SetMixtureCmd(i,val);
- }
- } else {
- FCS->SetMixtureCmd(ActiveEngine,val);
- }
- break;
- case FG_MAGNETO_CMD:
- if (ActiveEngine == -1) {
- for (i=0; i<Propulsion->GetNumEngines(); i++) {
- Propulsion->GetEngine(i)->SetMagnetos((int)val);
- }
- } else {
- Propulsion->GetEngine(ActiveEngine)->SetMagnetos((int)val);
- }
- break;
- case FG_STARTER_CMD:
- if (ActiveEngine == -1) {
- for (i=0; i<Propulsion->GetNumEngines(); i++) {
- if (val < 0.001)
- Propulsion->GetEngine(i)->SetStarter(false);
- else if (val >= 0.001)
- Propulsion->GetEngine(i)->SetStarter(true);
- }
- } else {
- Propulsion->GetEngine(ActiveEngine)->SetStarter(true);
- }
- break;
- case FG_ACTIVE_ENGINE:
- ActiveEngine = (int)val;
- break;
-
- case FG_LEFT_BRAKE_CMD:
- FCS->SetLBrake(val);
- break;
- case FG_CENTER_BRAKE_CMD:
- FCS->SetCBrake(val);
- break;
- case FG_RIGHT_BRAKE_CMD:
- FCS->SetRBrake(val);
- break;
- case FG_GEAR_CMD:
- FCS->SetGearCmd(val);
- break;
- case FG_GEAR_POS:
- FCS->SetGearPos(val);
- break;
- case FG_SET_LOGGING:
- if (val < -0.01) Output->Disable();
- else if (val > 0.01) Output->Enable();
- else Output->Toggle();
- break;
-
- default:
- cerr << "Parameter '" << val_idx << "' (" << paramdef[val_idx] << ") not handled" << endl;
- }
-}
-
-//***************************************************************************
-//
-// Reset: Assume all angles READ FROM FILE IN DEGREES !!
-//
-
-bool FGState::Reset(string path, string acname, string fname)
-{
- string resetDef;
- string token="";
-
- double U, V, W;
- double phi, tht, psi;
- double latitude, longitude, h;
- double wdir, wmag, wnorth, weast;
-
-# ifndef macintosh
- resetDef = path + "/" + acname + "/" + fname + ".xml";
-# else
- resetDef = path + ";" + acname + ";" + fname + ".xml";
-# endif
-
- FGConfigFile resetfile(resetDef);
- if (!resetfile.IsOpen()) return false;
-
- resetfile.GetNextConfigLine();
- token = resetfile.GetValue();
- if (token != string("initialize")) {
- cerr << "The reset file " << resetDef
- << " does not appear to be a reset file" << endl;
- return false;
- } else {
- resetfile.GetNextConfigLine();
- resetfile >> token;
- cout << "Resetting using: " << token << endl << endl;
- }
-
- while (token != string("/initialize") && token != string("EOF")) {
- if (token == "UBODY") resetfile >> U;
- if (token == "VBODY") resetfile >> V;
- if (token == "WBODY") resetfile >> W;
- if (token == "LATITUDE") resetfile >> latitude;
- if (token == "LONGITUDE") resetfile >> longitude;
- if (token == "PHI") resetfile >> phi;
- if (token == "THETA") resetfile >> tht;
- if (token == "PSI") resetfile >> psi;
- if (token == "ALTITUDE") resetfile >> h;
- if (token == "WINDDIR") resetfile >> wdir;
- if (token == "VWIND") resetfile >> wmag;
-
- resetfile >> token;
- }
-
-
- Position->SetLatitude(latitude*degtorad);
- Position->SetLongitude(longitude*degtorad);
- Position->Seth(h);
-
- wnorth = wmag*ktstofps*cos(wdir*degtorad);
- weast = wmag*ktstofps*sin(wdir*degtorad);
-
- Initialize(U, V, W, phi*degtorad, tht*degtorad, psi*degtorad,
- latitude*degtorad, longitude*degtorad, h, wnorth, weast, 0.0);
-
- return true;
-}
-