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
//! Control loops.
use Duration;
pub use BangBang;
pub use DcMotorFeedforward;
pub use ;
pub use TakeBackHalf;
/// Functionality for a generic control loop.
///
/// Control loops are fundamental to control systems, where a controller
/// continually adjusts its output to drive a control system to its desired value.
///
/// This trait defines the core behavior of such controllers, which take a `setpoint`
/// (the desired target value of the system) and optionally a `measurement` of the
/// system (recorded through a sensor or similar). The controller then computes an
/// output intended to minimize the system's *error*, which is the difference between
/// the `measurement` and the `setpoint`.
///
/// # Examples
///
/// This example shows an implementation of a basic [proportional feedback controller],
/// which scales its output based on the system's error. Measurements further from the
/// setpoint will yield larger control signals.
///
/// ```
/// pub struct PController {
/// pub kp: f64,
/// }
///
/// impl ControlLoop for PController {
/// type Input = f64;
/// type Output = f64;
///
/// fn update(
/// &mut self,
/// measurement: f64,
/// setpoint: f64,
/// _dt: Duration,
/// ) -> f64 {
/// (setpoint - measurement) * self.kp
/// }
/// }
/// ```
///
/// [proportional feedback controller]: https://en.wikipedia.org/wiki/Proportional_control