Fix for bug #204 and #222 by Bertrand Coconnier; NaNs (bug #222) were basically generated because the method JSBSim::unbind() was not implemented in JSBSim.cxx.
This commit is contained in:
parent
2ea7f87ae1
commit
287cc74965
3 changed files with 36 additions and 24 deletions
|
@ -144,8 +144,6 @@ FGJSBsim::FGJSBsim( double dt )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resetPropertyState();
|
|
||||||
|
|
||||||
fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
|
fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
|
||||||
|
|
||||||
// Register ground callback.
|
// Register ground callback.
|
||||||
|
@ -424,6 +422,33 @@ void FGJSBsim::init()
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
void checkTied ( FGPropertyManager *node )
|
||||||
|
{
|
||||||
|
int N = node->nChildren();
|
||||||
|
string name;
|
||||||
|
|
||||||
|
for (int i=0; i<N; i++) {
|
||||||
|
if (node->getChild(i)->nChildren() ) {
|
||||||
|
checkTied( (FGPropertyManager*)node->getChild(i) );
|
||||||
|
}
|
||||||
|
if ( node->getChild(i)->isTied() ) {
|
||||||
|
name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
|
||||||
|
node->Untie(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
void FGJSBsim::unbind()
|
||||||
|
{
|
||||||
|
SGPropertyNode* instance = globals->get_props()->getNode("/fdm/jsbsim");
|
||||||
|
checkTied((FGPropertyManager*)instance);
|
||||||
|
FGInterface::unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// Run an iteration of the EOM (equations of motion)
|
// Run an iteration of the EOM (equations of motion)
|
||||||
|
|
||||||
void FGJSBsim::update( double dt )
|
void FGJSBsim::update( double dt )
|
||||||
|
@ -1415,21 +1440,3 @@ void FGJSBsim::update_external_forces(double t_off)
|
||||||
fgSetDouble("/fdm/jsbsim/systems/hook/tailhook-pos-deg", fi);
|
fgSetDouble("/fdm/jsbsim/systems/hook/tailhook-pos-deg", fi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGJSBsim::resetPropertyState()
|
|
||||||
{
|
|
||||||
// this code works-around bug #222:
|
|
||||||
// http://code.google.com/p/flightgear-bugs/issues/detail?id=222
|
|
||||||
// for whatever reason, having an existing value for the WOW
|
|
||||||
// property causes the NaNs. Should that be fixed, this code can die
|
|
||||||
SGPropertyNode* gear = fgGetNode("/fdm/jsbsim/gear", false);
|
|
||||||
if (!gear) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
SGPropertyNode* unitNode = NULL;
|
|
||||||
for (; (unitNode = gear->getChild("unit", index)) != NULL; ++index) {
|
|
||||||
unitNode->removeChild("WOW", 0, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,9 @@ public:
|
||||||
/// Reset flight params to a specific position
|
/// Reset flight params to a specific position
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
/// Unbind properties
|
||||||
|
void unbind();
|
||||||
|
|
||||||
/// @name Position Parameter Set
|
/// @name Position Parameter Set
|
||||||
//@{
|
//@{
|
||||||
/** Set geocentric latitude
|
/** Set geocentric latitude
|
||||||
|
@ -283,8 +286,6 @@ private:
|
||||||
void update_gear(void);
|
void update_gear(void);
|
||||||
|
|
||||||
void update_external_forces(double t_off);
|
void update_external_forces(double t_off);
|
||||||
|
|
||||||
void resetPropertyState();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -307,18 +307,23 @@ bool FGPropulsion::Load(Element* el)
|
||||||
try {
|
try {
|
||||||
if (type == "piston_engine") {
|
if (type == "piston_engine") {
|
||||||
HavePistonEngine = true;
|
HavePistonEngine = true;
|
||||||
|
if (!IsBound) bind();
|
||||||
Engines.push_back(new FGPiston(FDMExec, document, numEngines));
|
Engines.push_back(new FGPiston(FDMExec, document, numEngines));
|
||||||
} else if (type == "turbine_engine") {
|
} else if (type == "turbine_engine") {
|
||||||
HaveTurbineEngine = true;
|
HaveTurbineEngine = true;
|
||||||
|
if (!IsBound) bind();
|
||||||
Engines.push_back(new FGTurbine(FDMExec, document, numEngines));
|
Engines.push_back(new FGTurbine(FDMExec, document, numEngines));
|
||||||
} else if (type == "turboprop_engine") {
|
} else if (type == "turboprop_engine") {
|
||||||
HaveTurboPropEngine = true;
|
HaveTurboPropEngine = true;
|
||||||
|
if (!IsBound) bind();
|
||||||
Engines.push_back(new FGTurboProp(FDMExec, document, numEngines));
|
Engines.push_back(new FGTurboProp(FDMExec, document, numEngines));
|
||||||
} else if (type == "rocket_engine") {
|
} else if (type == "rocket_engine") {
|
||||||
HaveRocketEngine = true;
|
HaveRocketEngine = true;
|
||||||
|
if (!IsBound) bind();
|
||||||
Engines.push_back(new FGRocket(FDMExec, document, numEngines));
|
Engines.push_back(new FGRocket(FDMExec, document, numEngines));
|
||||||
} else if (type == "electric_engine") {
|
} else if (type == "electric_engine") {
|
||||||
HaveElectricEngine = true;
|
HaveElectricEngine = true;
|
||||||
|
if (!IsBound) bind();
|
||||||
Engines.push_back(new FGElectric(FDMExec, document, numEngines));
|
Engines.push_back(new FGElectric(FDMExec, document, numEngines));
|
||||||
} else {
|
} else {
|
||||||
cerr << "Unknown engine type: " << type << endl;
|
cerr << "Unknown engine type: " << type << endl;
|
||||||
|
@ -345,7 +350,6 @@ bool FGPropulsion::Load(Element* el)
|
||||||
if (el->FindElement("dump-rate"))
|
if (el->FindElement("dump-rate"))
|
||||||
DumpRate = el->FindElementValueAsNumberConvertTo("dump-rate", "LBS/MIN");
|
DumpRate = el->FindElementValueAsNumberConvertTo("dump-rate", "LBS/MIN");
|
||||||
|
|
||||||
if (!IsBound) bind();
|
|
||||||
PostLoad(el, PropertyManager);
|
PostLoad(el, PropertyManager);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -642,7 +646,7 @@ void FGPropulsion::bind(void)
|
||||||
typedef int (FGPropulsion::*iPMF)(void) const;
|
typedef int (FGPropulsion::*iPMF)(void) const;
|
||||||
|
|
||||||
IsBound = true;
|
IsBound = true;
|
||||||
PropertyManager->Tie("propulsion/set-running", this, (iPMF)0, &FGPropulsion::InitRunning, true);
|
PropertyManager->Tie("propulsion/set-running", this, (iPMF)0, &FGPropulsion::InitRunning, false);
|
||||||
if (HaveTurbineEngine) {
|
if (HaveTurbineEngine) {
|
||||||
PropertyManager->Tie("propulsion/starter_cmd", this, (iPMF)0, &FGPropulsion::SetStarter, true);
|
PropertyManager->Tie("propulsion/starter_cmd", this, (iPMF)0, &FGPropulsion::SetStarter, true);
|
||||||
PropertyManager->Tie("propulsion/cutoff_cmd", this, (iPMF)0, &FGPropulsion::SetCutoff, true);
|
PropertyManager->Tie("propulsion/cutoff_cmd", this, (iPMF)0, &FGPropulsion::SetCutoff, true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue