Skip to content

Commit

Permalink
Add get_setpoint().
Browse files Browse the repository at this point in the history
- Bump to 1.2.1
  • Loading branch information
braincore committed Nov 15, 2018
1 parent 459a97a commit b6ee599
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pid"
version = "1.1.1"
version = "1.2.1"
authors = ["Ken Elkabany <[email protected]>"]
license = "MIT"
description = "A PID controller."
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ where
self.setpoint = Some(setpoint);
}

/// Returns the current setpoint.
pub fn get_setpoint(&mut self) -> Option<T> {
self.setpoint
}

/// Resets the integral term back to zero. This may drastically change the
/// control output.
pub fn reset_integral_term(&mut self) {
Expand Down Expand Up @@ -117,7 +122,9 @@ mod tests {
#[test]
fn proportional() {
let mut pid = Pid::new(2.0, 0.0, 0.0, 100.0, 100.0, 100.0);
assert_eq!(pid.get_setpoint(), None);
pid.update_setpoint(10.0);
assert_eq!(pid.get_setpoint(), Some(10.0));

// Test simple proportional
assert_eq!(pid.next_control_output(0.0).output, 20.0);
Expand Down

0 comments on commit b6ee599

Please sign in to comment.