void RfSystem::reset() { BaseClass::reset(); // --- // Do we need to find the antenna? // --- if (getAntenna() == 0 && getAntennaName() != 0 && getOwnship() != 0) { // We have a name of the antenna, but not the antenna it's self const char* name = *getAntennaName(); // Get the named antenna from the player's list of gimbals, antennas and optics Antenna* p = dynamic_cast<Antenna*>( getOwnship()->getGimbalByName(name) ); if (p != 0) { setAntenna( p ); getAntenna()->setSystem(this); } if (getAntenna() == 0) { // The assigned antenna was not found! std::cerr << "RfSystem::reset() ERROR -- antenna: " << name << ", was not found!" << std::endl; setSlotAntennaName(0); } } // --- // Initialize players of interest // --- processPlayersOfInterest(); }
//------------------------------------------------------------------------------ // queueIncomingMessage() -- Queue up an incoming message //------------------------------------------------------------------------------ bool Datalink::queueIncomingMessage(Basic::Object* const msg) { // Only queue message if Ownship is local. IPlayer messages are processed on their local systems if ((getOwnship() == 0) || !(getOwnship()->isLocalPlayer())) { return true; } //if (isMessageEnabled(MSG_INFO)) { //std::cout << getOwnship()->getID() << "\tincomming QQueue Size: " << inQueue->entries() << std::endl; //} if(inQueue->isFull()) { if (isMessageEnabled(MSG_WARNING)) { std::cerr << "dumping 10 oldest messages in Datalink::inQueue" << std::endl; } for(int i = 0; i < 10; i++) { Basic::Object* obj = inQueue->get(); obj->unref(); } //clear out 10 oldest messages } if (msg != 0) { msg->ref(); inQueue->put(msg); } return true; }
//------------------------------------------------------------------------------ // reset() -- Reset parameters //------------------------------------------------------------------------------ void RfSensor::reset() { BaseClass::reset(); // --- // Do we need to find the track manager? // --- if (getTrackManager() == 0 && getTrackManagerName() != 0 && getOwnship() != 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 OnboardComputer* obc = getOwnship()->getOnboardComputer(); if (obc != 0) { setTrackManager( obc->getTrackManagerByName(name) ); } if (getTrackManager() == 0) { // The assigned track manager was not found! std::cerr << "RfSensor::reset() ERROR -- track manager, " << name << ", was not found!" << std::endl; setTrackManagerName(0); } } scanning = false; scanBar = 0; if (nRanges > 0 && ranges != 0) { rngIdx = 1; if (initRngIdx >= 1 && initRngIdx <= nRanges) { rngIdx = initRngIdx; } setRange( ranges[rngIdx-1] ); } }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void IrSensor::updateData(const double dt) { BaseClass::updateData(dt); // --- // Do we need to find the track manager? // --- if (getTrackManager() == nullptr && getTrackManagerName() != nullptr && getOwnship() != nullptr) { // 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 OnboardComputer* obc = getOwnship()->getOnboardComputer(); if (obc != nullptr) { setTrackManager( obc->getTrackManagerByName(name) ); } if (getTrackManager() == nullptr) { // The assigned track manager was not found! if (isMessageEnabled(MSG_ERROR)) { std::cerr << "IrSensor::reset() ERROR -- track manager, " << name << ", was not found!" << std::endl; } setTrackManagerName(nullptr); } } }
//------------------------------------------------------------------------------ // updateData() -- update non-time critical stuff here //------------------------------------------------------------------------------ void TestDisplay::updateData(const double dt) { // Send flight data to readouts if (getOwnship() != nullptr) { send("hsi", UPDATE_VALUE5, getOwnship()->getHeadingR(), headingSD); send("rangeRO", UPDATE_VALUE, range, rangeSD); // Maintain Air Tracks oe::base::Pair* pair = findByName("airTracks"); if (pair != nullptr) { oe::graphics::SymbolLoader* myLoader = dynamic_cast<oe::graphics::SymbolLoader*>(pair->object()); if (myLoader != nullptr) { myLoader->setRange(range); myLoader->setHeadingDeg(getOwnship()->getHeadingD()); myLoader->setNorthUp(false); maintainAirTrackSymbols(myLoader, range); } } } // Update base classes stuff BaseClass::updateData(dt); }
// (default) System attitude function (using truth data from ownship) bool Navigation::updateSysAttitude() { bool ok = false; if (getOwnship() != 0) { setAttitude(getOwnship()->getRollD(), getOwnship()->getPitchD(), getOwnship()->getHeadingD()); ok = true; } return ok; }
// Weapon Release Switch bool TestDisplay::onWpnRelKey() { if (getOwnship() != nullptr) { oe::simulation::StoresMgr* sms = getOwnship()->getStoresManagement(); if (sms != nullptr) { sms->setWeaponDeliveryMode(oe::simulation::StoresMgr::A2A); getOwnship()->event(WPN_REL_EVENT); } } return true; }
// (default) System position (using truth data from ownship) bool Navigation::updateSysPosition() { bool ok = false; if (getOwnship() != 0) { // -- convert ownship's position vector to lat/lon/alt double lat0 = 0; double lon0 = 0; double alt0 = 0; ok = Basic::Nav::convertPosVec2LL(refLat, refLon, getOwnship()->getPosition(), &lat0, &lon0, &alt0); setPosition(lat0, lon0, alt0); } return ok; }
// Pre-Release Switch bool TestDisplay::onPreRelKey() { if (getOwnship() != nullptr) { oe::simulation::StoresMgr* sms = getOwnship()->getStoresManagement(); if (sms != nullptr) { sms->setWeaponDeliveryMode(oe::simulation::StoresMgr::A2A); oe::simulation::Weapon* wpn = sms->getCurrentWeapon(); if (wpn != nullptr) { wpn->prerelease(); std::cout << "Prelaunched wpn = " << wpn << std::endl; } } } return true; }
//------------------------------------------------------------------------------ // reset() -- Reset parameters //------------------------------------------------------------------------------ void System::reset() { // We're nothing without an ownship ... if (ownship == 0 && getOwnship() == 0) return; BaseClass::reset(); }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void IlsRadio::updateData(const LCreal dt) { //Must have ownship if (getOwnship() == 0) return; // Set our position to that of our ownship vehicle setPosition(); //Do not update data every time...Hard code delay length... if(timerCounter==0){ //Get Glideslope and Runway orientation: glideSlopeValid = findILSGlideslopeByFreq(getFrequency()); localizerValid = findLocalizerByFreq(getFrequency()); //Get test results - make sure dest LL do not change as plane flies Basic::Nav::gbd2ll(getLatitude(),getLongitude(),bearing,grdrange,&destLatitude,&destLongitude); //Test for bad result... if((glideSlopeValid==false)|(localizerValid==false)){ //std::cerr << "No ILS In Range..." << std::endl; } } else if(timerCounter==30){ timerCounter=0; //Make sure the lookup occurs on the next cycle } else{ timerCounter++; //Do not do another DB lookup - wait for some time } BaseClass::updateData(dt); }
//------------------------------------------------------------------------------ // transmitDataMessage() -- send a data message emission; // returns true if the data emission was sent. //------------------------------------------------------------------------------ bool CommRadio::transmitDataMessage(base::Object* const msg) { bool sent = false; // Transmitting, scanning and have an antenna? if(getOwnship() == nullptr) { if (isMessageEnabled(MSG_DEBUG)) { std::cout << "CommRadio ownship == nullptr!" << std::endl; } return sent; } if (msg != nullptr && isTransmitterEnabled() && getAntenna() != nullptr) { // Send the emission to the other player Emission* em = new Emission(); em->setDataMessage(msg); em->setFrequency(getFrequency()); em->setBandwidth(getBandwidth()); em->setPower(getPeakPower()); em->setTransmitLoss(getRfTransmitLoss()); em->setMaxRangeNM(getMaxDetectRange()); em->setTransmitter(this); em->setReturnRequest(false); getAntenna()->rfTransmit(em); em->unref(); sent = true; } return sent; }
//------------------------------------------------------------------------------ // stepOwnshipPlayer() -- Step to the next local player //------------------------------------------------------------------------------ void SimStation::stepOwnshipPlayer() { Basic::PairStream* pl = getSimulation()->getPlayers(); if (pl != nullptr) { Simulation::Player* f = nullptr; Simulation::Player* n = nullptr; bool found = false; // Find the next player Basic::List::Item* item = pl->getFirstItem(); while (item != nullptr) { Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue()); if (pair != nullptr) { Simulation::Player* ip = static_cast<Simulation::Player*>(pair->object()); if ( ip->isMode(Simulation::Player::ACTIVE) && ip->isLocalPlayer() && ip->isClassType(typeid(Simulation::AirVehicle)) ) { if (f == nullptr) { f = ip; } // Remember the first if (found) { n = ip; ; break; } if (ip == getOwnship()) found = true; } } item = item->getNext(); } if (found && n == nullptr) n = f; if (n != nullptr) setOwnshipPlayer(n); pl->unref(); } }
//------------------------------------------------------------------------------ // updateData() -- update Non-time critical stuff here //------------------------------------------------------------------------------ void Navigation::updateData(const LCreal dt) { // --- // Update our position, attitude and velocities // --- if (getOwnship() != 0) { velValid = updateSysVelocity(); posValid = updateSysPosition(); attValid = updateSysAttitude(); magVarValid = updateMagVar(); } else { posValid = false; attValid = false; velValid = false; magVarValid = false; } // --- // Update the BaseClass and our primary route // --- BaseClass::updateData(dt); if (priRoute != 0) priRoute->updateData(dt); // Update our bullseye if (bull != 0) bull->compute(this); // --- // Update our navigational steering data // --- updateNavSteering(); }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void System::updateData(const LCreal dt) { // We're nothing without an ownship ... if (ownship == 0 && getOwnship() == 0) return; BaseClass::updateData(dt); }
//------------------------------------------------------------------------------ // rollStabilizingController() -- Roll stabilizes the gimbal //------------------------------------------------------------------------------ void StabilizingGimbal::rollStabilizingController(const LCreal) { if (getOwnship() == nullptr) return; osg::Vec3 tpos = getCmdPosition(); if (mountPosition == NOSE){ tpos[ROLL_IDX] = static_cast<LCreal>(-getOwnship()->getRoll()); } else if (mountPosition == TAIL){ tpos[ROLL_IDX] = static_cast<LCreal>(getOwnship()->getRoll()); } else if (mountPosition == RIGHT_WING){ tpos[ELEV_IDX] = static_cast<LCreal>(-getOwnship()->getPitch()); } else if (mountPosition == LEFT_WING){ tpos[ELEV_IDX] = static_cast<LCreal>(getOwnship()->getPitch()); } setCmdPos( tpos ); }
//------------------------------------------------------------------------------ // Find the next target to shoot //------------------------------------------------------------------------------ Track* SimpleStoresMgr::getNextTarget() { Track* trk = nullptr; if (getOwnship() != nullptr) { OnboardComputer* obc = getOwnship()->getOnboardComputer(); if (obc != nullptr) { // Get the next to shoot int n = 0; base::safe_ptr<Track> track; n = obc->getShootList(&track,1); if (n > 0) trk = track; } } return trk; }
// ---------------------------------------------------------------------------- // updateData() - update background data // ---------------------------------------------------------------------------- void MapDisplay::updateData(const LCreal dt) { BaseClass::updateData(dt); // get pointer to MapPage data int cmdRange = 0; MapPage* page = static_cast<MapPage*>(subpage()); if (page != 0) { cmdRange = static_cast<int>(page->getRange()); } double cmdAirspeed = 0, cmdAltitude = 0, cmdHeading = 0; bool apButtonsVis = false; // pilot max double maxAccel = 0, maxTurn = 0, maxBank = 0, maxClimb = 0; // default to autopilot mode off int apMode = 1; Simulation::Aircraft* pA = static_cast<Simulation::Aircraft*>(getOwnship()); if (pA != 0) { Simulation::Autopilot* ap = static_cast<Simulation::Autopilot*>(pA->getPilot()); if (ap != 0) { // button visibility is based on autopilot being in NO modes apButtonsVis = (ap->isNavModeOn() || ap->isLoiterModeOn() || ap->isFollowTheLeadModeOn()); cmdAirspeed = ap->getCommandedVelocityKts(); cmdAltitude = ap->getCommandedAltitudeFt(); cmdHeading = ap->getCommandedHeadingD(); if (ap->isNavModeOn()) apMode = 2; else if (ap->isLoiterModeOn()) apMode = 3; else if (ap->isFollowTheLeadModeOn()) apMode = 4; maxAccel = ap->getMaxVelAcc(); maxTurn = ap->getMaxTurnRate(); maxBank = ap->getMaxBankAngle(); maxClimb = ap->getMaxClimbRate(); } } // get pointer to LaeroModel data send("cmdRange", UPDATE_VALUE, cmdRange, cmdRangeSD); send("cmdAirspeed", UPDATE_VALUE, cmdAirspeed, cmdAirspeedSD); send("cmdAltitude", UPDATE_VALUE, cmdAltitude, cmdAltitudeSD); send("cmdHeading", UPDATE_VALUE, cmdHeading, cmdHeadingSD); // Autopilot mode send("apMode", SELECT, apMode, apModeSD); // button visibility send("apReqButtons", SET_VISIBILITY, !apButtonsVis, apReqButtonVisSD); // maximums send("cmdAccel", UPDATE_VALUE, maxAccel, maxAccelSD); send("cmdClimb", UPDATE_VALUE, maxClimb, maxClimbSD); send("cmdRot", UPDATE_VALUE, maxTurn, maxTurnSD); send("cmdBank", UPDATE_VALUE, maxBank, maxBankSD); }
//------------------------------------------------------------------------------ // set the position to that of our ownship vehicle //------------------------------------------------------------------------------ bool NavRadio::setPosition() { bool ok = false; const Player* p = getOwnship(); if (p != 0) { latitude = p->getLatitude(); longitude = p->getLongitude(); altitude = p->getAltitudeFt(); ok = true; } return ok; }
// By weapon Weapon* Stores::prereleaseWeapon(Weapon* const wpn) { Weapon* flyout = nullptr; Player* own = getOwnship(); if (wpn != nullptr && own != nullptr) { // Release the weapon wpn->setLaunchVehicle(own); flyout = wpn->prerelease(); } return flyout; }
//------------------------------------------------------------------------------ // reset() -- Reset parameters //------------------------------------------------------------------------------ void IrSystem::reset() { // FAB - sensor needs to know its seeker without waiting for updateData if (getSeeker() == nullptr && getSeekerName() != nullptr && getOwnship() != nullptr) { // We have a name of the seeker, but not the seeker itself const char* name = *getSeekerName(); // Get the named seeker from the player's list of gimbals const auto p = dynamic_cast<IrSeeker*>( getOwnship()->getGimbalByName(name) ); if (p != nullptr) { setSeeker( p ); } if (getSeeker() == nullptr) { // The assigned seeker was not found! if (isMessageEnabled(MSG_ERROR)) { std::cerr << "IrSystem::update() ERROR -- seeker: " << name << ", was not found!" << std::endl; } setSlotSeekerName(nullptr); } } BaseClass::reset(); }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void IrSystem::updateData(const double dt) { // --- // Do we need to find the seeker? // --- if (getSeeker() == nullptr && getSeekerName() != nullptr && getOwnship() != nullptr) { // We have a name of the seeker, but not the seeker itself const char* name = *getSeekerName(); // Get the named seeker from the player's list of gimbals const auto p = dynamic_cast<IrSeeker*>( getOwnship()->getGimbalByName(name) ); if (p != nullptr) { setSeeker( p ); // FAB - not needed - esp if multiple sensors on a seeker. //getSeeker()->setSystem(this); } if (getSeeker() == nullptr) { // The assigned seeker was not found! if (isMessageEnabled(MSG_ERROR)) { std::cerr << "IrSystem::update() ERROR -- seeker: " << name << ", was not found!" << std::endl; } setSlotSeekerName(nullptr); } } // --- // Process our players of interest // --- processPlayersOfInterest(); // --- // Our base class methods // --- BaseClass::updateData(dt); }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void TacanRadio::updateData(const LCreal dt) { BaseClass::updateData(dt); //Must have ownship if (getOwnship() == 0) return; // Set our position to that of our ownship vehicle setPosition(); // //Get Range and Bearing... //bool rangeBearingTestResult = getRangeBearing(&rangeIsValid,&range,&grdrange,&bearingIsValid,&bearing); }
// By weapon Weapon* Stores::releaseWeapon(Weapon* const wpn) { Weapon* flyout = 0; Player* own = getOwnship(); if (wpn != 0 && own != 0) { // Release the weapon wpn->setLaunchVehicle(own); flyout = wpn->release(); } return flyout; }
//------------------------------------------------------------------------------ // updateTC() -- update time critical stuff here //------------------------------------------------------------------------------ void System::updateTC(const LCreal dt0) { // We're nothing without an ownship ... if (ownship == 0 && getOwnship() == 0) return; // --- // Delta time // --- // real or frozen? LCreal dt = dt0; if (isFrozen()) dt = 0.0; // Delta time for methods that are running every fourth phase LCreal dt4 = dt * 4.0f; // --- // Four phases per frame // --- Simulation* sim = ownship->getSimulation(); if (sim == 0) return; switch (sim->phase()) { case 0 : // Frame0 --- Dynamics method dynamics(dt4); break; case 1 : // Frame1 --- Transmit method transmit(dt4); break; case 2 : // Frame2 --- Receive method receive(dt4); break; case 3 : // Frame3 --- Process method process(dt4); break; } // --- // Last, update our base class // and use 'dt' because if we're frozen then so are our subcomponents. // --- BaseClass::updateTC(dt); }
// (default) Velocity data function (using truth data from ownship) bool Navigation::updateSysVelocity() { bool ok = false; if (getOwnship() != 0) { setVelocity( getOwnship()->getVelocity() ); setAcceleration( getOwnship()->getAcceleration() ); setGroundSpeedKts( getOwnship()->getGroundSpeedKts() ); setTrueAirspeedKts( getOwnship()->getTotalVelocityKts() ); setGroundTrackDeg( getOwnship()->getGroundTrackD() ); setVelocityDataValid( true ); ok = true; } else { setVelocityDataValid( false ); } return ok; }
//------------------------------------------------------------------------------ // Process phase //------------------------------------------------------------------------------ void Navigation::process(const LCreal dt) { BaseClass::process(dt); // --- // Update our position, attitude and velocities // --- if (getOwnship() != 0) { velValid = updateSysVelocity(); posValid = updateSysPosition(); attValid = updateSysAttitude(); magVarValid = updateMagVar(); } else { posValid = false; attValid = false; velValid = false; magVarValid = false; } // Update UTC double v = utc + dt; if (v >= Basic::Time::D2S) v = (v - Basic::Time::D2S); setUTC(v); // --- // Update our primary route // --- if (priRoute != 0) priRoute->tcFrame(dt); // Update our bullseye if (bull != 0) bull->compute(this); // --- // Update our navigational steering data // --- updateNavSteering(); }
//------------------------------------------------------------------------------ // process() -- //------------------------------------------------------------------------------ void Sar::process(const LCreal dt) { BaseClass::process(dt); // Imaging in porgress? if (timer > 0) { // --- // Point the beam // --- Antenna* ant = getAntenna(); if (ant != 0) { Simulation* s = getSimulation(); double refLat = s->getRefLatitude(); double refLon = s->getRefLongitude(); osg::Vec3 pos; Basic::Nav::convertLL2PosVec( refLat, refLon, // Ref point (at sea level) getStarePointLatitude(), getStarePointLongitude(), getStarePointElevation(), &pos); // x,y,z NED // Platform (ownship) coord and then body osg::Vec3 posP = pos - getOwnship()->getPosition(); osg::Vec3 posB = getOwnship()->getRotMat() * posP; // Convert to az/el LCreal tgt_az = 0.0; // Angle (degs) LCreal tgt_el = 0.0; // Angle (degs) xyz2AzEl(posB, &tgt_az, &tgt_el); // Command to that position LCreal az = tgt_az * (LCreal)Basic::Angle::D2RCC; LCreal el = tgt_el * (LCreal)Basic::Angle::D2RCC; ant->setRefAzimuth(az); ant->setRefElevation(el); ant->setScanMode(Antenna::CONICAL_SCAN); } // --- // Process timer // --- LCreal ttimer = timer - dt; if (ttimer <= 0) { // ### test -- Generate a test image ### Image* p = new Image(); p->testImage(width,height); p->setImageId(getNextId()); p->setLatitude(getStarePointLatitude()); p->setLongitude(getStarePointLongitude()); p->setElevation(getStarePointElevation()); p->setOrientation(0); if (isMessageEnabled(MSG_INFO)) { std::cout << "Sar:: Generating test image: resolution: " << getResolution() << std::endl; } if (getResolution() > 0) p->setResolution( getResolution() ); else p->setResolution( 3.0f * Basic::Distance::FT2M ); Basic::Pair* pp = new Basic::Pair("image", p); addImage(pp); // ### TEST TEST // Just finished! ttimer = 0; setTransmitterEnableFlag(false); } timer = ttimer; } BaseClass::updateData(dt); }
//------------------------------------------------------------------------------ // sendMessage() -- send the datalink message out to the world. //------------------------------------------------------------------------------ bool Datalink::sendMessage(Basic::Object* const msg) { bool sent = false; // If we can send to our local players directly (or via radio) if (sendLocal) { // --- // Have a comm radio -- then we'll just let our companion radio system handle this // --- if (radio != 0) { sent = radio->transmitDataMessage(msg); } // --- // No comm radio -- then we'll send this out to the other players ourself. // --- else if (getOwnship() != 0) { Simulation* sim = getSimulation(); if (sim != 0) { Basic::PairStream* players = sim->getPlayers(); if (players != 0) { Basic::List::Item* playerItem = players->getFirstItem(); while (playerItem != 0) { Basic::Pair* playerPair = static_cast<Basic::Pair*>(playerItem->getValue()); Player* player = static_cast<Player*>(playerPair->object()); if (player->isLocalPlayer()) { // Send to active, local players only (and not to ourself) if ((player->isActive() || player->isMode(Player::PRE_RELEASE)) && player != getOwnship() ) { player->event(DATALINK_MESSAGE, msg); } playerItem = playerItem->getNext(); } else { // Networked players are at the end of the list, // so we can stop now. playerItem = 0; } } players->unref(); players = 0; } } sent = true; } } // --- // and let any (optional) outgoing queue know about this. // --- if (queueForNetwork) { Player* ownship = getOwnship(); if (ownship != 0) { if (ownship->isLocalPlayer()) { queueOutgoingMessage(msg); } } } return sent; }
// ---------------------------------------------------------------------------- // buttonEvent() - called when a button is pressed // ---------------------------------------------------------------------------- void MapDisplay::buttonEvent(const int b) { // cmdRange up, down MapPage* page = static_cast<MapPage*>(subpage()); // cmdAirspeed, cmdAltitude, cmdHeading up, down Simulation::Player* pA = getOwnship(); Simulation::Autopilot* ap = 0; if (pA != 0) { ap = static_cast<Simulation::Autopilot*>(pA->getPilot()); } if (page != 0 && ap != 0) { if (b == DEC_RANGE) { if (page->getRange() > 5) { page->setRange(page->getRange() - 5); } } else if (b == INC_RANGE) { if (page->getRange() < 320) { page->setRange(page->getRange() + 5); } } else if (b == DEC_CMD_AS) { double cmdAirspeed = ap->getCommandedVelocityKts(); if (cmdAirspeed > 100) { cmdAirspeed -= 10; ap->setCommandedVelocityKts(cmdAirspeed); } } else if (b == INC_CMD_AS) { double cmdAirspeed = ap->getCommandedVelocityKts(); if (cmdAirspeed < 400) { cmdAirspeed += 10; ap->setCommandedVelocityKts(cmdAirspeed); } } else if (b == DEC_CMD_ALT) { double cmdAltitude = ap->getCommandedAltitudeFt(); if (cmdAltitude > 1000) { cmdAltitude -= 500; ap->setCommandedAltitudeFt(cmdAltitude); } } else if (b == INC_CMD_ALT) { double cmdAltitude = ap->getCommandedAltitudeFt(); if (cmdAltitude < 40000) { cmdAltitude += 500; ap->setCommandedAltitudeFt(cmdAltitude); } } else if (b == DEC_CMD_HDG) { double cmdHeading = ap->getCommandedHeadingD(); cmdHeading -= 10; if (cmdHeading < -180.0) cmdHeading += 360; ap->setCommandedHeadingD(cmdHeading); } else if (b == INC_CMD_HDG) { double cmdHeading = ap->getCommandedHeadingD(); cmdHeading += 10; if (cmdHeading > 180.0) cmdHeading -= 360; ap->setCommandedHeadingD(cmdHeading); } else if (b == INC_CMD_AS_NPS) { double maxAccel = ap->getMaxVelAcc(); if (maxAccel < 20) maxAccel++; ap->setMaxVelAccNps(maxAccel); } else if (b == DEC_CMD_AS_NPS) { double maxAccel = ap->getMaxVelAcc(); if (maxAccel > 1) maxAccel--; ap->setMaxVelAccNps(maxAccel); } // Climb rate in meters per second else if (b == INC_CMD_ALT_MPS) { double maxClimb = ap->getMaxClimbRate(); if (maxClimb < 100) maxClimb += 5; ap->setMaxClimbRateMps(maxClimb); } else if (b == DEC_CMD_ALT_MPS) { double maxClimb = ap->getMaxClimbRate(); if (maxClimb > 5) maxClimb -= 5; ap->setMaxClimbRateMps(maxClimb); } // Turn rate in degrees per second else if (b == INC_CMD_HDG_ROT) { double maxTR = ap->getMaxTurnRate(); if (maxTR < 25) maxTR++; ap->setMaxTurnRateDps(maxTR); } else if (b == DEC_CMD_HDG_ROT) { double maxTR = ap->getMaxTurnRate(); if (maxTR > 0) maxTR--; ap->setMaxTurnRateDps(maxTR); } // Max bank (degrees) else if (b == INC_CMD_HDG_BNK) { double maxBank = ap->getMaxBankAngle(); if (maxBank < 90) maxBank++; ap->setMaxBankAngleDeg(maxBank); } else if (b == DEC_CMD_HDG_BNK) { double maxBank = ap->getMaxBankAngle(); if (maxBank > 0) maxBank--; ap->setMaxBankAngleDeg(maxBank); } else if (b == PASSIVE_ENABLE) { passiveEnable = true; } else if (b == PASSIVE_DISABLE) { passiveEnable = false; } // get our autopilot mode and change it else if (b == CHANGE_AP_MODE) { // if off, go to nav bool navMode = ap->isNavModeOn(); bool loiterMode = ap->isLoiterModeOn(); bool flMode = ap->isFollowTheLeadModeOn(); // if in nav mode, go to loiter mode if (navMode) { ap->setNavMode(false); ap->setLoiterMode(true); } // if in loiter mode, go to follow the lead mode else if (loiterMode) { ap->setLoiterMode(false); ap->setFollowTheLeadMode(true); } // if in follow the lead mode, turn off all modes else if (flMode) { ap->setFollowTheLeadMode(false); } // all modes off, go back to nav else ap->setNavMode(true); } } }