Beispiel #1
0
int JSBSimModel::getEngPLA(LCreal* const pla, const int max) const
{
    if (fdmex == 0) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == 0) return 0;
    JSBSim::FGFCS* FCS = fdmex->GetFCS();
    if (FCS == 0) return 0;

    // return throttle PLA (percent)
    if (pla == 0 || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGEngine* eng = Propulsion->GetEngine(i);
        double t = FCS->GetThrottlePos(i);
        double tmin = eng->GetThrottleMin();
        double tmax = eng->GetThrottleMax();
        double throttle = (t - tmin) / (tmax - tmin) * 100.0;
        pla[i] = (LCreal)throttle;
    }
    return num;
}
Beispiel #2
0
int JSBSimModel::getEngRPM(LCreal* const rpm, const int max) const
{
    if (fdmex == 0) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == 0) return 0;

    if (rpm == 0 || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGEngine* eng = Propulsion->GetEngine(i);
        switch (eng->GetType()) {
        case JSBSim::FGEngine::etPiston:
            {
            JSBSim::FGPiston* eng1 = (JSBSim::FGPiston *) eng;
            rpm[i] = (LCreal)eng1->getRPM();
            }
            break;
        case JSBSim::FGEngine::etElectric:
            {
            JSBSim::FGElectric* eng1 = (JSBSim::FGElectric *) eng;
            rpm[i] = (LCreal)eng1->getRPM();
            }
            break;
        case JSBSim::FGEngine::etTurbine:
            {
            JSBSim::FGTurbine* eng1 = (JSBSim::FGTurbine *) eng;
            rpm[i] = (LCreal)eng1->GetN2();
            }
            break;
        case JSBSim::FGEngine::etTurboprop:
            {
            JSBSim::FGTurboProp* eng1 = (JSBSim::FGTurboProp *) eng;
            rpm[i] = (LCreal)eng1->GetN1();
            }
            break;
        case JSBSim::FGEngine::etRocket:
            rpm[i] = 0.0;
            break;
        default:
            break;
        }
    }
    return num;
}
Beispiel #3
0
int JSBSimModel::getEngOilPressure(LCreal* const oil, const int max) const
{
    if (fdmex == 0) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == 0) return 0;

    // return Engine Oil Pressure
    if (oil == 0 || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGEngine* eng = Propulsion->GetEngine(i);
        switch (eng->GetType()) {
        case JSBSim::FGEngine::etPiston:
            {
            JSBSim::FGPiston* eng1 = (JSBSim::FGPiston *) eng;
            oil[i] = (LCreal)eng1->getOilPressure_psi();
            }
            break;
        case JSBSim::FGEngine::etTurbine:
            {
            JSBSim::FGTurbine* eng1 = (JSBSim::FGTurbine *) eng;
            oil[i] = (LCreal)eng1->getOilPressure_psi();
            }
            break;
        case JSBSim::FGEngine::etTurboprop:
            {
            JSBSim::FGTurboProp* eng1 = (JSBSim::FGTurboProp *) eng;
            oil[i] = (LCreal)eng1->getOilPressure_psi();
            }
            break;
        case JSBSim::FGEngine::etRocket:
        case JSBSim::FGEngine::etElectric:
            oil[i] = 0.0;
            break;
        default:
            break;
        }
    }
    return num;
}
Beispiel #4
0
int JSBSimModel::getEngThrust(LCreal* const fn, const int max) const
{
    if (fdmex == 0) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == 0) return 0;

    if (fn == 0 || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGThruster* thruster = Propulsion->GetEngine(i)->GetThruster();
        fn[i] = (LCreal)thruster->GetThrust();
    }
    return num;
}
Beispiel #5
0
int JSBSimModel::getEngThrust(double* const fn, const int max) const
{
    if (fdmex == nullptr) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == nullptr) return 0;

    if (fn == nullptr || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGThruster* thruster = Propulsion->GetEngine(i)->GetThruster();
        fn[i] = static_cast<double>(thruster->GetThrust());
    }
    return num;
}
Beispiel #6
0
int JSBSimModel::getEngFuelFlow(LCreal* const ff, const int max) const
{
    if (fdmex == 0) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == 0) return 0;

    // Return fuel flow rate lbs/hour
    if (ff == 0 || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGEngine* eng = Propulsion->GetEngine(i);
        ff[i] = (LCreal)eng->getFuelFlow_pph();
    }
    return num;
}
Beispiel #7
0
int JSBSimModel::getEngNozzle(LCreal* const pla, const int max) const
{
    if (fdmex == 0) return 0;
    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    if (Propulsion == 0) return 0;

    // return nozzle position (percentage)
    if (pla == 0 || max <= 0) {
        return 0;
    }
    int num = getNumberOfEngines();
    if (max < num) {
        num = max;
    }
    for (int i = 0; i < num; i++) {
        JSBSim::FGEngine* eng = Propulsion->GetEngine(i);
        switch (eng->GetType()) {
        case JSBSim::FGEngine::etTurbine:
            {
            JSBSim::FGTurbine* eng1 = (JSBSim::FGTurbine *) eng;
            pla[i] = (LCreal)(eng1->GetNozzle() * 100.0);
            }
            break;
        case JSBSim::FGEngine::etTurboprop:
            {
            JSBSim::FGTurboProp* eng1 = (JSBSim::FGTurboProp *) eng;
            pla[i] = (LCreal)(eng1->GetNozzle() * 100.0);
            }
            break;
        case JSBSim::FGEngine::etPiston:
        case JSBSim::FGEngine::etRocket:
        case JSBSim::FGEngine::etElectric:
            pla[i] = 0.0;
            break;
        default:
            break;
        }
    }
    return num;
}
Beispiel #8
0
//------------------------------------------------------------------------------
// reset() -- 
//------------------------------------------------------------------------------
void JSBSimModel::reset()
{
    BaseClass::reset();

    pitchTrimPos  = (LCreal)0.0;
    pitchTrimRate = (LCreal)0.1;
    pitchTrimSw   = (LCreal)0.0;
    rollTrimPos   = (LCreal)0.0;
    rollTrimRate  = (LCreal)0.1;
    rollTrimSw    = (LCreal)0.0;

    // Get our Player (must have one!)
    Simulation::Player* p = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );
    if (p == 0) return;

    // must have strings set
    if (rootDir == 0 || model == 0) return;

    // Must also have the JSBSim object
    if (fdmex == 0) {
        // must have a JSBSim property manager
        if (propMgr == 0) {
            propMgr = new JSBSim::FGPropertyManager();
        }
        fdmex = new JSBSim::FGFDMExec(propMgr);

        std::string RootDir(rootDir->getString());
        fdmex->SetAircraftPath(RootDir + "aircraft");
        fdmex->SetEnginePath(RootDir + "engine");
        fdmex->SetSystemsPath(RootDir + "systems"); // JSBSim-1.0 or after only

        fdmex->LoadModel(model->getString());
        JSBSim::FGPropertyManager* propMgr = fdmex->GetPropertyManager();
        if (propMgr != 0) {
            hasHeadingHold = propMgr->HasNode("ap/heading_hold") && propMgr->HasNode("ap/heading_setpoint");
            hasVelocityHold = propMgr->HasNode("ap/airspeed_hold") && propMgr->HasNode("ap/airspeed_setpoint");
            hasAltitudeHold = propMgr->HasNode("ap/altitude_hold") && propMgr->HasNode("ap/altitude_setpoint");
#if 0
            // CGB this isn't working for some reason. I set the values directly in "dynamics" for now.
            if (hasHeadingHold) {
                propMgr->Tie("ap/heading_hold", this, &JSBSimModel::isHeadingHoldOn);
                propMgr->Tie("ap/heading_setpoint", this, &JSBSimModel::getCommandedHeadingD);
            }
            if (hasVelocityHold) {
                propMgr->Tie("ap/airspeed_hold", this, &JSBSimModel::isVelocityHoldOn);
                propMgr->Tie("ap/airspeed_setpoint", this, &JSBSimModel::getCommandedVelocityKts);
            }
            if (hasAltitudeHold) {
                propMgr->Tie("ap/altitude_hold", this, &JSBSimModel::isAltitudeHoldOn);
                propMgr->Tie("ap/altitude_setpoint", this, &JSBSimModel::getCommandedAltitude * Basic::Distance::M2FT);
            }
#endif
        }
    }
    
#if 0
    // CGB TBD
    reset = 0;
    freeze = 0;
#endif
    JSBSim::FGInitialCondition* fgic = fdmex->GetIC();
    if (fgic == 0) return;

    fgic->SetAltitudeASLFtIC(Basic::Distance::M2FT * p->getAltitude());

#if 0
    fgic->SetTrueHeadingDegIC(Basic::Angle::R2DCC * p->getHeading());
    fgic->SetRollAngleDegIC(Basic::Angle::R2DCC * p->getRoll());
    fgic->SetPitchAngleDegIC(Basic::Angle::R2DCC * p->getPitch());
#else
    fgic->SetPsiDegIC(Basic::Angle::R2DCC * p->getHeading());
    fgic->SetPhiDegIC(Basic::Angle::R2DCC * p->getRoll());
    fgic->SetThetaDegIC(Basic::Angle::R2DCC * p->getPitch());
#endif
    fgic->SetVtrueKtsIC(Basic::Distance::M2NM * p->getTotalVelocity() * 3600.0f);
    fgic->SetLatitudeDegIC(p->getInitLatitude());
    fgic->SetLongitudeDegIC(p->getInitLongitude());

    JSBSim::FGPropulsion* Propulsion = fdmex->GetPropulsion();
    JSBSim::FGFCS* FCS = fdmex->GetFCS();
    if (Propulsion != 0 && FCS != 0) {
        Propulsion->SetMagnetos(3);
        for (unsigned int i=0; i < Propulsion->GetNumEngines(); i++) {
            FCS->SetMixtureCmd(i, 1.0);
            FCS->SetThrottleCmd(i, 1.0);
            FCS->SetPropAdvanceCmd(i, 1.0);
            FCS->SetMixturePos(i, 1.0);
            FCS->SetThrottlePos(i, 1.0);
            FCS->SetPropAdvance(i, 1.0);
            JSBSim::FGEngine* eng = Propulsion->GetEngine(i);
            eng->SetRunning(true);
            JSBSim::FGThruster* thruster = eng->GetThruster();
            thruster->SetRPM(1000.0);
        }
        Propulsion->SetFuelFreeze(p->isFuelFrozen());
        Propulsion->InitRunning(-1);     // -1 refers to "All Engines"
        Propulsion->GetSteadyState();
   }
   fdmex->RunIC();
}