Esempio n. 1
0
//------------------------------------------------------------------------------
// resetButton() - this forces a timer stop, and returns to the center
// button position
//------------------------------------------------------------------------------
void SolenoidSwitch::resetButton()
{
    // timer logic
    if (timer != nullptr) {
        if (currButtonId != CENTER_BUTTON) {
            graphics::Display* myDisplay = (graphics::Display*)findContainerByType(typeid(graphics::Display));
            if (myDisplay != nullptr) {
                //std::cout << "EVENT ID " << eventMap[CENTER_BUTTON-1] << " sent!" << std::endl;
                myDisplay->buttonEvent(eventMap[CENTER_BUTTON-1]);
            }
        }
        currButtonId = CENTER_BUTTON;
        lastButtonId = currButtonId;
        timer->stop();
        for (int i = 0; i < NUM_BUTTONS; i++) picked[i] = false;
        picked[currButtonId-1] = true;
    }
    else {
        if (currButtonId != CENTER_BUTTON) {
            graphics::Display* myDisplay = (graphics::Display*)findContainerByType(typeid(graphics::Display));
            if (myDisplay != nullptr) {
                //std::cout << "EVENT ID " << eventMap[CENTER_BUTTON-1] << " sent!" << std::endl;
                myDisplay->buttonEvent(eventMap[CENTER_BUTTON-1]);
            }
        }
        // we are using logic, don't send a reset, just go back to the center
        currButtonId = CENTER_BUTTON;
        lastButtonId = currButtonId;
        for (int i = 0; i < NUM_BUTTONS; i++) picked[i] = false;
        picked[currButtonId-1] = true;
    }
}
Esempio n. 2
0
//------------------------------------------------------------------------------
// reset() -- Reset parameters
//------------------------------------------------------------------------------
void Datalink::reset()
{
   clearQueues();
   // ---
   // Do we need to find the track manager?
   // ---
   if (getTrackManager() == 0 && getTrackManagerName() != 0) {
        // We have a name of the track manager, but not the track manager itself
        const char* name = *getTrackManagerName();
        // Get the named track manager from the onboard computer
        Player* ownship = dynamic_cast<Player*>( findContainerByType(typeid(Player)) );
        if (ownship != 0) {
            OnboardComputer* obc = ownship->getOnboardComputer();
            if (obc != 0) {
               setTrackManager(obc->getTrackManagerByName(name));
            }
        }    
        if (getTrackManager() == 0) {
            // The assigned track manager was not found!
            //if (isMessageEnabled(MSG_ERROR)) {
            //std::cerr << "Datalink ERROR -- track manager, " << name << ", was not found!" << std::endl;
            //}
        }
   }
   // ---
   // Do we need to find the comm radio?
   // ---
   if (getRadio() == 0 && getRadioName() != 0) {
        // We have a name of the radio, but not the radio itself
        const char* name = *getRadioName();
        // Get the named radio from the component list of radios
        Player* ownship = dynamic_cast<Player*>( findContainerByType(typeid(Player)) );
        if (ownship != 0) {
            CommRadio* cr = dynamic_cast<CommRadio*>(ownship->getRadioByName(name));
            setRadio(cr);
        }
        CommRadio* rad = getRadio();
        if (rad == 0) {
            // The assigned radio was not found!
            if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "Datalink ERROR -- radio, " << name << ", was not found!" << std::endl;
        }
        }
        else {
            rad->setDatalink(this);
            rad->setReceiverEnabledFlag(true);
            rad->setTransmitterEnableFlag(true);
        }
   }
   BaseClass::reset();
}
Esempio n. 3
0
//------------------------------------------------------------------------------
// getRCS() -- Get the RCS
//------------------------------------------------------------------------------
LCreal SigSwitch::getRCS(const Emission* const em)
{
   LCreal rcs = 0.0;

   // Find our ownship player ...
   const Player* ownship = static_cast<const Player*>(findContainerByType(typeid(Player)));
   if (ownship != 0) {

      // get our ownship's camouflage type
      unsigned int camouflage = ownship->getCamouflageType();
      camouflage++; // our components are one based

      // find a RfSignature with this index
      Basic::Pair* pair = findByIndex(camouflage);
      if (pair != 0) {
         RfSignature* sig = dynamic_cast<RfSignature*>( pair->object() );
         if (sig != 0) {

            // OK -- we've found the correct RfSignature subcomponent
            // now let it do all of the work
            rcs = sig->getRCS(em);

         }
      }

   }

   return rcs;
}
Esempio n. 4
0
//------------------------------------------------------------------------------
// latch() - called when our button has been pressed and we either want timing to
// begin or awaiting logical latching.
//------------------------------------------------------------------------------
void SolenoidSwitch::latch(const int buttonId)
{
    // clear out our buttons
    if (buttonId == CENTER_BUTTON) resetButton();
    else {
        if (buttonId != currButtonId) {
            for (int i = 0; i < NUM_BUTTONS; i++) picked[i] = false;
            lastButtonId = currButtonId;
            currButtonId = buttonId;
            picked[currButtonId-1] = true;
            // send the event ID IF we are using LOGIC instead of TIMING
            if (timer == nullptr) {
                if (eventMap[currButtonId-1] != -1) {
                    graphics::Display* myDisplay = (graphics::Display*)findContainerByType(typeid(graphics::Display));
                    if (myDisplay != nullptr) {
                        myDisplay->buttonEvent(eventMap[currButtonId-1]);
                        //std::cout << "EVENT ID " << eventMap[currButtonId-1] << " sent!" << std::endl;
                    }
                }
            }
            // if we are using a timer, restart
            else timer->restart();
        }
    }
}
Esempio n. 5
0
//------------------------------------------------------------------------------
// updateData() - updates the values
//------------------------------------------------------------------------------
void MapPage::updateData(const LCreal dt)
{
   // find our nearest map page above us and get the data from it!
   MapPage* page = static_cast<MapPage*>(findContainerByType(typeid(MapPage)));
   if (page != nullptr) {
      setHeadingDeg(page->getHeadingDeg());
      setDisplacement(page->getDisplacement());
      setReferenceLatDeg(page->getReferenceLatDeg());
      setReferenceLonDeg(page->getReferenceLonDeg());
      setOuterRadius(page->getOuterRadius());
      setOuterRadiusDC(page->getOuterRadiusDC());
      setCentered(page->getCentered());
      setRange(page->getRange());
      setNorthUp(page->getNorthUp());
      nm2Screen = page->getScale();
   }
   // if we are the top map page, we do the calculations ourself
   else {
      // determine if we are centered or not, and set our displacement and radius accordingly
      if (isCentered) nm2Screen = outerRadius / range;
      else nm2Screen = outerRadiusDC / range;
   }

   // update base class stuff
   BaseClass::updateData(dt);
}
//------------------------------------------------------------------------------
// Simulation access functions
//------------------------------------------------------------------------------
Simulation::Station* MapDisplay::getStation()
{
    if (myStation == 0) {
        Simulation::Station* s = dynamic_cast<Simulation::Station*>( findContainerByType(typeid(Simulation::Station)) );
        if (s != 0) myStation = s;
    }
    return myStation;
}
oe::simulation::Station* MapDisplay::getStation()
{
    if (myStation == nullptr) {
        auto s = dynamic_cast<oe::simulation::Station*>( findContainerByType(typeid(oe::simulation::Station)) );
        if (s != nullptr) myStation = s;
    }
    return myStation;
}
Esempio n. 8
0
// find owr ownship
bool System::findOwnship()
{
   if (ownship == 0) {
      ownship = (Player*) findContainerByType( typeid(Player) );
   }

   return (ownship != 0);
}
Esempio n. 9
0
oe::simulation::Station* InstrumentPanel::getStation()
{
   if (myStation == nullptr) {
      oe::simulation::Station* s = dynamic_cast<oe::simulation::Station*>( findContainerByType(typeid(oe::simulation::Station)) );
      if (s != nullptr) myStation = s;
   }
   return myStation;
}
Esempio n. 10
0
//------------------------------------------------------------------------------
// onMouseDown() - when the mouse is pressed
//------------------------------------------------------------------------------
bool SolenoidButton::onMouseDown()
{
    if (!noTimer) {
        // tell our switch to latch
        SolenoidSwitch* hs = (SolenoidSwitch*)findContainerByType(typeid(SolenoidSwitch));
        if (hs != nullptr) hs->latch(getEventId());
    }
    return true;
}
Esempio n. 11
0
//------------------------------------------------------------------------------
// onSingleClick() - override this to talk to our Hold Switch, not our display
//------------------------------------------------------------------------------
bool SolenoidButton::onSingleClick()
{
    if (!noTimer) {
        // if we are timing, we need to tell our switch that it needs to start timing
        SolenoidSwitch* hs = (SolenoidSwitch*)findContainerByType(typeid(SolenoidSwitch));
        if (hs != nullptr) hs->determineLatch();
    }
    return true;
}
Esempio n. 12
0
// Dynamics model interface
bool LaeroModel::setCommandedHeadingD(const double h, const double hDps, const double maxBank)
{
   //-------------------------------------------------------
   // get data pointers
   //-------------------------------------------------------
   Simulation::Player* pPlr = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );

   bool ok = (pPlr != nullptr);
   if (ok) {

      //----------------------------------------------------
      // define local constants
      //----------------------------------------------------
      const double MAX_BANK_RAD = maxBank * Basic::Angle::D2RCC;
      //const double TAU = 2.0;  // time constant [sec]
      const double TAU = 1.0;  // time constant [sec]

      //-------------------------------------------------------
      // get current data
      //-------------------------------------------------------
      double velMps        = pPlr->getTotalVelocity();
      double hdgDeg        = pPlr->getHeadingD();
      double hdgErrDeg     = Basic::Angle::aepcdDeg(h - hdgDeg);
      double hdgErrAbsDeg  = std::fabs(hdgErrDeg);

      //-------------------------------------------------------
      // get absolute heading rate of change (hdgDotAbsDps)
      //-------------------------------------------------------
      double hdgDotMaxAbsRps = Eaagles::ETHGM * std::tan(MAX_BANK_RAD) / velMps;
      double hdgDotMaxAbsDps = hdgDotMaxAbsRps * Basic::Angle::R2DCC;

      double hdgDotAbsDps = hDps;
      if (hdgDotAbsDps > hdgDotMaxAbsDps) {
         hdgDotAbsDps = hdgDotMaxAbsDps;
      }

      double hdgErrBrkAbsDeg = TAU * hdgDotAbsDps;
      if (hdgErrAbsDeg < hdgErrBrkAbsDeg) {
         hdgDotAbsDps = hdgErrAbsDeg / TAU;
      }

      //-------------------------------------------------------
      // define direction of heading rate of change (hdgDotDps)
      //-------------------------------------------------------
      double hdgDotDps = sign(hdgErrDeg) * hdgDotAbsDps;
      psiDot = hdgDotDps * Basic::Angle::D2RCC;

      //-------------------------------------------------------
      // define bank angle as a function of turn rate
      //-------------------------------------------------------
      double phiCmdDeg = std::atan2(psiDot * velMps, Eaagles::ETHGM) * Basic::Angle::R2DCC;
      ok = flyPhi(phiCmdDeg);
   }

   return ok;
}
Esempio n. 13
0
//------------------------------------------------------------------------------
// Simulation access functions
//------------------------------------------------------------------------------
Simulation::Station* AdiDisplay::getStation()
{
   if (myStation == nullptr) {
      Simulation::Station* s = dynamic_cast<Simulation::Station*>( findContainerByType(typeid(Simulation::Station)) );
      if (s != nullptr) {
         myStation = s;
      }
   }
   return myStation;
}
Station* MultiActorAgent::getStation()
{
   if ( myStation == nullptr ) {
      Station* s = dynamic_cast<Station*>(findContainerByType(typeid(Station)));
      if (s != nullptr) {
         myStation = s;
      }
   }
   return myStation;
}
Esempio n. 15
0
// Find our parent Station
Station* DataRecorder::getStationImp()
{
   if (sta == nullptr) {
      sta = static_cast<Station*>(findContainerByType(typeid(Station)));
      if (sta == nullptr && isMessageEnabled(MSG_ERROR)) {
         std::cerr << "Datarecorder::getStationImp(): ERROR, unable to locate the Station class!" << std::endl;
      }
   }
   return sta;
}
Esempio n. 16
0
//------------------------------------------------------------------------------
// updateData() -- update Non-time critical stuff here
//------------------------------------------------------------------------------
void Route::updateData(const LCreal dt)
{
   BaseClass::updateData(dt);

   const Navigation* nav = static_cast<const Navigation*>(findContainerByType(typeid(Navigation)));
   if (nav != nullptr) {
      computeSteerpointData(dt,nav);
      autoSequencer(dt,nav);
   }
}
Esempio n. 17
0
//----------------------------------------------------------
// reset() -- sets up our initial flying values
//----------------------------------------------------------
void LaeroModel::reset()
{
   BaseClass::reset();

   Simulation::Player* pPlr = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );
   if (pPlr != nullptr) {
      LCreal initVel = pPlr->getInitVelocity();
      u = initVel * Basic::Distance::NM2M / Basic::Time::H2S;
   }
}
Esempio n. 18
0
void MapDrawer::updateData(const LCreal dt)
{
    // Update our baseclass
    BaseClass::updateData(dt);

    // Set our map if we don't have one
    if (myMap == 0) {
        CadrgMap* map = dynamic_cast<CadrgMap*>(findContainerByType(typeid(CadrgMap)));
        if (map != 0) setMap(map);
    }
}
Esempio n. 19
0
// Returns the path to the datafiles
const char* Terrain::getPathname() const
{
   const char* p = nullptr;
   if (path != nullptr) {
      // Our path
      p = *path;
   } else {
      // See if we have a contain "Terrain" object that has a path set
      const Terrain* q = static_cast<const Terrain*>(findContainerByType(typeid(Terrain)));
      if (q != nullptr) p = q->getPathname();
   }
   return p;
}
Esempio n. 20
0
// Returns the path to the datafiles
const char* Terrain::getPathname() const
{
   const char* p = 0;
   if (path != 0) {
      // Our path
      p = *path;
   }
   else {
      // See if we have a contain "Terrain" object that has a path set
      const Terrain* q = (const Terrain*) findContainerByType(typeid(Terrain));
      if (q != 0) p = q->getPathname();
   }
   return p;
}
Esempio n. 21
0
//------------------------------------------------------------------------------
// onSingleClick() - tells us we have been clicked, and we can override this
// to make it do whatever we want.
//------------------------------------------------------------------------------
bool Button::onSingleClick()
{
    // when I am clicked, I will send an event to my container, we find out what
    // event Id we have, and send that eventId
    bool ok = false;
    graphics::Display* myDisplay = (graphics::Display*)findContainerByType(typeid(graphics::Display));

    if (myDisplay != nullptr) {
        myDisplay->buttonEvent(getEventId());
        ok = true;
    }

    return ok;
}
Esempio n. 22
0
//------------------------------------------------------------------------------
// trigger the 'to' steerpoint's action (if any)
//------------------------------------------------------------------------------
void Route::triggerAction()
{
   // ---
   // find and start the current 'to' steerpoint action
   // ---
   Player* own = static_cast<Player*>(findContainerByType(typeid(Player)));
   if (to != nullptr && own != nullptr) {
      Steerpoint* toSP = static_cast<Steerpoint*>(to->object());
      Action* toAction = toSP->getAction();
      if (toAction != nullptr) {
         OnboardComputer* obc = own->getOnboardComputer();
         if (obc != nullptr) obc->triggerAction(toAction);
      }
   }
}
Esempio n. 23
0
// setCommandedVelocityKts() - also can limit velocity rate of acceleration
bool LaeroModel::setCommandedVelocityKts(const double v, const double vNps)
{
   //-------------------------------------------------------
   // get data pointers
   //-------------------------------------------------------
   Simulation::Player* pPlr = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );
   bool ok = (pPlr != nullptr);
   if (ok) {

      //-------------------------------------------------------
      // define local constants
      //-------------------------------------------------------
      const double KTS2MPS = Basic::Distance::NM2M / Basic::Time::H2S;

      //-------------------------------------------------------
      // convert argument units (deg -> rad)
      //-------------------------------------------------------
      double velCmdMps     = v * KTS2MPS;
      double velDotCmdMps2 = vNps * KTS2MPS;

      //-------------------------------------------------------
      // current vel error (rad)
      //-------------------------------------------------------
      double velMps    = pPlr->getTotalVelocityKts() * KTS2MPS;
      double velErrMps = velCmdMps - velMps;

      //-------------------------------------------------------
      // vel error break point (rad)
      //-------------------------------------------------------
      const double TAU = 1.0;  // time constant [sec]
      double velErrBrkMps = velDotCmdMps2 * TAU;

      //-------------------------------------------------------
      // control signal for commanded vel (rps)
      //-------------------------------------------------------
      double velDotMps2 = sign(velErrMps) * velDotCmdMps2;
      if (std::abs(velErrMps) < velErrBrkMps) {
         velDotMps2 = (velErrMps / velErrBrkMps) * velDotCmdMps2;
      }

      //-------------------------------------------------------
      // assign result to velocity control
      //-------------------------------------------------------
      uDot = velDotMps2;
   }

   return true;
}
Esempio n. 24
0
// Dynamics model interface - all input values in meters
bool LaeroModel::setCommandedAltitude(const double a, const double aMps, const double maxPitch)
{
   //-------------------------------------------------------
   // get data pointers
   //-------------------------------------------------------
   Simulation::Player* pPlr = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );

   bool ok = (pPlr != nullptr);
   if (ok) {

      //-------------------------------------------------------
      // define local constants
      //-------------------------------------------------------
      const double TAU            = 4.0;  // time constant [sec]

      //-------------------------------------------------------
      // get current alt error (mtr)
      //-------------------------------------------------------
      double altMtr     = pPlr->getAltitude();
      double altErrMtr = a - altMtr;

      //-------------------------------------------------------
      // get alt error break point (mtr)
      //-------------------------------------------------------
      double altDotCmdMps = aMps;
      double altErrBrkMtr = altDotCmdMps * TAU;

      //-------------------------------------------------------
      // get commanded altDot (mps)
      //-------------------------------------------------------
      double altDotMps = sign(altErrMtr) * altDotCmdMps;
      if (std::abs(altErrMtr) < altErrBrkMtr) {
         altDotMps = altErrMtr * (altDotCmdMps / altErrBrkMtr);
      }

      //-------------------------------------------------------
      // assign result to altitude control
      //-------------------------------------------------------
      double thtCmdDeg = (altDotMps / u) * Basic::Angle::R2DCC;
      // SLS - TO DO: Limit commanded pitch to max pitch angle as well.
      ok = flyTht(thtCmdDeg);
   }

   return ok;
}
Esempio n. 25
0
bool LaeroModel::flyTht(const double thtCmdDeg, const double thtDotCmdDps)
{
   //-------------------------------------------------------
   // get data pointers
   //-------------------------------------------------------
   Simulation::Player* pPlr = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );
   bool ok = (pPlr != nullptr);
   if (ok) {

      //-------------------------------------------------------
      // convert argument units (deg -> rad)
      //-------------------------------------------------------
      double thtCmdRad    = thtCmdDeg * Basic::Angle::D2RCC;
      double thtDotCmdRps = thtDotCmdDps * Basic::Angle::D2RCC;

      //-------------------------------------------------------
      // current tht error (rad)
      //-------------------------------------------------------
      double thtRad    = pPlr->getPitchR();
      double thtErrRad = thtCmdRad - thtRad;

      //-------------------------------------------------------
      // tht error break point (rad)
      //-------------------------------------------------------
      const double TAU = 1.0;  // time constant [sec]
      double thtErrBrkRad = thtDotCmdRps * TAU;

      //-------------------------------------------------------
      // control signal for commanded tht (rps)
      //-------------------------------------------------------
      double thtDotRps = sign(thtErrRad) * thtDotCmdRps;
      if (std::abs(thtErrRad) < thtErrBrkRad) {
         thtDotRps = (thtErrRad / thtErrBrkRad) * thtDotCmdRps;
      }

      //-------------------------------------------------------
      // assign result to pitch control
      //-------------------------------------------------------
      thtDot = thtDotRps;
   }

   return ok;
}
Esempio n. 26
0
bool LaeroModel::flyPsi(const double psiCmdDeg, const double psiDotCmdDps)
{
   //-------------------------------------------------------
   // get data pointers
   //-------------------------------------------------------
   Simulation::Player* pPlr = static_cast<Simulation::Player*>( findContainerByType(typeid(Simulation::Player)) );
   bool ok = (pPlr != nullptr);
   if (ok) {

      //-------------------------------------------------------
      // convert argument units (deg -> rad)
      //-------------------------------------------------------
      double psiCmdRad    = psiCmdDeg * Basic::Angle::D2RCC;
      double psiDotCmdRps = psiDotCmdDps * Basic::Angle::D2RCC;

      //-------------------------------------------------------
      // current psi error (rad)
      //-------------------------------------------------------
      double psiRad    = pPlr->getHeadingR();
      double psiErrRad = psiCmdRad - psiRad;

      //-------------------------------------------------------
      // psi error break point (rad)
      //-------------------------------------------------------
      const double TAU = 1.0;  // time constant [sec]
      double psiErrBrkRad = psiDotCmdRps * TAU;

      //-------------------------------------------------------
      // control signal for commanded psi (rps)
      //-------------------------------------------------------
      double psiDotRps = sign(psiErrRad) * psiDotCmdRps;
      if (std::abs(psiErrRad) < psiErrBrkRad) {
         psiDotRps = (psiErrRad / psiErrBrkRad) * psiDotCmdRps;
      }

      //-------------------------------------------------------
      // assign result to azimuth control
      //-------------------------------------------------------
      psiDot = psiDotRps;
   }

   return ok;
}
Esempio n. 27
0
//------------------------------------------------------------------------------
// setMode() -- set the mode of the field (display, input)
//------------------------------------------------------------------------------
Field::Mode Field::setMode(const Field::Mode nmode)
{
    Mode omode = mode;
    mode = nmode;

    if (nmode == input && omode == display) {

        // When we're entering the INPUT mode ...

        // Change the input focus to this field
        getDisplay()->focus(this);

        // Set the input chararcter pointer to the first character
        if (startCP > 0 && startCP < w) icp = startCP;
        else icp = 0;

    }
    else if (nmode == display && omode == input) {

        // When we're leaving the INPUT mode ...

        // Change the input focus to our container page (Page)
        if (getDisplay()->focus() == this) {
            Page* page = (Page*) findContainerByType(typeid(Page));
            if (page != 0)
                getDisplay()->focus(page);
            else
                getDisplay()->focus(0);

            // Reset text string
            adjust();

        }
    }


    return omode;
} 
Esempio n. 28
0
//------------------------------------------------------------------------------
// updateData() - background thread
//------------------------------------------------------------------------------
void SolenoidSwitch::updateData(const double dt)
{
    BaseClass::updateData(dt);

    // timer latching
    if (timer != nullptr && timer->alarm()) {
        for (int i = 0; i < NUM_BUTTONS; i++) picked[i] = false;
        lastButtonId = currButtonId;
        picked[currButtonId-1] = true;
        timer->stop();
        if (eventMap[currButtonId-1] != -1) {
            graphics::Display* myDisplay = (graphics::Display*)findContainerByType(typeid(graphics::Display));
            if (myDisplay != nullptr) {
                myDisplay->buttonEvent(eventMap[currButtonId-1]);
                //std::cout << "TIMER EVENT ID " << eventMap[currButtonId-1] << " sent!" << std::endl;
            }
        }
        timer->stop();
        timer->reset();
    }

    // tell our buttons what position they have
    send("button%d", USER_KEY_EVENT, picked, pickedSD, NUM_BUTTONS);
}
Esempio n. 29
0
  //------------------------------------------------------------------------------
  // Handle input devices
  //------------------------------------------------------------------------------
  void IoHandler::inputDevices(const LCreal dt) {
     BaseClass::inputDevices(dt);
     // ---
     // get the Input data buffer
     // ---
     const Basic::IoData* const inData = getInputData();
     // ---
     // get the Station, Simulation and our ownship player
     // ---
     SimStation* const sta = static_cast<SimStation*>( findContainerByType(typeid(SimStation)) );
     Simulation::Simulation* sim = 0;
     Simulation::AirVehicle* av = 0;

     if (sta != 0) {
        sim = sta->getSimulation();
        av = dynamic_cast<Simulation::AirVehicle*>(sta->getOwnship());
     }

     // ---
     // If we have everything we need ....
     // ---
     if (av != 0 && sim != 0 && inData != 0) {

        // find the (optional) autopilot
        Simulation::Autopilot* ap = 0;
        {
           Basic::Pair* p = av->getPilotByType( typeid( Simulation::Autopilot) );
           if (p != 0) ap = static_cast<Simulation::Autopilot*>( p->object() );
        }

        // ------------------------------------------------------------
        // Simulation Control Inputs
        // ------------------------------------------------------------

        {
           bool enabled = false;
           inData->getDiscreteInput(CTL_ENABLE_SW, &enabled);

           {  // Toggle simulation freeze
              bool sw = false;
              inData->getDiscreteInput(FREEZE_SW, &sw);
              bool frzSw = sw && enabled;
              if (frzSw && !frzSw1) {
                 Basic::Boolean newFrz( !sim->isFrozen() );
                 sim->event(FREEZE_EVENT, &newFrz);
              }
              frzSw1 = frzSw;
           }

           {  // Send a reset pulse to the station
              bool sw = false;
              inData->getDiscreteInput(RESET_SW, &sw);
              bool rstSw = sw && enabled;
              if (rstSw && !rstSw1) {
                 sta->event(RESET_EVENT);
              }
              rstSw1 = rstSw;
           }

           {  // Send a weapons reload pulse to the station
              bool sw = false;
              inData->getDiscreteInput(RELOAD_SW, &sw);
              bool wpnReloadSw = sw && enabled;
              if (wpnReloadSw && !wpnReloadSw1) {
                 sta->event(WPN_RELOAD);
              }
              wpnReloadSw1 = wpnReloadSw;
           }
        }

        // ------------------------------------------------------------
        // Flight Control Inputs
        // ------------------------------------------------------------

        {  // Process Roll Input
           LCreal ai = 0;
           inData->getAnalogInput(ROLL_AI, &ai);
           LCreal aiLim = alim(ai, 1.0f);
           if (ap != 0) ap->setControlStickRollInput(aiLim);
           else av->setControlStickRollInput(aiLim);
        }

        {  // Process Pitch Input
           LCreal ai = 0;
           inData->getAnalogInput(PITCH_AI, &ai);
           LCreal aiLim = alim(ai, 1.0f);
           if (ap != 0) ap->setControlStickPitchInput(aiLim);
           else av->setControlStickPitchInput(aiLim);
        }

        {  // Process Rudder Input
           LCreal ai = 0;
           inData->getAnalogInput(RUDDER_AI, &ai);
           LCreal aiLim = alim(ai, 1.0f);
           av->setRudderPedalInput(aiLim);
        }

        {  // Process Throttle Input
           LCreal value = 0;
           inData->getAnalogInput(THROTTLE_AI, &value);

           if (value < 0.0f) value = 0.0f;
           else if (value > 2.0f) value = 2.0f;

           if (ap != 0) ap->setThrottles(&value,1);
           else av->setThrottles(&value,1);
        }

        { // Weapons Release
           bool sw = false;
           inData->getDiscreteInput(PICKLE_SW, &sw);
           if (sw != wpnRelSw1) {
              Basic::Boolean sw(sw);
              av->event(WPN_REL_EVENT, &sw);
           }
           wpnRelSw1 = sw;
        }

        { // Trigger switch
           bool sw = false;
           inData->getDiscreteInput(TRIGGER_SW2, &sw);
           if (sw != trgSw1) {
              Basic::Boolean sw(sw);
              av->event(TRIGGER_SW_EVENT, &sw);
           }
           trgSw1 = sw;
        }

        { // Target Step (reject)
           bool sw = false;
           inData->getDiscreteInput(TMS_RIGHT_SW, &sw);
           if (sw && !tgtStepSw1) {
              av->event(TGT_STEP_EVENT);
           }
           tgtStepSw1 = sw;
        }

        { // Target Designate
           bool sw = false;
           inData->getDiscreteInput(TMS_UP_SW, &sw);
           if (sw && !tgtDesSw1) {
              av->event(TGT_DESIGNATE);
           }
           tgtDesSw1 = sw;
        }

        { // Return-To-Search
           bool sw = false;
           inData->getDiscreteInput(TMS_DOWN_SW, &sw);
           if (sw && !rtn2SrchSw1) {
              av->event(SENSOR_RTS);
           }
           rtn2SrchSw1 = sw;
        }

        { // Autopilot disengage
           bool autopilotSw = false;
           inData->getDiscreteInput(PADDLE_SW, &autopilotSw);
           if (autopilotSw && !autopilotSw1) {
              Simulation::Autopilot* ap = dynamic_cast<Simulation::Autopilot*>(av->getPilot());
              if (ap != 0) {
                 ap->setHeadingHoldMode(false);
                 ap->setAltitudeHoldMode(false);
                 ap->setVelocityHoldMode(false);
                 ap->setLoiterMode(false);
                 ap->setNavMode(false);
              }
           }
           autopilotSw1 = autopilotSw;
        }

        { // Speedbrake switch  
           bool sbExtSw = false;
           bool sbRetSw = false;
           inData->getDiscreteInput(SB_EXT_SW, &sbExtSw);
           inData->getDiscreteInput(SB_RET_SW, &sbRetSw);

           LCreal sb = 0.0;
           if(sbExtSw) sb = -1.0f;
           if(sbRetSw) sb =  1.0f;
           av->setSpeedBrakesSwitch(sb);
        }

        { // Steerpoint increment
           bool incStptSw = false;
           inData->getDiscreteInput(DMS_UP_SW, &incStptSw);
           if(incStptSw && !incStptSw1) {
              // find our route and increment the steerpoint
              Simulation::Navigation* myNav = av->getNavigation();
              if (myNav != 0) {
                 myNav->ref();
                 Simulation::Route* myRoute = myNav->getPriRoute();
                 if (myRoute != 0) {
                    myRoute->ref();
                    myRoute->incStpt();
                    myRoute->unref();
                 }
              }
           }
           incStptSw1 = incStptSw;
        }

        { // Steerpoint decrement
           bool decStptSw = false;
           inData->getDiscreteInput(DMS_DOWN_SW, &decStptSw);
           if (decStptSw && !decStptSw1) {
              // find our route and increment the steerpoint
              Simulation::Navigation* myNav = av->getNavigation();
              if (myNav != 0) {
                 myNav->ref();
                 Simulation::Route* myRoute = myNav->getPriRoute();
                 if (myRoute != 0) {
                    myRoute->ref();
                    myRoute->decStpt();
                    myRoute->unref();
                 }
              }
           }
           decStptSw1 = decStptSw;
        }
     }
  }
Esempio n. 30
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();
}