1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Decides when a landing vehicle has touched down: see [`TouchdownDetector`].
/// Sinking faster than this, in m/s, shows the descent has begun.
pub const DESCENDING_MPS: f32 = 0.2;
/// Vertical speed below this, in m/s either way, counts as stopped.
pub const STOPPED_MPS: f32 = 0.1;
/// How long, in seconds, the vehicle must stay stopped after descending to count as down.
pub const TOUCHDOWN_HOLD_S: f32 = 1.0;
/// Detects touchdown during a land ([`ControlInput::Land`](crate::ControlInput::Land)) from
/// the vertical speed alone.
///
/// Landing guidance keeps lowering its altitude target, so a vehicle still in the air can't
/// hold a vertical speed near zero for long: its thrust falls until it sinks. Once the vehicle
/// has sunk faster than [`DESCENDING_MPS`], staying within ±[`STOPPED_MPS`] for
/// [`TOUCHDOWN_HOLD_S`] means the ground stopped it. Before the descent begins (the hover the
/// land started from), nothing counts. Touchdown latches until [`reset`](Self::reset).
///
/// It works only while a land is flown; hovering would read as touchdown. A non-finite speed
/// restarts the stopped timer without clearing the descent.
///
/// # Examples
///
/// ```
/// use stable_flight::commanders::TouchdownDetector;
///
/// let mut detector = TouchdownDetector::default();
/// assert!(!detector.update(0.5, 0.0)); // hovering before the descent: not down
/// assert!(!detector.update(0.5, -0.7)); // descending
/// assert!(!detector.update(0.5, 0.0)); // stopped for 0.5 s
/// assert!(detector.update(0.6, 0.0)); // stopped for 1.1 s: down
/// ```