bool TaskManager::Update(const AircraftState &state, const AircraftState &state_last) { if (!state.location.IsValid()) { /* in case of GPS failure or and during startup (before the first GPS fix), update only the stats */ UpdateCommonStats(state); return false; } /* always update ordered task so even if we are temporarily in a different mode, so the task stats are still updated. Otherwise, the task stats would freeze and sampling etc would not be performed. In actual use, even if you are in Abort/Goto you still may want to go back to the task and have it know where you went with respect to your task turnpoints etc. */ bool retval = false; if (state_last.time > state.time) Reset(); if (task_ordered.TaskSize() > 1) // always update ordered task retval |= task_ordered.Update(state, state_last, glide_polar); // inform the abort task whether it is running as the task or not task_abort.SetActive(active_task == &task_abort); // and tell it where the task destination is (if any) const GeoPoint *destination = &state.location; if (task_behaviour.abort_task_mode == AbortTaskMode::HOME) { const Waypoint *home = task_abort.GetHome(); if (home) destination = &home->location; } else if (task_behaviour.abort_task_mode == AbortTaskMode::TASK) { const TaskWaypoint *twp = GetActiveTaskPoint(); if (twp) destination = &(twp->GetLocationRemaining()); } task_abort.SetTaskDestination(*destination); retval |= task_abort.Update(state, state_last, GetReachPolar()); if (active_task && active_task != &task_ordered && active_task != &task_abort) // update mode task for any that have not yet run retval |= active_task->Update(state, state_last, glide_polar); UpdateCommonStats(state); return retval; }
bool TaskManager::Update(const AircraftState &state, const AircraftState &state_last) { /* always update ordered task so even if we are temporarily in a different mode, so the task stats are still updated. Otherwise, the task stats would freeze and sampling etc would not be performed. In actual use, even if you are in Abort/Goto you still may want to go back to the task and have it know where you went with respect to your task turnpoints etc. */ bool retval = false; if (!negative(state_last.time) && !negative(state.time) && state_last.time > state.time) /* time warp */ Reset(); if (ordered_task->TaskSize() > 1) { // always update ordered task retval |= ordered_task->Update(state, state_last, glide_polar); } // inform the abort task whether it is running as the task or not abort_task->SetActive(active_task == abort_task); // and tell it where the task destination is (if any) const GeoPoint *destination = &state.location; if (task_behaviour.abort_task_mode == AbortTaskMode::HOME) { const auto home = abort_task->GetHome(); if (home) destination = &home->location; } else if (task_behaviour.abort_task_mode == AbortTaskMode::TASK) { const OrderedTaskPoint *twp = (const OrderedTaskPoint *) ordered_task->GetActiveTaskPoint(); if (twp) destination = &(twp->GetLocationRemaining()); } abort_task->SetTaskDestination(*destination); retval |= abort_task->Update(state, state_last, GetReachPolar()); if (active_task && active_task != ordered_task && active_task != abort_task) // update mode task for any that have not yet run retval |= active_task->Update(state, state_last, glide_polar); UpdateCommonStats(state); return retval; }
bool TaskManager::UpdateIdle(const AircraftState& state) { bool retval = false; if (active_task) { const GlidePolar &polar = active_task == &task_abort ? GetReachPolar() : glide_polar; retval |= active_task->UpdateIdle(state, polar); } return retval; }