CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduPlane/VTOL_Assist.h
Views: 1798
1
#pragma once
2
3
// VTOL assistance in a forward flight mode
4
5
class QuadPlane;
6
class VTOL_Assist {
7
public:
8
VTOL_Assist(QuadPlane& _quadplane):quadplane(_quadplane) {};
9
10
// check for assistance needed
11
bool should_assist(float aspeed, bool have_airspeed);
12
13
// Assistance not needed, reset any state
14
void reset();
15
16
// speed below which quad assistance is given
17
AP_Float speed;
18
19
// angular error at which quad assistance is given
20
AP_Int8 angle;
21
22
// altitude to trigger assistance
23
AP_Int16 alt;
24
25
// Time hysteresis for triggering of assistance
26
AP_Float delay;
27
28
// State from pilot
29
enum class STATE {
30
ASSIST_DISABLED,
31
ASSIST_ENABLED,
32
FORCE_ENABLED,
33
};
34
void set_state(STATE _state) { state = _state; }
35
36
// Logging getters for assist types
37
bool in_force_assist() const { return force_assist; }
38
bool in_speed_assist() const { return speed_assist; }
39
bool in_alt_assist() const { return alt_error.is_active(); }
40
bool in_angle_assist() const { return angle_error.is_active(); }
41
42
private:
43
44
// Default to enabled
45
STATE state = STATE::ASSIST_ENABLED;
46
47
class Assist_Hysteresis {
48
public:
49
// Reset state
50
void reset();
51
52
// Update state, return true when first triggered
53
bool update(const bool trigger, const uint32_t &now_ms, const uint32_t &trigger_delay_ms, const uint32_t &clear_delay_ms);
54
55
// Return true if the output is active
56
bool is_active() const { return active; }
57
58
private:
59
uint32_t start_ms;
60
uint32_t last_ms;
61
bool active;
62
};
63
Assist_Hysteresis angle_error;
64
Assist_Hysteresis alt_error;
65
66
// Force and speed assist have no hysteresis
67
bool force_assist;
68
bool speed_assist;
69
70
// Reference to access quadplane
71
QuadPlane& quadplane;
72
};
73
74