1
0
Fork 0
flightgear/src/FDM/JSBSim/FGFCS.cpp

935 lines
30 KiB
C++
Raw Normal View History

2001-11-09 04:38:53 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 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 General Public License for more
details.
You should have received a copy of the GNU 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 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 airplane
HISTORY
--------------------------------------------------------------------------------
12/12/98 JSB Created
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGFCS.h"
#include "FGState.h"
#include "FGFDMExec.h"
#include "FGAtmosphere.h"
#include "FGAircraft.h"
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGPosition.h"
#include "FGAuxiliary.h"
#include "FGOutput.h"
#include "FGPropertyManager.h"
2001-11-09 04:38:53 +00:00
#include "filtersjb/FGFilter.h"
#include "filtersjb/FGDeadBand.h"
#include "filtersjb/FGGain.h"
#include "filtersjb/FGGradient.h"
#include "filtersjb/FGSwitch.h"
#include "filtersjb/FGSummer.h"
#include "filtersjb/FGKinemat.h"
2001-11-09 04:38:53 +00:00
static const char *IdSrc = "$Id$";
static const char *IdHdr = ID_FCS;
#if defined(WIN32) && !defined(__CYGWIN__)
#define snprintf _snprintf
#endif
2001-11-09 04:38:53 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
{
int i;
2001-11-09 04:38:53 +00:00
Name = "FGFCS";
DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0.0;
2002-08-28 13:46:42 +00:00
AP_DaCmd = AP_DeCmd = AP_DrCmd = AP_ThrottleCmd = 0.0;
PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
GearCmd = GearPos = 1; // default to gear down
2001-11-09 04:38:53 +00:00
LeftBrake = RightBrake = CenterBrake = 0.0;
DoNormalize=true;
2002-08-28 13:46:42 +00:00
eMode = mNone;
bind();
2002-04-16 13:15:29 +00:00
for (i=0;i<=NForms;i++) {
DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
}
2002-04-16 13:15:29 +00:00
for (i=0;i<NNorm;i++) { ToNormalize[i]=-1;}
2001-12-13 04:48:34 +00:00
Debug(0);
2001-11-09 04:38:53 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGFCS::~FGFCS()
{
ThrottleCmd.clear();
ThrottlePos.clear();
MixtureCmd.clear();
MixturePos.clear();
2001-12-05 03:10:20 +00:00
PropAdvanceCmd.clear();
PropAdvance.clear();
2001-11-09 04:38:53 +00:00
unbind();
2001-11-09 04:38:53 +00:00
2002-08-28 13:46:42 +00:00
unsigned int i;
for (i=0;i<APComponents.size();i++) delete APComponents[i];
for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];
2001-12-13 04:48:34 +00:00
Debug(1);
2001-11-09 04:38:53 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGFCS::Run(void)
{
unsigned int i;
if (!FGModel::Run()) {
for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
2001-12-05 03:10:20 +00:00
for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
2002-08-28 13:46:42 +00:00
for (i=0; i<APComponents.size(); i++) {
eMode = mAP;
APComponents[i]->Run();
eMode = mNone;
}
for (i=0; i<FCSComponents.size(); i++) {
eMode = mFCS;
FCSComponents[i]->Run();
eMode = mNone;
}
2002-04-16 13:15:29 +00:00
if (DoNormalize) Normalize();
2002-08-05 20:13:34 +00:00
2002-08-28 13:46:42 +00:00
return false;
2001-11-09 04:38:53 +00:00
} else {
2002-08-28 13:46:42 +00:00
return true;
2001-11-09 04:38:53 +00:00
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-11-20 22:34:24 +00:00
void FGFCS::SetThrottleCmd(int engineNum, double setting)
2001-11-09 04:38:53 +00:00
{
unsigned int ctr;
2001-11-20 22:34:24 +00:00
if (engineNum < (int)ThrottlePos.size()) {
2001-11-09 04:38:53 +00:00
if (engineNum < 0) {
2001-11-20 22:34:24 +00:00
for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
2001-11-09 04:38:53 +00:00
} else {
ThrottleCmd[engineNum] = setting;
}
} else {
cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
<< " engines exist, but attempted throttle command is for engine "
<< engineNum << endl;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-11-20 22:34:24 +00:00
void FGFCS::SetThrottlePos(int engineNum, double setting)
2001-11-09 04:38:53 +00:00
{
unsigned int ctr;
2001-11-20 22:34:24 +00:00
if (engineNum < (int)ThrottlePos.size()) {
2001-11-09 04:38:53 +00:00
if (engineNum < 0) {
2001-11-20 22:34:24 +00:00
for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
2001-11-09 04:38:53 +00:00
} else {
ThrottlePos[engineNum] = setting;
}
} else {
cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
<< " engines exist, but attempted throttle position setting is for engine "
<< engineNum << endl;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double FGFCS::GetThrottleCmd(int engineNum) const
2001-11-09 04:38:53 +00:00
{
2001-11-20 22:34:24 +00:00
if (engineNum < (int)ThrottlePos.size()) {
2001-11-09 04:38:53 +00:00
if (engineNum < 0) {
cerr << "Cannot get throttle value for ALL engines" << endl;
} else {
return ThrottleCmd[engineNum];
}
} else {
cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
<< " engines exist, but throttle setting for engine " << engineNum
2001-12-05 03:10:20 +00:00
<< " is selected" << endl;
2001-11-09 04:38:53 +00:00
}
return 0.0;
2001-11-09 04:38:53 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double FGFCS::GetThrottlePos(int engineNum) const
2001-11-09 04:38:53 +00:00
{
2001-11-20 22:34:24 +00:00
if (engineNum < (int)ThrottlePos.size()) {
2001-11-09 04:38:53 +00:00
if (engineNum < 0) {
cerr << "Cannot get throttle value for ALL engines" << endl;
} else {
return ThrottlePos[engineNum];
}
} else {
cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
<< " engines exist, but attempted throttle position setting is for engine "
<< engineNum << endl;
}
return 0.0;
2001-11-09 04:38:53 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-11-20 22:34:24 +00:00
void FGFCS::SetMixtureCmd(int engineNum, double setting)
2001-11-09 04:38:53 +00:00
{
unsigned int ctr;
2001-11-20 22:34:24 +00:00
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
} else {
MixtureCmd[engineNum] = setting;
}
2001-11-09 04:38:53 +00:00
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-11-20 22:34:24 +00:00
void FGFCS::SetMixturePos(int engineNum, double setting)
2001-11-09 04:38:53 +00:00
{
unsigned int ctr;
2001-11-20 22:34:24 +00:00
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
} else {
MixturePos[engineNum] = setting;
}
2001-11-09 04:38:53 +00:00
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-12-05 03:10:20 +00:00
void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
{
unsigned int ctr;
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
2001-12-05 03:10:20 +00:00
for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
} else {
2001-12-05 03:10:20 +00:00
PropAdvanceCmd[engineNum] = setting;
}
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-12-05 03:10:20 +00:00
void FGFCS::SetPropAdvance(int engineNum, double setting)
{
unsigned int ctr;
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
2001-12-05 03:10:20 +00:00
for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
} else {
2001-12-05 03:10:20 +00:00
PropAdvance[engineNum] = setting;
}
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-11-09 04:38:53 +00:00
bool FGFCS::Load(FGConfigFile* AC_cfg)
{
2002-08-28 13:46:42 +00:00
string token, delimiter;
string name, file, fname;
unsigned i;
2002-08-28 13:46:42 +00:00
vector <FGFCSComponent*> *Components;
FGConfigFile *FCS_cfg;
Components=0;
2002-08-28 13:46:42 +00:00
// Determine if the FCS/Autopilot is defined inline in the aircraft configuration
// file or in a separate file. Set up the config file class as appropriate.
delimiter = AC_cfg->GetValue();
name = AC_cfg->GetValue("NAME");
fname = AC_cfg->GetValue("FILE");
if ( AC_cfg->GetValue("NORMALIZE") == "FALSE") {
DoNormalize = false;
cout << " Automatic Control Surface Normalization Disabled" << endl;
}
# ifndef macintosh
file = "control/" + fname + ".xml";
# else
file = "control;" + fname + ".xml";
# endif
if (name.empty()) {
name = fname;
if (file.empty()) {
cerr << "FCS/Autopilot does not appear to be defined inline nor in a file" << endl;
} else {
FCS_cfg = new FGConfigFile(file);
if (!FCS_cfg->IsOpen()) {
cerr << "Could not open " << delimiter << " file: " << file << endl;
return false;
} else {
AC_cfg = FCS_cfg; // set local config file object pointer to FCS config
// file object pointer
}
}
} else {
AC_cfg->GetNextConfigLine();
}
if (delimiter == "AUTOPILOT") {
Components = &APComponents;
eMode = mAP;
Name = "Autopilot: " + name;
2002-08-28 13:46:42 +00:00
} else if (delimiter == "FLIGHT_CONTROL") {
Components = &FCSComponents;
eMode = mFCS;
Name = "FCS: " + name;
2002-08-28 13:46:42 +00:00
} else {
cerr << endl << "Unknown FCS delimiter" << endl << endl;
}
2001-11-09 04:38:53 +00:00
if (debug_lvl > 0) cout << " Control System Name: " << Name << endl;
2002-08-28 13:46:42 +00:00
while ((token = AC_cfg->GetValue()) != string("/" + delimiter)) {
2001-11-09 04:38:53 +00:00
if (token == "COMPONENT") {
token = AC_cfg->GetValue("TYPE");
2002-02-17 21:04:44 +00:00
if (debug_lvl > 0) cout << endl << " Loading Component \""
2001-11-09 04:38:53 +00:00
<< AC_cfg->GetValue("NAME")
2001-12-05 03:10:20 +00:00
<< "\" of type: " << token << endl;
2001-11-09 04:38:53 +00:00
if ((token == "LAG_FILTER") ||
(token == "LEAD_LAG_FILTER") ||
(token == "SECOND_ORDER_FILTER") ||
(token == "WASHOUT_FILTER") ||
(token == "INTEGRATOR") ) {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGFilter(this, AC_cfg));
2001-11-09 04:38:53 +00:00
} else if ((token == "PURE_GAIN") ||
(token == "SCHEDULED_GAIN") ||
(token == "AEROSURFACE_SCALE") ) {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGGain(this, AC_cfg));
2001-11-09 04:38:53 +00:00
} else if (token == "SUMMER") {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGSummer(this, AC_cfg));
2001-11-09 04:38:53 +00:00
} else if (token == "DEADBAND") {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGDeadBand(this, AC_cfg));
2001-11-09 04:38:53 +00:00
} else if (token == "GRADIENT") {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGGradient(this, AC_cfg));
2001-11-09 04:38:53 +00:00
} else if (token == "SWITCH") {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGSwitch(this, AC_cfg));
} else if (token == "KINEMAT") {
2002-08-28 13:46:42 +00:00
Components->push_back(new FGKinemat(this, AC_cfg));
2001-11-09 04:38:53 +00:00
} else {
cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
return false;
}
2002-08-28 13:46:42 +00:00
if (AC_cfg->GetNextConfigLine() == "EOF") break;
2001-11-09 04:38:53 +00:00
}
}
2002-08-28 13:46:42 +00:00
//collect information for normalizing control surfaces
2002-08-28 13:46:42 +00:00
string nodeName;
2002-08-28 13:46:42 +00:00
for (i=0; i<Components->size(); i++) {
2002-08-28 13:46:42 +00:00
if ( (((*Components)[i])->GetType() == "AEROSURFACE_SCALE"
|| ((*Components)[i])->GetType() == "KINEMAT")
&& ((*Components)[i])->GetOutputNode() ) {
nodeName = ((*Components)[i])->GetOutputNode()->GetName();
2002-04-16 13:15:29 +00:00
if ( nodeName == "elevator-pos-rad" ) {
ToNormalize[iDe]=i;
} else if ( nodeName == "left-aileron-pos-rad"
|| nodeName == "aileron-pos-rad" ) {
ToNormalize[iDaL]=i;
} else if ( nodeName == "right-aileron-pos-rad" ) {
ToNormalize[iDaR]=i;
} else if ( nodeName == "rudder-pos-rad" ) {
ToNormalize[iDr]=i;
} else if ( nodeName == "speedbrake-pos-rad" ) {
ToNormalize[iDsb]=i;
} else if ( nodeName == "spoiler-pos-rad" ) {
ToNormalize[iDsp]=i;
} else if ( nodeName == "flap-pos-deg" ) {
ToNormalize[iDf]=i;
}
}
}
2002-08-28 13:46:42 +00:00
if (delimiter == "FLIGHT_CONTROL") bindModel();
eMode = mNone;
2001-11-09 04:38:53 +00:00
return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002-08-28 13:46:42 +00:00
double FGFCS::GetComponentOutput(int idx)
{
switch (eMode) {
case mFCS:
return FCSComponents[idx]->GetOutput();
case mAP:
return APComponents[idx]->GetOutput();
case mNone:
cerr << "Unknown FCS mode" << endl;
break;
}
return 0.0;
2001-11-09 04:38:53 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002-08-28 13:46:42 +00:00
string FGFCS::GetComponentName(int idx)
{
switch (eMode) {
case mFCS:
return FCSComponents[idx]->GetName();
case mAP:
return APComponents[idx]->GetName();
case mNone:
cerr << "Unknown FCS mode" << endl;
break;
}
return string("");
}
2001-11-09 04:38:53 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-12-13 04:48:34 +00:00
double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
{
2001-11-09 04:38:53 +00:00
switch (bg) {
case FGLGear::bgLeft:
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::GetComponentStrings(void)
{
unsigned int comp;
string CompStrings = "";
bool firstime = true;
2002-08-28 13:46:42 +00:00
for (comp = 0; comp < FCSComponents.size(); comp++) {
2001-11-09 04:38:53 +00:00
if (firstime) firstime = false;
else CompStrings += ", ";
2002-08-28 13:46:42 +00:00
CompStrings += FCSComponents[comp]->GetName();
}
for (comp = 0; comp < APComponents.size(); comp++)
{
CompStrings += ", ";
CompStrings += APComponents[comp]->GetName();
2001-11-09 04:38:53 +00:00
}
return CompStrings;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGFCS::GetComponentValues(void)
{
unsigned int comp;
string CompValues = "";
char buffer[10];
bool firstime = true;
2002-08-28 13:46:42 +00:00
for (comp = 0; comp < FCSComponents.size(); comp++) {
2001-11-09 04:38:53 +00:00
if (firstime) firstime = false;
else CompValues += ", ";
2002-08-28 13:46:42 +00:00
sprintf(buffer, "%9.6f", FCSComponents[comp]->GetOutput());
CompValues += string(buffer);
}
for (comp = 0; comp < APComponents.size(); comp++) {
sprintf(buffer, ", %9.6f", APComponents[comp]->GetOutput());
2001-11-09 04:38:53 +00:00
CompValues += string(buffer);
}
return CompValues;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGFCS::AddThrottle(void)
{
ThrottleCmd.push_back(0.0);
ThrottlePos.push_back(0.0);
2001-12-05 03:10:20 +00:00
MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
2001-11-09 04:38:53 +00:00
MixturePos.push_back(0.0);
2001-12-05 03:10:20 +00:00
PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
PropAdvance.push_back(0.0);
2001-11-09 04:38:53 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGFCS::Normalize(void) {
//not all of these are guaranteed to be defined for every model
//those that are have an index >=0 in the ToNormalize array
//ToNormalize is filled in Load()
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDe] > -1 ) {
2002-08-28 13:46:42 +00:00
DePos[ofNorm] = FCSComponents[ToNormalize[iDe]]->GetOutputPct();
}
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDaL] > -1 ) {
2002-08-28 13:46:42 +00:00
DaLPos[ofNorm] = FCSComponents[ToNormalize[iDaL]]->GetOutputPct();
}
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDaR] > -1 ) {
2002-08-28 13:46:42 +00:00
DaRPos[ofNorm] = FCSComponents[ToNormalize[iDaR]]->GetOutputPct();
}
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDr] > -1 ) {
2002-08-28 13:46:42 +00:00
DrPos[ofNorm] = FCSComponents[ToNormalize[iDr]]->GetOutputPct();
}
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDsb] > -1 ) {
2002-08-28 13:46:42 +00:00
DsbPos[ofNorm] = FCSComponents[ToNormalize[iDsb]]->GetOutputPct();
}
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDsp] > -1 ) {
2002-08-28 13:46:42 +00:00
DspPos[ofNorm] = FCSComponents[ToNormalize[iDsp]]->GetOutputPct();
}
2002-04-16 13:15:29 +00:00
if ( ToNormalize[iDf] > -1 ) {
2002-08-28 13:46:42 +00:00
DfPos[ofNorm] = FCSComponents[ToNormalize[iDf]]->GetOutputPct();
}
DePos[ofMag] = fabs(DePos[ofRad]);
DaLPos[ofMag] = fabs(DaLPos[ofRad]);
DaRPos[ofMag] = fabs(DaRPos[ofRad]);
DrPos[ofMag] = fabs(DrPos[ofRad]);
DsbPos[ofMag] = fabs(DsbPos[ofRad]);
DspPos[ofMag] = fabs(DspPos[ofRad]);
DfPos[ofMag] = fabs(DfPos[ofRad]);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002-04-16 13:15:29 +00:00
void FGFCS::bind(void)
{
PropertyManager->Tie("fcs/aileron-cmd-norm", this,
&FGFCS::GetDaCmd,
&FGFCS::SetDaCmd,
true);
PropertyManager->Tie("fcs/elevator-cmd-norm", this,
&FGFCS::GetDeCmd,
&FGFCS::SetDeCmd,
true);
PropertyManager->Tie("fcs/rudder-cmd-norm", this,
&FGFCS::GetDrCmd,
&FGFCS::SetDrCmd,
true);
PropertyManager->Tie("fcs/flap-cmd-norm", this,
&FGFCS::GetDfCmd,
&FGFCS::SetDfCmd,
true);
PropertyManager->Tie("fcs/speedbrake-cmd-norm", this,
&FGFCS::GetDsbCmd,
&FGFCS::SetDsbCmd,
true);
PropertyManager->Tie("fcs/spoiler-cmd-norm", this,
&FGFCS::GetDspCmd,
&FGFCS::SetDspCmd,
true);
PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this,
&FGFCS::GetPitchTrimCmd,
&FGFCS::SetPitchTrimCmd,
true);
PropertyManager->Tie("fcs/roll-trim-cmd-norm", this,
&FGFCS::GetYawTrimCmd,
&FGFCS::SetYawTrimCmd,
true);
PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this,
&FGFCS::GetRollTrimCmd,
&FGFCS::SetRollTrimCmd,
true);
PropertyManager->Tie("gear/gear-cmd-norm", this,
&FGFCS::GetGearCmd,
&FGFCS::SetGearCmd,
true);
PropertyManager->Tie("fcs/left-aileron-pos-rad", this,ofRad,
&FGFCS::GetDaLPos,
&FGFCS::SetDaLPos,
true);
PropertyManager->Tie("fcs/left-aileron-pos-norm", this,ofNorm,
&FGFCS::GetDaLPos,
&FGFCS::SetDaLPos,
true);
PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this,ofMag,
&FGFCS::GetDaLPos,
&FGFCS::SetDaLPos,
true);
PropertyManager->Tie("fcs/right-aileron-pos-rad", this,ofRad,
&FGFCS::GetDaRPos,
&FGFCS::SetDaRPos,
true);
PropertyManager->Tie("fcs/right-aileron-pos-norm", this,ofNorm,
&FGFCS::GetDaRPos,
&FGFCS::SetDaRPos,
true);
PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this,ofMag,
&FGFCS::GetDaRPos,
&FGFCS::SetDaRPos,
true);
PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad,
&FGFCS::GetDePos,
&FGFCS::SetDePos,
true );
PropertyManager->Tie("fcs/elevator-pos-norm", this,ofNorm,
&FGFCS::GetDePos,
&FGFCS::SetDePos,
true );
PropertyManager->Tie("fcs/mag-elevator-pos-rad", this,ofMag,
&FGFCS::GetDePos,
&FGFCS::SetDePos,
true );
PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad,
&FGFCS::GetDrPos,
&FGFCS::SetDrPos,
true);
PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm,
&FGFCS::GetDrPos,
&FGFCS::SetDrPos,
true);
PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag,
&FGFCS::GetDrPos,
&FGFCS::SetDrPos,
true);
PropertyManager->Tie("fcs/flap-pos-deg", this,ofRad,
&FGFCS::GetDfPos,
&FGFCS::SetDfPos,
true);
PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm,
&FGFCS::GetDfPos,
&FGFCS::SetDfPos,
true);
PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad,
&FGFCS::GetDsbPos,
&FGFCS::SetDsbPos,
true);
PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm,
&FGFCS::GetDsbPos,
&FGFCS::SetDsbPos,
true);
PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag,
&FGFCS::GetDsbPos,
&FGFCS::SetDsbPos,
true);
PropertyManager->Tie("fcs/spoiler-pos-rad", this,ofRad,
&FGFCS::GetDspPos,
&FGFCS::SetDspPos,
true);
PropertyManager->Tie("fcs/spoiler-pos-norm", this,ofNorm,
&FGFCS::GetDspPos,
&FGFCS::SetDspPos,
true);
PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this,ofMag,
&FGFCS::GetDspPos,
&FGFCS::SetDspPos,
true);
PropertyManager->Tie("gear/gear-pos-norm", this,
&FGFCS::GetGearPos,
&FGFCS::SetGearPos,
true);
2002-08-28 13:46:42 +00:00
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/elevator_cmd", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPDeCmd,
&FGFCS::SetAPDeCmd,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/aileron_cmd", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPDaCmd,
&FGFCS::SetAPDaCmd,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/rudder_cmd", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPDrCmd,
&FGFCS::SetAPDrCmd,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/throttle_cmd", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPThrottleCmd,
&FGFCS::SetAPThrottleCmd,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/attitude_setpoint", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAttitudeSetPt,
&FGFCS::SetAPAttitudeSetPt,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/altitude_setpoint", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAltitudeSetPt,
&FGFCS::SetAPAltitudeSetPt,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/heading_setpoint", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPHeadingSetPt,
&FGFCS::SetAPHeadingSetPt,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/airspeed_setpoint", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAirspeedSetPt,
&FGFCS::SetAPAirspeedSetPt,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/acquire_attitude", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAcquireAttitude,
&FGFCS::SetAPAcquireAttitude,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/acquire_altitude", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAcquireAltitude,
&FGFCS::SetAPAcquireAltitude,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/acquire_heading", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAcquireHeading,
&FGFCS::SetAPAcquireHeading,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/acquire_airspeed", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAcquireAirspeed,
&FGFCS::SetAPAcquireAirspeed,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/attitude_hold", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAttitudeHold,
&FGFCS::SetAPAttitudeHold,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/altitude_hold", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAltitudeHold,
&FGFCS::SetAPAltitudeHold,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/heading_hold", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPHeadingHold,
&FGFCS::SetAPHeadingHold,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/airspeed_hold", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPAirspeedHold,
&FGFCS::SetAPAirspeedHold,
true);
2002-09-05 13:55:16 +00:00
PropertyManager->Tie("ap/wingslevel_hold", this,
2002-08-28 13:46:42 +00:00
&FGFCS::GetAPWingsLevelHold,
&FGFCS::SetAPWingsLevelHold,
true);
}
2002-04-16 13:15:29 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002-04-16 13:15:29 +00:00
void FGFCS::bindModel(void)
{
unsigned i;
char tmp[80];
2002-04-16 13:15:29 +00:00
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 );
2002-04-16 13:15:29 +00:00
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 );
}
2002-04-16 13:15:29 +00:00
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 );
}
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002-04-16 13:15:29 +00:00
void FGFCS::unbind(void)
{
PropertyManager->Untie("fcs/aileron-cmd-norm");
PropertyManager->Untie("fcs/elevator-cmd-norm");
PropertyManager->Untie("fcs/rudder-cmd-norm");
PropertyManager->Untie("fcs/flap-cmd-norm");
PropertyManager->Untie("fcs/speedbrake-cmd-norm");
PropertyManager->Untie("fcs/spoiler-cmd-norm");
PropertyManager->Untie("fcs/pitch-trim-cmd-norm");
PropertyManager->Untie("fcs/roll-trim-cmd-norm");
PropertyManager->Untie("fcs/yaw-trim-cmd-norm");
PropertyManager->Untie("gear/gear-cmd-norm");
PropertyManager->Untie("fcs/left-aileron-pos-rad");
PropertyManager->Untie("fcs/mag-left-aileron-pos-rad");
PropertyManager->Untie("fcs/left-aileron-pos-norm");
PropertyManager->Untie("fcs/right-aileron-pos-rad");
PropertyManager->Untie("fcs/mag-right-aileron-pos-rad");
PropertyManager->Untie("fcs/right-aileron-pos-norm");
PropertyManager->Untie("fcs/elevator-pos-rad");
PropertyManager->Untie("fcs/mag-elevator-pos-rad");
PropertyManager->Untie("fcs/elevator-pos-norm");
PropertyManager->Untie("fcs/rudder-pos-rad");
PropertyManager->Untie("fcs/mag-rudder-pos-rad");
PropertyManager->Untie("fcs/rudder-pos-norm");
PropertyManager->Untie("fcs/flap-pos-deg");
PropertyManager->Untie("fcs/flap-pos-norm");
PropertyManager->Untie("fcs/speedbrake-pos-rad");
PropertyManager->Untie("fcs/mag-speedbrake-pos-rad");
PropertyManager->Untie("fcs/speedbrake-pos-norm");
PropertyManager->Untie("fcs/spoiler-pos-rad");
PropertyManager->Untie("fcs/mag-spoiler-pos-rad");
PropertyManager->Untie("fcs/spoiler-pos-norm");
PropertyManager->Untie("gear/gear-pos-norm");
2002-09-05 13:55:16 +00:00
PropertyManager->Untie("ap/elevator_cmd");
PropertyManager->Untie("ap/aileron_cmd");
PropertyManager->Untie("ap/rudder_cmd");
PropertyManager->Untie("ap/throttle_cmd");
PropertyManager->Untie("ap/attitude_setpoint");
PropertyManager->Untie("ap/altitude_setpoint");
PropertyManager->Untie("ap/heading_setpoint");
PropertyManager->Untie("ap/airspeed_setpoint");
PropertyManager->Untie("ap/acquire_attitude");
PropertyManager->Untie("ap/acquire_altitude");
PropertyManager->Untie("ap/acquire_heading");
PropertyManager->Untie("ap/acquire_airspeed");
PropertyManager->Untie("ap/attitude_hold");
PropertyManager->Untie("ap/altitude_hold");
PropertyManager->Untie("ap/heading_hold");
PropertyManager->Untie("ap/airspeed_hold");
PropertyManager->Untie("ap/wingslevel_hold");
}
2001-11-09 04:38:53 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-12-13 04:48:34 +00:00
// 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 bounds
void FGFCS::Debug(int from)
2001-11-09 04:38:53 +00:00
{
2001-12-13 04:48:34 +00:00
if (debug_lvl <= 0) return;
if (debug_lvl & 1) { // Standard console startup message output
if (from == 0) { // Constructor
2001-11-09 04:38:53 +00:00
2001-12-13 04:48:34 +00:00
}
}
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
}
2001-12-24 13:54:55 +00:00
if (debug_lvl & 64) {
if (from == 0) { // Constructor
cout << IdSrc << endl;
cout << IdHdr << endl;
}
}
2001-12-13 04:48:34 +00:00
}
2001-12-24 13:54:55 +00:00