Removed FGEngInterface and FGGearInterface after consultation with
FDM people. FlightGear now supports an unlimited number of fuel tanks. Also added correct fuel-flow reporting for piston engines, and tracked new features in SimGear property support.
This commit is contained in:
parent
eedf9f9671
commit
80b4567d54
10 changed files with 138 additions and 492 deletions
|
@ -111,9 +111,6 @@ FGJSBsim::FGJSBsim( double dt )
|
|||
|
||||
int Neng = Propulsion->GetNumEngines();
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, "num engines = " << Neng );
|
||||
for(int i=0;i<Neng;i++) {
|
||||
add_engine( FGEngInterface() );
|
||||
}
|
||||
|
||||
if ( GroundReactions->GetNumGearUnits() <= 0 ) {
|
||||
SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
|
||||
|
@ -250,16 +247,6 @@ FGJSBsim::update( int multiloop ) {
|
|||
needTrim = false;
|
||||
}
|
||||
|
||||
for( i=0; i<get_num_engines(); i++ ) {
|
||||
FGEngInterface * e = get_engine(i);
|
||||
FGEngine * eng = Propulsion->GetEngine(i);
|
||||
FGThruster * thrust = Propulsion->GetThruster(i);
|
||||
eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
|
||||
eng->SetStarter( globals->get_controls()->get_starter(i) );
|
||||
e->set_Throttle( globals->get_controls()->get_throttle(i) );
|
||||
}
|
||||
|
||||
|
||||
for ( i=0; i < multiloop; i++ ) {
|
||||
fdmex->Run();
|
||||
}
|
||||
|
@ -286,24 +273,6 @@ FGJSBsim::update( int multiloop ) {
|
|||
}
|
||||
}
|
||||
|
||||
for( i=0; i<get_num_engines(); i++ ) {
|
||||
FGEngInterface * e = get_engine(i);
|
||||
FGEngine * eng = Propulsion->GetEngine(i);
|
||||
FGThruster * thrust = Propulsion->GetThruster(i);
|
||||
e->set_Manifold_Pressure( eng->getManifoldPressure_inHg() );
|
||||
e->set_RPM( thrust->GetRPM() );
|
||||
e->set_EGT( eng->getExhaustGasTemp_degF() );
|
||||
e->set_CHT( eng->getCylinderHeadTemp_degF() );
|
||||
e->set_Oil_Temp( eng->getOilTemp_degF() );
|
||||
e->set_Running_Flag( eng->GetRunning() );
|
||||
e->set_Cranking_Flag( eng->GetCranking() );
|
||||
}
|
||||
|
||||
|
||||
update_gear();
|
||||
|
||||
stall_warning->setDoubleValue( Aircraft->GetStallWarn() );
|
||||
|
||||
// translate JSBsim back to FG structure so that the
|
||||
// autopilot (and the rest of the sim can use the updated values
|
||||
copy_from_JSBsim();
|
||||
|
@ -314,6 +283,8 @@ FGJSBsim::update( int multiloop ) {
|
|||
// Convert from the FGInterface struct to the JSBsim generic_ struct
|
||||
|
||||
bool FGJSBsim::copy_to_JSBsim() {
|
||||
int i;
|
||||
|
||||
// copy control positions into the JSBsim structure
|
||||
|
||||
FCS->SetDaCmd( globals->get_controls()->get_aileron());
|
||||
|
@ -329,11 +300,15 @@ bool FGJSBsim::copy_to_JSBsim() {
|
|||
FCS->SetRBrake( globals->get_controls()->get_brake( 1 ) );
|
||||
FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
|
||||
FCS->SetGearCmd( globals->get_controls()->get_gear_down());
|
||||
for (int i = 0; i < get_num_engines(); i++) {
|
||||
for (i = 0; i < Propulsion->GetNumEngines(); i++) {
|
||||
FGEngine * eng = Propulsion->GetEngine(i);
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
|
||||
FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
|
||||
FCS->SetPropAdvanceCmd(i, globals->get_controls()->get_prop_advance(i));
|
||||
Propulsion->GetThruster(i)->SetRPM(get_engine(i)->get_RPM());
|
||||
Propulsion->GetThruster(i)->SetRPM(node->getDoubleValue("rpm"));
|
||||
eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
|
||||
eng->SetStarter( globals->get_controls()->get_starter(i) );
|
||||
}
|
||||
|
||||
Position->SetSeaLevelRadius( get_Sea_level_radius() );
|
||||
|
@ -351,6 +326,12 @@ bool FGJSBsim::copy_to_JSBsim() {
|
|||
// << get_V_east_airmass() << ", "
|
||||
// << get_V_down_airmass() );
|
||||
|
||||
for (i = 0; i < Propulsion->GetNumTanks(); i++) {
|
||||
FGTank * tank = Propulsion->GetTank(i);
|
||||
tank->SetContents(fgGetNode("consumables/fuel/tank", i, true)
|
||||
->getDoubleValue());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -455,6 +436,33 @@ bool FGJSBsim::copy_from_JSBsim() {
|
|||
_set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the engine values from JSBSim.
|
||||
for( i=0; i < Propulsion->GetNumEngines(); i++ ) {
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
FGEngine * eng = Propulsion->GetEngine(i);
|
||||
FGThruster * thrust = Propulsion->GetThruster(i);
|
||||
|
||||
node->setDoubleValue("mp-osi", eng->getManifoldPressure_inHg());
|
||||
node->setDoubleValue("rpm", thrust->GetRPM());
|
||||
node->setDoubleValue("egt-degf", eng->getExhaustGasTemp_degF());
|
||||
node->setDoubleValue("fuel-flow-gph", eng->getFuelFlow_gph());
|
||||
node->setDoubleValue("cht-degf", eng->getCylinderHeadTemp_degF());
|
||||
node->setDoubleValue("oil-temperature-degf", eng->getOilTemp_degF());
|
||||
node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
|
||||
node->setBoolValue("running", eng->GetRunning());
|
||||
node->setBoolValue("cranking", eng->GetCranking());
|
||||
}
|
||||
|
||||
// Copy the fuel levels from JSBSim.
|
||||
for (i = 0; i < Propulsion->GetNumTanks(); i++)
|
||||
fgGetNode("consumables/fuel/tank", i, true)
|
||||
->setDoubleValue(Propulsion->GetTank(i)->GetContents());
|
||||
|
||||
update_gear();
|
||||
|
||||
stall_warning->setDoubleValue( Aircraft->GetStallWarn() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -637,38 +645,32 @@ void FGJSBsim::set_Velocities_Local_Airmass (double wnorth,
|
|||
|
||||
void FGJSBsim::init_gear(void ) {
|
||||
|
||||
FGGearInterface *gear;
|
||||
FGGroundReactions* gr=fdmex->GetGroundReactions();
|
||||
int Ngear=GroundReactions->GetNumGearUnits();
|
||||
for (int i=0;i<Ngear;i++) {
|
||||
add_gear_unit( FGGearInterface() );
|
||||
gear=get_gear_unit(i);
|
||||
gear->SetX( gr->GetGearUnit(i)->GetBodyLocation()(1) );
|
||||
gear->SetY( gr->GetGearUnit(i)->GetBodyLocation()(2) );
|
||||
gear->SetZ( gr->GetGearUnit(i)->GetBodyLocation()(3) );
|
||||
gear->SetWoW( gr->GetGearUnit(i)->GetWOW() );
|
||||
if ( gr->GetGearUnit(i)->GetBrakeGroup() > 0 ) {
|
||||
gear->SetBrake(true);
|
||||
}
|
||||
if ( gr->GetGearUnit(i)->GetRetractable() ) {
|
||||
gear->SetPosition( FCS->GetGearPos() );
|
||||
} else {
|
||||
gear->SetPosition( 1.0 );
|
||||
}
|
||||
SGPropertyNode * node = fgGetNode("gear/gear", i, true);
|
||||
node->setDoubleValue("xoffset-in",
|
||||
gr->GetGearUnit(i)->GetBodyLocation()(1));
|
||||
node->setDoubleValue("yoffset-in",
|
||||
gr->GetGearUnit(i)->GetBodyLocation()(2));
|
||||
node->setDoubleValue("zoffset-in",
|
||||
gr->GetGearUnit(i)->GetBodyLocation()(3));
|
||||
node->setBoolValue("wow", gr->GetGearUnit(i)->GetWOW());
|
||||
node->setBoolValue("has-brake", gr->GetGearUnit(i)->GetBrakeGroup() > 0);
|
||||
node->setDoubleValue("position", FCS->GetGearPos());
|
||||
}
|
||||
}
|
||||
|
||||
void FGJSBsim::update_gear(void) {
|
||||
|
||||
FGGearInterface* gear;
|
||||
FGGroundReactions* gr=fdmex->GetGroundReactions();
|
||||
int Ngear=GroundReactions->GetNumGearUnits();
|
||||
for (int i=0;i<Ngear;i++) {
|
||||
gear=get_gear_unit(i);
|
||||
gear->SetWoW( gr->GetGearUnit(i)->GetWOW() );
|
||||
if ( gr->GetGearUnit(i)->GetRetractable() ) {
|
||||
gear->SetPosition( FCS->GetGearPos() );
|
||||
}
|
||||
SGPropertyNode * node = fgGetNode("gear/gear", i, true);
|
||||
node->getChild("wow", 0, true)
|
||||
->setBoolValue(gr->GetGearUnit(i)->GetWOW());
|
||||
node->getChild("position", 0, true)
|
||||
->setDoubleValue(FCS->GetGearPos());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,22 +65,10 @@ FGLaRCsim::FGLaRCsim( double dt ) {
|
|||
eng.init( get_delta_t() );
|
||||
// dcl - in passing dt to init rather than update I am assuming
|
||||
// that the LaRCsim dt is fixed at one value (yes it is 120hz CLO)
|
||||
|
||||
// update the engines interface
|
||||
FGEngInterface e;
|
||||
add_engine( e );
|
||||
|
||||
// Fill the fuel tanks
|
||||
// Hardwired to C172 full tanks for now - need to fix this sometime
|
||||
// Also note that this is the max quantity - the usable quantity
|
||||
// is slightly less
|
||||
set_Tank1Fuel(28.0);
|
||||
set_Tank2Fuel(28.0);
|
||||
}
|
||||
|
||||
FGLaRCsim::~FGLaRCsim(void) {
|
||||
if ( lsic != NULL ) {
|
||||
free_engines();
|
||||
delete lsic;
|
||||
lsic = NULL;
|
||||
}
|
||||
|
@ -117,41 +105,30 @@ void FGLaRCsim::update( int multiloop ) {
|
|||
eng.update();
|
||||
|
||||
// copy engine state values onto "bus"
|
||||
FGEngInterface *e = get_engine( 0 );
|
||||
e->set_Throttle( globals->get_controls()->get_throttle(0) * 100.0 );
|
||||
e->set_Mixture( 80 ); // ???????
|
||||
e->set_Prop_Advance( 100 );
|
||||
e->set_RPM( eng.get_RPM() );
|
||||
e->set_Manifold_Pressure( eng.get_Manifold_Pressure() );
|
||||
e->set_MaxHP( eng.get_MaxHP() );
|
||||
e->set_Percentage_Power( eng.get_Percentage_Power() );
|
||||
e->set_EGT( eng.get_EGT() );
|
||||
e->set_CHT( eng.get_CHT() );
|
||||
e->set_prop_thrust( eng.get_prop_thrust_SI() );
|
||||
e->set_Fuel_Flow( eng.get_fuel_flow_gals_hr() );
|
||||
e->set_Oil_Temp( eng.get_oil_temp() );
|
||||
e->set_Running_Flag( eng.getRunningFlag() );
|
||||
e->set_Cranking_Flag( eng.getCrankingFlag() );
|
||||
fgSetDouble("/engines/engine/rpm", eng.get_RPM());
|
||||
fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure());
|
||||
fgSetDouble("/engines/engine/max-hp", eng.get_MaxHP());
|
||||
fgSetDouble("/engines/engine/power-pct", eng.get_Percentage_Power());
|
||||
fgSetDouble("/engines/engine/egt-degf", eng.get_EGT());
|
||||
fgSetDouble("/engines/engine/cht-degf", eng.get_CHT());
|
||||
fgSetDouble("/engines/engine/prop-thrust", eng.get_prop_thrust_SI());
|
||||
fgSetDouble("/engines/engine/fuel-flow-gph",
|
||||
eng.get_fuel_flow_gals_hr());
|
||||
fgSetDouble("/engines/engine/oil-temperature-degf",
|
||||
eng.get_oil_temp());
|
||||
fgSetDouble("/engines/engine/running", eng.getRunningFlag());
|
||||
fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag());
|
||||
|
||||
//Assume we are using both tanks equally for now
|
||||
reduce_Tank1Fuel( (eng.get_fuel_flow_gals_hr() / (2 * 3600))
|
||||
* get_delta_t() );
|
||||
reduce_Tank2Fuel( (eng.get_fuel_flow_gals_hr() / (2 * 3600))
|
||||
* get_delta_t() );
|
||||
fgSetDouble("/consumables/fuel/tank[0]",
|
||||
fgGetDouble("/consumables/fuel/tank[0]")
|
||||
- (eng.get_fuel_flow_gals_hr() / (2 * 3600))
|
||||
* get_delta_t());
|
||||
fgSetDouble("/consumables/fuel/tank[1]",
|
||||
fgGetDouble("/consumables/fuel/tank[1]")
|
||||
- (eng.get_fuel_flow_gals_hr() / (2 * 3600))
|
||||
* get_delta_t());
|
||||
|
||||
#if 0
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, "Throttle = "
|
||||
<< globals->get_controls()->get_throttle( 0 ) * 100.0);
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, " Mixture = " << 80);
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, " RPM = " << eng.get_RPM());
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, " MP = " << eng.get_Manifold_Pressure());
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, " HP = "
|
||||
<< ( eng.get_MaxHP() * eng.get_Percentage_Power()/ 100.0) );
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, " EGT = " << eng.get_EGT());
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, " Thrust (N) "
|
||||
<< eng.get_prop_thrust_SI()); // Thrust in Newtons
|
||||
SG_LOG( SG_FLIGHT, SG_INFO, '\n');
|
||||
#endif
|
||||
F_X_engine = eng.get_prop_thrust_lbs();
|
||||
// cout << "F_X_engine = " << F_X_engine << '\n';
|
||||
}
|
||||
|
|
|
@ -141,16 +141,14 @@ void YASim::init()
|
|||
int i;
|
||||
for(i=0; i<a->numGear(); i++) {
|
||||
Gear* g = a->getGear(i);
|
||||
FGGearInterface fgg;
|
||||
SGPropertyNode * node = fgGetNode("gear/gear", i, true);
|
||||
float pos[3];
|
||||
g->getPosition(pos);
|
||||
fgg.SetX(pos[0]); fgg.SetY(-pos[1]); fgg.SetZ(-pos[2]);
|
||||
add_gear_unit(fgg);
|
||||
node->setDoubleValue("xoffset-in", pos[0]);
|
||||
node->setDoubleValue("yoffset-in", pos[1]);
|
||||
node->setDoubleValue("zoffset-in", pos[2]);
|
||||
}
|
||||
for(i=0; i<m->numThrusters(); i++) {
|
||||
FGEngInterface fge;
|
||||
add_engine(fge);
|
||||
|
||||
// Sanify the initial input conditions
|
||||
char buf[64];
|
||||
sprintf(buf, "/controls/throttle[%d]", i); fgSetFloat(buf, 0);
|
||||
|
@ -402,43 +400,39 @@ void YASim::copyFromYASim()
|
|||
|
||||
// Fill out our engine and gear objects
|
||||
int i;
|
||||
for(i=0; i<get_num_gear(); i++) {
|
||||
FGGearInterface* fgg = get_gear_unit(i);
|
||||
for(i=0; i<airplane->numGear(); i++) {
|
||||
Gear* g = airplane->getGear(i);
|
||||
if(g->getBrake() != 0)
|
||||
fgg->SetBrake(true);
|
||||
if(g->getCompressFraction() != 0)
|
||||
fgg->SetWoW(true);
|
||||
else
|
||||
fgg->SetWoW(false);
|
||||
fgg->SetPosition(g->getExtension());
|
||||
SGPropertyNode * node = fgGetNode("gear/gear", i, true);
|
||||
node->setBoolValue("has-brake", g->getBrake() != 0);
|
||||
node->setBoolValue("wow", g->getCompressFraction() != 0);
|
||||
node->setBoolValue("position", g->getExtension());
|
||||
}
|
||||
|
||||
for(i=0; i<get_num_engines(); i++) {
|
||||
FGEngInterface* fge = get_engine(i);
|
||||
for(i=0; i<model->numThrusters(); i++) {
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
Thruster* t = model->getThruster(i);
|
||||
|
||||
fge->set_Running_Flag(true);
|
||||
fge->set_Cranking_Flag(false);
|
||||
node->setBoolValue("running", true);
|
||||
node->setBoolValue("cranking", false);
|
||||
|
||||
// Note: assumes all tanks have the same fuel density!
|
||||
fge->set_Fuel_Flow(CM2GALS * t->getFuelFlow()
|
||||
node->setDoubleValue("fuel-flow-gph", CM2GALS * t->getFuelFlow()
|
||||
/ airplane->getFuelDensity(0));
|
||||
|
||||
float tmp[3];
|
||||
t->getThrust(tmp);
|
||||
fge->set_prop_thrust(Math::mag3(tmp) * KG2LBS / 9.8);
|
||||
node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);
|
||||
|
||||
PropEngine* pe = t->getPropEngine();
|
||||
if(pe) {
|
||||
fge->set_RPM(pe->getOmega() * RAD2RPM);
|
||||
node->setDoubleValue("rpm", pe->getOmega() * RAD2RPM);
|
||||
|
||||
pe->getTorque(tmp);
|
||||
float power = Math::mag3(tmp) * pe->getOmega();
|
||||
float maxPower = pe->getPistonEngine()->getMaxPower();
|
||||
|
||||
fge->set_MaxHP(maxPower * W2HP);
|
||||
fge->set_Percentage_Power(100 * power/maxPower);
|
||||
node->setDoubleValue("max-hp", maxPower * W2HP);
|
||||
node->setDoubleValue("power-pct", 100 * power/maxPower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,34 +54,6 @@ inline void init_vec(FG_VECTOR_3 vec) {
|
|||
vec[0] = 0.0; vec[1] = 0.0; vec[2] = 0.0;
|
||||
}
|
||||
|
||||
FGEngInterface::FGEngInterface() {
|
||||
|
||||
// inputs
|
||||
Throttle=0;
|
||||
Mixture=0;
|
||||
Prop_Advance=0;
|
||||
|
||||
// outputs
|
||||
RPM=0;
|
||||
Manifold_Pressure=0;
|
||||
MaxHP=0;
|
||||
Percentage_Power=0;
|
||||
EGT=0;
|
||||
prop_thrust=0;
|
||||
}
|
||||
|
||||
FGEngInterface::~FGEngInterface(void) {
|
||||
}
|
||||
|
||||
FGGearInterface::FGGearInterface(void) {
|
||||
x=y=z=0.0;
|
||||
brake=rolls=WoW=false;
|
||||
position=1.0;
|
||||
}
|
||||
|
||||
FGGearInterface::~FGGearInterface() {
|
||||
}
|
||||
|
||||
// Constructor
|
||||
FGInterface::FGInterface() {
|
||||
_setup();
|
||||
|
@ -386,38 +358,6 @@ FGInterface::bind ()
|
|||
&FGInterface::get_Climb_Rate); // read-only
|
||||
fgTie("/velocities/side-slip-rad", this,
|
||||
&FGInterface::get_Beta); // read-only
|
||||
|
||||
// Powerplant
|
||||
for (int i = 0; i < get_num_engines(); i++) {
|
||||
char buf[64];
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/rpm", i);
|
||||
fgTie(buf, get_engine(i),
|
||||
&FGEngInterface::get_RPM, &FGEngInterface::set_RPM);
|
||||
fgSetArchivable(buf);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/egt-degf", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_EGT);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/cht-degf", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_CHT);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/oil-temperature-degf", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Oil_Temp);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/mp-osi", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Manifold_Pressure);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/fuel-flow-gph", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Fuel_Flow);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/running", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Running_Flag);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/cranking", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Cranking_Flag);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -452,45 +392,6 @@ FGInterface::unbind ()
|
|||
fgUntie("/velocities/wBody-fps");
|
||||
fgUntie("/velocities/vertical-speed-fps");
|
||||
fgUntie("/velocities/side-slip-rad");
|
||||
for (int i = 0; i < get_num_engines(); i++) {
|
||||
char buf[64];
|
||||
sprintf(buf, "/engines/engine[%d]/rpm", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/egt-degf", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/cht-degf", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/oil-temperature-degf", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/mp-osi", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/fuel-flow-gph", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/running", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/cranking", i);
|
||||
fgUntie(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FGInterface::free_engines ()
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i < get_num_engines(); ++i ) {
|
||||
delete get_engine(i);
|
||||
}
|
||||
engines.clear();
|
||||
}
|
||||
|
||||
void
|
||||
FGInterface::free_gear_units ()
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i < get_num_gear(); ++i ) {
|
||||
delete [] get_gear_unit(i);
|
||||
}
|
||||
gear.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,120 +101,6 @@ SG_USING_STD(string);
|
|||
|
||||
typedef double FG_VECTOR_3[3];
|
||||
|
||||
|
||||
class FGEngInterface {
|
||||
|
||||
private:
|
||||
|
||||
// inputs
|
||||
double Throttle;
|
||||
double Mixture;
|
||||
double Prop_Advance;
|
||||
// int Magnetos; // 0=off, 1=left, 2=right, 3=both
|
||||
// bool Starter; // flag to indicate the starter switch is on
|
||||
|
||||
// outputs
|
||||
double RPM;
|
||||
double Manifold_Pressure; //inches
|
||||
double MaxHP;
|
||||
double Percentage_Power; //HP
|
||||
double EGT; //deg F
|
||||
double CHT; //deg F
|
||||
double prop_thrust; //lbs
|
||||
double Fuel_Flow; //Gals/hr
|
||||
double Oil_Temp; //deg F
|
||||
double Oil_Pressure; //PSI
|
||||
bool running; //flag to indicate the engine is running self-sustained
|
||||
bool cranking; //flag to indicate the engine is being turned by the starter
|
||||
|
||||
/* others...
|
||||
double PercentN1,N1; //GE,CFM
|
||||
double PercentN2,N2;
|
||||
double EPR; //P&W, RR?
|
||||
double FuelFlow;
|
||||
bool AfterBurner;
|
||||
double InletAngles[3];
|
||||
double InletPosition[3];
|
||||
double ThrustVector[3];
|
||||
*/
|
||||
|
||||
public:
|
||||
FGEngInterface(void);
|
||||
~FGEngInterface(void);
|
||||
|
||||
inline double get_Throttle() const { return Throttle; }
|
||||
inline double get_Mixture() const { return Mixture; }
|
||||
inline double get_Prop_Advance() const { return Prop_Advance; }
|
||||
inline double get_RPM() const { return RPM; }
|
||||
inline double get_Manifold_Pressure() const { return Manifold_Pressure; }
|
||||
inline double get_MaxHP() const { return MaxHP; }
|
||||
inline double get_Percentage_Power() const { return Percentage_Power; }
|
||||
inline double get_EGT() const { return EGT; }
|
||||
inline double get_CHT() const { return CHT; }
|
||||
inline double get_prop_thrust() const { return prop_thrust; }
|
||||
inline double get_Fuel_Flow() const { return Fuel_Flow; }
|
||||
inline double get_Oil_Temp() const { return Oil_Temp; }
|
||||
inline double get_Oil_Pressure() const { return Oil_Pressure; }
|
||||
inline bool get_Running_Flag() const { return running; }
|
||||
inline bool get_Cranking_Flag() const { return cranking; }
|
||||
|
||||
inline void set_Throttle( double t ) { Throttle = t; }
|
||||
inline void set_Mixture( double m ) { Mixture = m; }
|
||||
inline void set_Prop_Advance( double p ) { Prop_Advance = p; }
|
||||
inline void set_RPM( double r ) { RPM = r; }
|
||||
inline void set_Manifold_Pressure( double mp ) { Manifold_Pressure = mp; }
|
||||
inline void set_MaxHP( double hp ) { MaxHP = hp; }
|
||||
inline void set_Percentage_Power( double p ) { Percentage_Power = p; }
|
||||
inline void set_EGT( double e ) { EGT = e; }
|
||||
inline void set_CHT( double c ) { CHT = c; }
|
||||
inline void set_prop_thrust( double t ) { prop_thrust = t; }
|
||||
inline void set_Fuel_Flow( double f ) { Fuel_Flow = f; }
|
||||
inline void set_Oil_Temp (double o) { Oil_Temp = o; }
|
||||
inline void set_Running_Flag (bool r) { running = r; }
|
||||
inline void set_Cranking_Flag (bool c) { cranking = c; }
|
||||
|
||||
};
|
||||
|
||||
typedef vector < FGEngInterface > engine_list;
|
||||
|
||||
class FGGearInterface {
|
||||
private:
|
||||
|
||||
string name;
|
||||
float x,y,z; // >0 forward of cg, >0 right, >0 down
|
||||
bool brake; // true if this gear unit has a brake mechanism
|
||||
bool rolls; // true if this gear unit has a wheel
|
||||
bool WoW; // true if this gear unit is touching the ground
|
||||
float position; // 0 if retracted, 1 if extended
|
||||
|
||||
public:
|
||||
FGGearInterface(void);
|
||||
~FGGearInterface(void);
|
||||
inline string GetName(void) { return name; }
|
||||
inline void SetName(string nm) { name=nm; }
|
||||
inline float GetX(void) { return x; }
|
||||
inline void SetX(float xloc) { x=xloc; }
|
||||
inline float GetY(void) { return y; }
|
||||
inline void SetY(float yloc) { y=yloc; }
|
||||
inline float GetZ(void) { return z; }
|
||||
inline void SetZ(float zloc) { z=zloc; }
|
||||
inline bool GetBrake(void) { return brake; }
|
||||
inline void SetBrake(bool brk) { brake=brk; }
|
||||
|
||||
// no good way to implement these right now
|
||||
//inline bool GetRolls(void) { return rolls; }
|
||||
//inline SetRolls(bool rl) { rolls=rl; }
|
||||
|
||||
inline bool GetWoW(void) { return WoW; }
|
||||
inline void SetWoW(bool wow) { WoW=wow; }
|
||||
inline float GetPosition(void) { return position; }
|
||||
inline void SetPosition(float pos) { position=pos; }
|
||||
};
|
||||
|
||||
typedef vector < FGGearInterface > gear_list;
|
||||
|
||||
|
||||
|
||||
// This is based heavily on LaRCsim/ls_generic.h
|
||||
class FGInterface : public FGSubsystem {
|
||||
|
||||
|
@ -330,19 +216,11 @@ private:
|
|||
double sin_longitude, cos_longitude;
|
||||
double sin_latitude, cos_latitude;
|
||||
double altitude_agl;
|
||||
double Tank1Fuel; // Gals
|
||||
double Tank2Fuel; // Gals
|
||||
|
||||
double daux[16]; // auxilliary doubles
|
||||
float faux[16]; // auxilliary floats
|
||||
int iaux[16]; // auxilliary ints
|
||||
|
||||
// Engine list
|
||||
engine_list engines;
|
||||
|
||||
//gear list
|
||||
gear_list gear;
|
||||
|
||||
// SGTimeStamp valid_stamp; // time this record is valid
|
||||
// SGTimeStamp next_stamp; // time this record is valid
|
||||
|
||||
|
@ -646,22 +524,6 @@ public:
|
|||
double weast,
|
||||
double wdown );
|
||||
|
||||
// Consumables
|
||||
inline void set_Tank1Fuel( double f ) { Tank1Fuel = f; }
|
||||
inline void set_Tank2Fuel( double f ) { Tank2Fuel = f; }
|
||||
|
||||
inline void reduce_Tank1Fuel( double f ) {
|
||||
Tank1Fuel -= f;
|
||||
if(Tank1Fuel < 0)
|
||||
Tank1Fuel = 0;
|
||||
}
|
||||
inline void reduce_Tank2Fuel( double f ) {
|
||||
Tank2Fuel -= f;
|
||||
if(Tank2Fuel < 0)
|
||||
Tank2Fuel = 0;
|
||||
}
|
||||
|
||||
|
||||
// ========== Mass properties and geometry values ==========
|
||||
|
||||
// Inertias
|
||||
|
@ -1206,40 +1068,6 @@ public:
|
|||
inline float get_faux( int n ) const { return faux[n]; }
|
||||
inline int get_iaux( int n ) const { return iaux[n]; }
|
||||
|
||||
// Consumables
|
||||
inline double get_Tank1Fuel() const { return Tank1Fuel; }
|
||||
inline double get_Tank2Fuel() const { return Tank2Fuel; }
|
||||
|
||||
// engines
|
||||
inline int get_num_engines() const {
|
||||
return engines.size();
|
||||
}
|
||||
|
||||
inline FGEngInterface* get_engine( int i ) {
|
||||
return &engines[i];
|
||||
}
|
||||
|
||||
inline void add_engine( FGEngInterface e ) {
|
||||
engines.push_back( e );
|
||||
}
|
||||
|
||||
void free_engines();
|
||||
|
||||
//gear
|
||||
inline int get_num_gear() const {
|
||||
return gear.size();
|
||||
}
|
||||
|
||||
inline FGGearInterface* get_gear_unit( int i ) {
|
||||
return &gear[i];
|
||||
}
|
||||
|
||||
inline void add_gear_unit( FGGearInterface fgi ) {
|
||||
gear.push_back( fgi );
|
||||
}
|
||||
|
||||
void free_gear_units();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -539,37 +539,6 @@ getHeadingMag ()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the fuel level in tank 1
|
||||
*/
|
||||
static double
|
||||
getTank1Fuel ()
|
||||
{
|
||||
return current_aircraft.fdm_state->get_Tank1Fuel();
|
||||
}
|
||||
|
||||
static void
|
||||
setTank1Fuel ( double gals )
|
||||
{
|
||||
current_aircraft.fdm_state->set_Tank1Fuel( gals );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fuel level in tank 2
|
||||
*/
|
||||
static double
|
||||
getTank2Fuel ()
|
||||
{
|
||||
return current_aircraft.fdm_state->get_Tank2Fuel();
|
||||
}
|
||||
|
||||
static void
|
||||
setTank2Fuel ( double gals )
|
||||
{
|
||||
current_aircraft.fdm_state->set_Tank2Fuel( gals );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the autopilot altitude lock (true=on).
|
||||
*/
|
||||
|
@ -963,31 +932,6 @@ setWindDown (double speed)
|
|||
speed);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the current engine0 running flag.
|
||||
*/
|
||||
static void
|
||||
setRunningFlag (bool flag)
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
current_aircraft.fdm_state->get_engine(0)->set_Running_Flag( flag );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the current engine0 cranking flag.
|
||||
*/
|
||||
//Although there is no real reason to want to tell the engine that it is cranking,
|
||||
//this is currently necessary to avoid the cranking sound being played
|
||||
//before the engine inits.
|
||||
static void
|
||||
setCrankingFlag (bool flag)
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
current_aircraft.fdm_state->get_engine(0)->set_Cranking_Flag( flag );
|
||||
}
|
||||
}
|
||||
|
||||
static double
|
||||
getFOV ()
|
||||
{
|
||||
|
@ -1125,14 +1069,6 @@ fgInitProps ()
|
|||
// Orientation
|
||||
fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
|
||||
|
||||
//consumables
|
||||
fgTie("/consumables/fuel/tank[0]/level-gal_us",
|
||||
getTank1Fuel, setTank1Fuel, false);
|
||||
fgSetArchivable("/consumables/fuel/tank[0]/level-gal_us");
|
||||
fgTie("/consumables/fuel/tank[1]/level-gal_us",
|
||||
getTank2Fuel, setTank2Fuel, false);
|
||||
fgSetArchivable("/consumables/fuel/tank[1]/level-gal_us");
|
||||
|
||||
// Autopilot
|
||||
fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
|
||||
fgSetArchivable("/autopilot/locks/altitude");
|
||||
|
|
|
@ -80,6 +80,27 @@ fgGetNode (const string &path, bool create = false)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a property node with separate index.
|
||||
*
|
||||
* This method separates the index from the path string, to make it
|
||||
* easier to iterate through multiple components without using sprintf
|
||||
* to add indices. For example, fgGetNode("foo[1]/bar", 3) will
|
||||
* return the same result as fgGetNode("foo[1]/bar[3]").
|
||||
*
|
||||
* @param path The path of the node, relative to root.
|
||||
* @param index The index for the last member of the path (overrides
|
||||
* any given in the string).
|
||||
* @param create true to create the node if it doesn't exist.
|
||||
* @return The node, or 0 if none exists and none was created.
|
||||
*/
|
||||
inline SGPropertyNode *
|
||||
fgGetNode (const string &path, int index, bool create = false)
|
||||
{
|
||||
return globals->get_props()->getNode(path, index, create);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test whether a given node exists.
|
||||
*
|
||||
|
|
|
@ -61,11 +61,6 @@ bool FGOpenGC::open() {
|
|||
static void collect_data( const FGInterface *fdm, ogcFGData *data ) {
|
||||
//static void collect_data( ogcFGData *data ) {
|
||||
|
||||
FGEngInterface *p_engine[4]; // four is enough unless you're a BUF
|
||||
|
||||
p_engine[0] = cur_fdm_state->get_engine(0);
|
||||
p_engine[1] = cur_fdm_state->get_engine(1);
|
||||
|
||||
data->version_id = 0x0011;
|
||||
|
||||
data->latitude = fdm->get_Longitude_deg();
|
||||
|
@ -80,17 +75,17 @@ static void collect_data( const FGInterface *fdm, ogcFGData *data ) {
|
|||
|
||||
data->magvar = globals->get_mag()->get_magvar();
|
||||
|
||||
data->rpm[0] = p_engine[0]->get_RPM();
|
||||
data->rpm[1] = p_engine[1]->get_RPM();
|
||||
data->rpm[0] = fgGetDouble("/engines/engine[0]/rpm");
|
||||
data->rpm[1] = fgGetDouble("/engines/engine[1]/rpm");
|
||||
|
||||
data->epr[0] = p_engine[0]->get_Manifold_Pressure();
|
||||
data->epr[1] = p_engine[1]->get_Manifold_Pressure();
|
||||
data->epr[0] = fgGetDouble("/engines/engine[0]/mp-osi");
|
||||
data->epr[1] = fgGetDouble("/engines/engine[1]/mp-osi");
|
||||
|
||||
data->egt[0] = p_engine[0]->get_EGT();
|
||||
data->egt[1] = p_engine[1]->get_EGT();
|
||||
data->egt[0] = fgGetDouble("/engines/engine[0]/egt-degf");
|
||||
data->egt[1] = fgGetDouble("/engines/engine[1]/egt-degf");
|
||||
|
||||
data->oil_pressure[0] = p_engine[0]->get_Oil_Pressure();
|
||||
data->oil_pressure[1] = p_engine[1]->get_Oil_Pressure();
|
||||
data->oil_pressure[0] = fgGetDouble("/engines/engine[0]/oil-pressure-psi");
|
||||
data->oil_pressure[1] = fgGetDouble("/engines/engine[1]/oil-pressure-psi");
|
||||
|
||||
|
||||
// navigation data
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "protocol.hxx"
|
||||
#include "opengc_data.hxx"
|
||||
|
||||
class FGOpenGC : public FGProtocol, public FGInterface, public FGEngInterface {
|
||||
class FGOpenGC : public FGProtocol, public FGInterface {
|
||||
|
||||
ogcFGData buf;
|
||||
int length;
|
||||
|
|
|
@ -192,11 +192,9 @@ FGFX::init ()
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
for (i = 0; i < MAX_ENGINES; i++) {
|
||||
char buf[100];
|
||||
sprintf(buf, "/engines/engine[%d]/running", i);
|
||||
_engine_running_prop[i] = fgGetNode(buf, true);
|
||||
sprintf(buf, "/engines/engine[%d]/cranking", i);
|
||||
_engine_cranking_prop[i] = fgGetNode(buf, true);
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
_engine_running_prop[i] = node->getChild("running", 0, true);
|
||||
_engine_cranking_prop[i] = node->getChild("cranking", 0, true);
|
||||
}
|
||||
_stall_warning_prop = fgGetNode("/sim/aero/alarms/stall-warning", true);
|
||||
_vc_prop = fgGetNode("/velocities/airspeed-kt", true);
|
||||
|
@ -226,16 +224,14 @@ FGFX::update (int dt)
|
|||
|
||||
for (i = 0; i < MAX_ENGINES; i++) {
|
||||
|
||||
if (cur_fdm_state->get_num_engines() > 0 &&
|
||||
_engine_running_prop[i]->getBoolValue()) {
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
|
||||
if (_engine_running_prop[i]->getBoolValue()) {
|
||||
// pitch corresponds to rpm
|
||||
// volume corresponds to manifold pressure
|
||||
|
||||
double rpm_factor;
|
||||
if ( cur_fdm_state->get_num_engines() > 0 )
|
||||
rpm_factor = cur_fdm_state->get_engine(i)->get_RPM() / 2500.0;
|
||||
else
|
||||
rpm_factor = 1.0;
|
||||
rpm_factor = node->getDoubleValue("rpm") / 2500.0;
|
||||
|
||||
double pitch = 0.3 + rpm_factor * 3.0;
|
||||
|
||||
|
@ -247,11 +243,7 @@ FGFX::update (int dt)
|
|||
pitch = 5.0;
|
||||
|
||||
double mp_factor;
|
||||
if ( cur_fdm_state->get_num_engines() > 0 )
|
||||
mp_factor =
|
||||
cur_fdm_state->get_engine(i)->get_Manifold_Pressure() / 100;
|
||||
else
|
||||
mp_factor = 0.3;
|
||||
mp_factor = node->getDoubleValue("mp-osi") / 100;
|
||||
|
||||
double volume = 0.15 + mp_factor / 2.0;
|
||||
|
||||
|
@ -311,7 +303,6 @@ FGFX::update (int dt)
|
|||
// Update the rumble.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
float totalGear = min(cur_fdm_state->get_num_gear(), int(MAX_GEAR));
|
||||
float gearOnGround = 0;
|
||||
|
||||
|
||||
|
@ -324,10 +315,11 @@ FGFX::update (int dt)
|
|||
|
||||
// FIXME: take rotational velocities
|
||||
// into account as well.
|
||||
for (i = 0; i < totalGear; i++) {
|
||||
for (i = 0; i < MAX_GEAR; i++) {
|
||||
SGPropertyNode * node = fgGetNode("gear/gear", i, true);
|
||||
// cout << "air speed = " << cur_fdm_state->get_V_equiv_kts();
|
||||
// cout << " wheel " << i << " speed = " << _wheel_spin[i];
|
||||
if (cur_fdm_state->get_gear_unit(i)->GetWoW()) {
|
||||
if (node->getBoolValue("wow")) {
|
||||
gearOnGround++;
|
||||
if (!_gear_on_ground[i]) {
|
||||
// wheel just touched down
|
||||
|
@ -377,7 +369,7 @@ FGFX::update (int dt)
|
|||
// velocity is under ~0.25 kt.
|
||||
double speed = cur_fdm_state->get_V_equiv_kts();
|
||||
if (gearOnGround > 0 && speed > 0.5) {
|
||||
double volume = 2.0 * (gearOnGround/totalGear) * log(speed)/12; //(speed/60.0);
|
||||
double volume = 2.0 * (gearOnGround/MAX_GEAR) * log(speed)/12; //(speed/60.0);
|
||||
_rumble->set_volume(volume);
|
||||
set_playing("rumble", true);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue