#pragma once
class QuadPlane;
class VTOL_Assist {
public:
VTOL_Assist(QuadPlane& _quadplane):quadplane(_quadplane) {};
bool should_assist(float aspeed, bool have_airspeed);
void reset();
AP_Float speed;
AP_Int8 angle;
AP_Int16 alt;
AP_Float delay;
AP_Int16 options;
enum class OPTION {
FW_FORCE_DISABLED=(1U<<0),
SPIN_DISABLED=(1U<<1),
};
bool option_is_set(OPTION option) const {
return (options.get() & int32_t(option)) != 0;
}
enum class STATE {
ASSIST_DISABLED,
ASSIST_ENABLED,
FORCE_ENABLED,
};
void set_state(STATE _state) { state = _state; }
bool in_force_assist() const { return force_assist; }
bool in_speed_assist() const { return speed_assist; }
bool in_alt_assist() const { return alt_error.is_active(); }
bool in_angle_assist() const { return angle_error.is_active(); }
bool check_VTOL_recovery(void);
void output_spin_recovery(void);
private:
STATE state = STATE::ASSIST_ENABLED;
class Assist_Hysteresis {
public:
void reset();
bool update(const bool trigger, const uint32_t &now_ms, const uint32_t &trigger_delay_ms, const uint32_t &clear_delay_ms);
bool is_active() const { return active; }
private:
uint32_t start_ms;
uint32_t last_ms;
bool active;
};
Assist_Hysteresis angle_error;
Assist_Hysteresis alt_error;
bool force_assist;
bool speed_assist;
QuadPlane& quadplane;
};