You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit relaxes the bounds of the generics used for the
controller so signed integers (e.g. i8, i64, etc.) can be used
as well as floats. This has been done by adding a new trait which
also allows user-defined numbers to be easily implemented.
Resolves: #12
Copy file name to clipboardExpand all lines: src/lib.rs
+60-22Lines changed: 60 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -44,10 +44,27 @@
44
44
//! ```
45
45
#![no_std]
46
46
47
-
use num_traits::float::FloatCore;
48
47
#[cfg(feature = "serde")]
49
48
use serde::{Deserialize,Serialize};
50
49
50
+
/// A trait for any numeric type usable in the PID controller
51
+
///
52
+
/// This trait is automatically implemented for all types that satisfy `PartialOrd + num_traits::Signed + Copy`. This includes all of the signed float types and builtin integer except for [isize]:
53
+
/// - [i8]
54
+
/// - [i16]
55
+
/// - [i32]
56
+
/// - [i64]
57
+
/// - [i128]
58
+
/// - [f32]
59
+
/// - [f64]
60
+
///
61
+
/// As well as any user type that matches the requirements
@@ -81,9 +98,13 @@ use serde::{Deserialize, Serialize};
81
98
/// This [`next_control_output`](Self::next_control_output) method is what's used to input new values into the controller to tell it what the current state of the system is. In the examples above it's only being used once, but realistically this will be a hot method. Please see [ControlOutput] for examples of how to handle these outputs; it's quite straight forward and mirrors the values of this structure in some ways.
82
99
///
83
100
/// The last item of note is that these [`p`](Self::p()), [`i`](Self::i()), and [`d`](Self::d()) methods can be used *during* operation which lets you add and/or modify these controller values if need be.
/// [Number] is abstract and can be used with anything from a [i32] to an [i128] (as well as user-defined types). Because of this, very small types might overflow during calculation in [`next_control_output`](Self::next_control_output). You probably don't want to use [i8] or user-defined types around that size so keep that in mind when designing your controller.
0 commit comments