Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_PrecLand/AC_PrecLand_StateMachine.h
Views: 1798
#pragma once12#include "AC_PrecLand_config.h"34#if AC_PRECLAND_ENABLED56#include <AC_PrecLand/AC_PrecLand.h>7#include <AP_Math/AP_Math.h>89// This class constantly monitors what the status of the landing target is10// If it is not in sight, depending on user parameters, it decides what measures can be taken to bring the target back in sight11// If the target has been lost recently, the vehicle might try to retry the landing by going to the last known location of the target/going to the location where the target was last detected12// If we have no clue where the target might be, then failsafe measures are activated13// Failsafe measures can include stopping completely (hover), or landing vertically14class AC_PrecLand_StateMachine {15public:1617// Constructor18AC_PrecLand_StateMachine() {19init();20};2122// Do not allow copies23CLASS_NO_COPY(AC_PrecLand_StateMachine);2425// Initialize the state machine. This is called every time vehicle switches mode26void init();2728// Current status of the precland state machine29enum class Status: uint8_t {30ERROR = 0, // Unknown error31DESCEND, // No action is required, just descend vertically32RETRYING, // Vehicle is attempting to retry landing33FAILSAFE // Switch to prec landing failsafe34};3536// FailSafe action needed37enum class FailSafeAction: uint8_t {38HOLD_POS = 0, // Hold the current position of the vehicle39DESCEND // Descend vertically40};4142// Run Prec Land State Machine. During Prec Landing, we might encounter four scenarios:43// 1. We had the target in sight, but have lost it now. 2. We never had the target in sight and user wants to land.44// 3. We have the target in sight and can continue landing. 4. The sensor is out of range45// This method deals with all of these scenarios46// Returns the action needed to be done by the vehicle.47// Parameters: Vector3f "retry_pos_m" is filled with the required location if we need to retry landing.48Status update(Vector3f &retry_pos_m);4950// This is only called when the current status of the state machine returns "failsafe" and will return the action that the vehicle should do51// At the moment this method only allows you to stop in air permanently, or land vertically52// Failsafe will only trigger as a last resort53FailSafeAction get_failsafe_actions();5455// Strictness that the user wants for Prec Landing56enum class RetryStrictness: uint8_t {57NOT_STRICT = 0, // This is the behaviour on Copter 4.1 and below. The vehicle will land ASAP irrespective of target in sight or not58NORMAL, // Vehicle will retry a failed prec landing; if the target isn't found, it will land vertically59VERY_STRICT // Same as above, except vehicle will never land if the target isn't found60};6162// which retry action should be done63enum class RetryAction: uint8_t {64GO_TO_LAST_LOC = 0, // Go to the last location where landing target was detected65GO_TO_TARGET_LOC // Go towards the location of the detected landing target66};6768private:6970// Target is lost (i.e we had it in sight some time back), this method helps decide on what needs to be done next71// The chosen action depends on user set landing strictness and will be returned by this function72// Parameters: Vector3f "retry_pos_m" is filled with the required location if we need to retry landing.73Status get_target_lost_actions(Vector3f &retry_pos_m);7475// Retry landing based on a previously known location of the landing target76// Returns the action that should be taken by the vehicle77// Vector3f "retry_pos_m" is filled with the required location.78Status retry_landing(Vector3f &retry_pos_m);7980// Reset the landing statemachine. This needs to be called every time the landing target is back in sight.81// So that if the landing target goes out of sight again, we can start the failed landing procedure back from the beginning stage82void reset_failed_landing_statemachine();8384// State machine for action to do when Landing target is lost (after it was in sight a while back)85enum class TargetLostAction: uint8_t {86INIT = 0, // Decide on what action needs to be taken87DESCEND, // Descend for sometime (happens if we have just lost the target)88LAND_VERTICALLY, // Land vertically89RETRY_LANDING, // Retry landing (only possible if we had the landing target in sight sometime during the flight)90};9192TargetLostAction landing_target_lost_action; // Current action being done in the Lost Landing target state machine9394// State Machine for landing retry95enum class RetryLanding : uint8_t {96INIT = 0, // Init the retry statemachine. This would involve increasing the retry counter (so we how many times we have already retried)97IN_PROGRESS, // Retry in progress, we wait for the vehicle to get close to the target location98DESCEND, // Descend to the original height from where we had started the retry99COMPLETE // Retry completed. We try failsafe measures after this100};101RetryLanding _retry_state; // Current action being done in the Landing retry state machine102uint8_t _retry_count; // Total number of retires done in this mode103104bool failsafe_initialized; // True if failsafe has been initalized105uint32_t failsafe_start_ms; // timestamp of when failsafe was triggered106107};108109#endif // AC_PRECLAND_ENABLED110111112