| Crates.io | discrete_pid |
| lib.rs | discrete_pid |
| version | 0.1.0 |
| created_at | 2025-05-13 12:15:01.292292+00 |
| updated_at | 2025-05-13 12:15:01.292292+00 |
| description | A PID controller for robotics and discrete control systems |
| homepage | |
| repository | https://github.com/Hs293Go/discrete_pid |
| max_upload_size | |
| id | 1671816 |
| size | 365,877 |
A PID controller for robotics and discrete control systems in rust.
| Step Response | Quadrotor Rate Control |
|---|---|
![]() |
![]() |
Principled and Reliable
Real-World Ready
Lightweight and Dependency-Free
#![no_std] mode only requires core float traits from num_traitsOne of the most notable achievements of PID controllers in recent years has been the stabilization and control of quadrotors. We demonstrate just that using our PID controller in an example.

Run the example:
cargo run --example quadrotor_control --features simulation
Visualize the results:
python3 examples/plot_quadrotor_trajectory.py # Generates static plot
python3 examples/plot_quadrotor_trajectory.py --animate show # Live 3D animation
python3 examples/plot_quadrotor_trajectory.py --animate save # Save to GIF
In this example, we used our PID controller to track quadrotor body rates computed by an upstream geometric tracking controller. The README for the examples contains more details about the cascaded controller and the quadrotor simulation.
use core::time::Duration;
use discrete_pid::{pid, time};
let loop_time = Duration::from_micros(125);
let cfg = pid::PidConfigBuilder::default()
.kp(2.0)
.ki(1.5)
.sample_time(loop_time)
.filter_tc(0.1)
.build()
.expect("Failed to build a PID configuration");
let controller = pid::FuncPidController::new(cfg);
let mut ctx = pid::PidContext::new_uninit();
let pos_meas = 0.5;
let pos_setpoint = 1.0;
let timestamp = time::Micros(125);
let vel_setpoint = 2.0;
let (output, new_ctx) =
controller.compute(ctx, pos_meas, pos_setpoint, timestamp, vel_setpoint.into());
pid-rs: well-known and effective; You may
consider using their crate instead if you:
Are working with simple, slow-acting processes that don't benefit from sample time handling and D-term filtering
Need to use integer process values/setpoints
Need to apply clamping on P, I, and D terms separately
[!WARNING]
We doubt the usefulness of per-term clamping since it breaks linear superposition of the terms, generating subtle nonlinearities and potentially disrupting tuning techniques
pidgeon: Strong
support for synchronization and built-in visualization; You may consider using
their crate instead if you:
std
through std::sync::Mutex📦 View on crates.io
📚 API Docs on docs.rs
This project is licensed under the MIT License © 2025 Hs293Go
Beauregard, B. Improving the Beginner's PID. http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ ↩