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
/// Persistent state carried between [`pid_compute`](crate::pid_compute) invocations.
///
/// This struct is the "memory" of the controller. Pass it into [`pid_compute`](crate::pid_compute)
/// and receive an updated copy back alongside the control output. Start with
/// [`PidState::default()`] for a fresh controller.
///
/// All fields are public to support serialization, checkpointing, and testing.
///
/// # Examples
///
/// ```
/// use pidgeon::{ControllerConfig, PidState, pid_compute};
///
/// let config = ControllerConfig::builder()
/// .with_kp(1.0)
/// .with_output_limits(-10.0, 10.0)
/// .build()
/// .unwrap();
///
/// let state = PidState::default();
/// let (output, next_state) = pid_compute(&config, &state, 5.0, 0.01).unwrap();
/// assert!(!next_state.first_run);
/// ```