{"id":14992268,"url":"https://github.com/braincore/pid-rs","last_synced_at":"2025-12-12T15:35:07.518Z","repository":{"id":51223743,"uuid":"142090520","full_name":"braincore/pid-rs","owner":"braincore","description":"A PID controller for Rust projects.","archived":false,"fork":false,"pushed_at":"2024-06-19T12:51:04.000Z","size":25,"stargazers_count":93,"open_issues_count":4,"forks_count":27,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-02T01:04:21.642Z","etag":null,"topics":["pid-controller","rust","rust-library"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/braincore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-24T01:56:16.000Z","updated_at":"2024-10-25T18:12:34.000Z","dependencies_parsed_at":"2024-06-21T07:33:00.596Z","dependency_job_id":"9588b1ab-76b0-45ea-875d-b9596d7afdde","html_url":"https://github.com/braincore/pid-rs","commit_stats":{"total_commits":35,"total_committers":9,"mean_commits":3.888888888888889,"dds":0.4285714285714286,"last_synced_commit":"9f39e7d4addcb3c54e0e100be8a9d4a22fff35f9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braincore%2Fpid-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braincore%2Fpid-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braincore%2Fpid-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/braincore%2Fpid-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/braincore","download_url":"https://codeload.github.com/braincore/pid-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234200176,"owners_count":18795139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pid-controller","rust","rust-library"],"created_at":"2024-09-24T15:00:54.001Z","updated_at":"2025-09-25T14:31:07.680Z","avatar_url":"https://github.com/braincore.png","language":"Rust","readme":"# PID Controller for Rust\n[![Latest Version]][crates.io] [![Documentation]][docs.rs] \n\n[Latest Version]: https://img.shields.io/crates/v/pid.svg\n[crates.io]: https://crates.io/crates/pid\n[Documentation]: https://docs.rs/pid/badge.svg\n[docs.rs]: https://docs.rs/pid\n\nA proportional-integral-derivative (PID) controller.\n\n## Features\n\n* Visibility into individual contribution of P, I, and D terms which often\n  need to be logged for later analysis and parameter tuning.\n* Output limits on a per term basis.\n* Three-term control output limit.\n* Mitigation of integral windup using integral term limit.\n* Mitigation of derivative kick by using the derivative of the measurement\n  rather than the derivative of the error.\n* On-the-fly changes to `setpoint`/`kp`/`ki`/`kd`.\n  * Mitigation of output jumps when changing `ki` by storing the integration of\n    `e(t) * ki(t)` rather than only `e(t)`.\n* Generic float type parameter to support `f32` or `f64`.\n* Support for `no_std` environments, such as embedded systems.\n* Optional support for [Serde](https://crates.io/crates/serde). Enable the\n  `serde` Cargo feature, if you need `Pid` to implement\n  `Serialize`/`Deserialize`.\n\n## Example\n\n```rust\nuse pid::Pid;\n\n// Create a new proportional-only PID controller with a setpoint of 15\nlet mut pid = Pid::new(15.0, 100.0);\npid.p(10.0, 100.0);\n\n// Input a measurement with an error of 5.0 from our setpoint\nlet output = pid.next_control_output(10.0);\n\n// Show that the error is correct by multiplying by our kp\nassert_eq!(output.output, 50.0); // \u003c--\nassert_eq!(output.p, 50.0);\n\n// It won't change on repeat; the controller is proportional-only\nlet output = pid.next_control_output(10.0);\nassert_eq!(output.output, 50.0); // \u003c--\nassert_eq!(output.p, 50.0);\n\n// Add a new integral term to the controller and input again\npid.i(1.0, 100.0);\nlet output = pid.next_control_output(10.0);\n\n// Now that the integral makes the controller stateful, it will change\nassert_eq!(output.output, 55.0); // \u003c--\nassert_eq!(output.p, 50.0);\nassert_eq!(output.i, 5.0);\n\n// Add our final derivative term and match our setpoint target\npid.d(2.0, 100.0);\nlet output = pid.next_control_output(15.0);\n\n// The output will now say to go down due to the derivative\nassert_eq!(output.output, -5.0); // \u003c--\nassert_eq!(output.p, 0.0);\nassert_eq!(output.i, 5.0);\nassert_eq!(output.d, -10.0);\n```\n\n## Assumptions\n\n* Measurements occur at equal spacing. (`t(i) = t(i-1) + C`)\n* Output limits per term are symmetric around 0 (`-limit \u003c= term \u003c= limit`).\n\n## Formulation\n\nThere are several different formulations of PID controllers. This library\nuses the independent form:\n\n```math\nC(t) = K_p \\cdot e(t) + K_i \\cdot \\int{e(t)dt} - K_d \\cdot \\frac{dP(t)}{dt}\n```\n\nWhere:\n\n- C(t) = control output, the output to the actuator.\n- P(t) = process variable, the measured value.\n- e(t) = error = S(t) - P(t)\n- S(t) = set point, the desired target for the process variable.\n\n`kp`/`ki`/`kd` can be changed during operation and can therefore be a function\nof time.\n\nIf you're interested in the dependent form, add your own logic that computes\n`kp`/`ki`/`kd` using dead time, time constant, `kc`, or whatever else.\n\n## Todo\n\n- [ ] Helper for (auto-)tuning by detecting frequency \u0026 amplitude of\n      oscillations.\n\n## License\n\nLicensed under either at your discretion:\n\n- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)\n","funding_links":[],"categories":["Motion Control"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbraincore%2Fpid-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbraincore%2Fpid-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbraincore%2Fpid-rs/lists"}