Skip to content

Commit

Permalink
Remove unnecessary dependency on std so that PID works with embedded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Boldt authored and braincore committed May 15, 2019
1 parent b6ee599 commit 96d1063
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ repository = "https://github.com/braincore/pid-rs"
keywords = ["pid"]
readme = "README.md"

[dependencies]
num-traits = "0.2"
[dependencies.num-traits]
version = "0.2"
default-features = false

[badges]
travis-ci = { repository = "braincore/pid-rs" }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A proportional-integral-derivative (PID) controller.
* Mitigation of output jumps when changing `ki` by storing the integration of
`e(t) * ki(t)` rather than only `e(t)`.
* Generic float type parameter to support `f32` or `f64`.
* Support for `no_std` environments, such as embedded systems.

## Assumptions

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! A proportional-integral-derivative (PID) controller.
#![no_std]
extern crate num_traits;
use num_traits::Float;
use num_traits::float::FloatCore;

#[derive(Debug)]
pub struct Pid<T: Float> {
pub struct Pid<T: FloatCore> {
/// Proportional gain.
pub kp: T,
/// Integral gain.
Expand All @@ -25,7 +25,7 @@ pub struct Pid<T: Float> {
}

#[derive(Debug)]
pub struct ControlOutput<T: Float> {
pub struct ControlOutput<T: FloatCore> {
/// Contribution of the P term to the output.
pub p: T,
/// Contribution of the I term to the output.
Expand All @@ -39,7 +39,7 @@ pub struct ControlOutput<T: Float> {

impl<T> Pid<T>
where
T: Float,
T: FloatCore,
{
pub fn new(kp: T, ki: T, kd: T, p_limit: T, i_limit: T, d_limit: T) -> Self {
Self {
Expand Down

0 comments on commit 96d1063

Please sign in to comment.