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
//! Control Theory Primitives
//!
//! This module provides basic building-blocks and implementations for controlling
//! systems. These "systems" could be drivetrains, an arm or lift, or any other
//! mechanism that requires precise motion control.
use Duration;
/// A trait for implementing feedback control of a system.
///
/// Feedback controllers are algorithms that attempt to reach a desired state (setpoint) by:
///
/// 1. Measuring the difference (error) between the current and the desired state.
/// 2. Computing corrective control signals that drive the system toward the desired setpoint
/// to minimize error in the system.
/// 3. Continuously adjusting based on new measurements of the system.
///
/// This is a form of "closed-loop" control, which refers to how the controller forms a loop
/// by continuously measuring the system's state and "feeding" the measurement back into the
/// controller to adjust for a new, more desirable measurement that minimizes on error.
///
/// # Example
///
/// Simple P (proportional only) controller:
///
/// ```
/// use core::time::Duration;
///
/// struct ProportionalController {
/// gain: f64,
/// }
///
/// impl Feedback for ProportionalController {
/// type Error = f64;
/// type Output = f64;
///
/// fn update(&mut self, error: Self::Error, _dt: Duration) -> Self::Output {
/// self.gain * error
/// }
/// }
/// ```