| Crates.io | pidgeon |
| lib.rs | pidgeon |
| version | 0.2.2 |
| created_at | 2025-03-08 22:24:36.695015+00 |
| updated_at | 2025-03-22 23:46:16.26643+00 |
| description | A robust, thread-safe PID controller library written in Rust |
| homepage | |
| repository | https://github.com/security-union/pidgeon |
| max_upload_size | |
| id | 1584865 |
| size | 721,385 |
Pidgeon is a high-performance, thread-safe PID controller library written in Rust.
The name pays homage to history's most battle-tested messengers. In both World Wars, carrier pigeons maintained 95% delivery rates [^1] while flying through artillery barrages, poison gas, and enemy lines. Cher Ami, a famous war pidgeon, delivered a critical message despite losing a leg, an eye, and being shot through the chest. Like these feathered veterans, our PID controller is engineered to perform reliably when everything else fails. It might not win the Croix de Guerre like Cher Ami did, but it'll survive your chaotic production environment with the same unflappable determination.
Pidgeon is designed for developers who need a robust, high-performance PID controller for real-time control applications. Whether you're building a drone, a robot, or a smart thermostat, Pidgeon provides the precision and reliability you need to keep your system on track.
Clone trait so that you can easily share the controller across threads.cargo run --example drone_altitude_control
The visualization above shows our PID controller in action, maintaining a quadcopter's altitude despite various disturbances. This simulator models real-world drone physics including:
The visualization demonstrates how the PID controller responds to these challenges:
Each of these scenarios demonstrates real-world challenges that PID controllers solve elegantly. The beautiful visualization makes it easy to understand the relationship between altitude, velocity, thrust adjustments, and error over time.
This example demonstrates how to create a Controller, please refer to the examples directory for complete programs.
use pidgeon::{ControllerConfig, ThreadSafePidController};
use rand::{thread_rng, Rng};
use std::{
io::{self, Write},
thread,
time::Duration,
};
const SETPOINT_ALTITUDE: f64 = 10.0; // Target altitude in meters
fn main() {
// Create a PID controller with carefully tuned gains for altitude control
let config = ControllerConfig::new()
.with_kp(10.0) // Proportional gain - immediate response to altitude error
.with_ki(5.0) // Integral gain - eliminates steady-state error (hovering accuracy)
.with_kd(8.0) // Derivative gain - dampens oscillations (crucial for stability)
.with_output_limits(0.0, 100.0) // Thrust percentage (0-100%)
.with_setpoint(SETPOINT_ALTITUDE)
.with_deadband(0.0) // Set deadband to zero for exact tracking to setpoint
.with_anti_windup(true); // Prevent integral term accumulation when saturated
let controller = ThreadSafePidController::new(config);
}
Pidgeon is licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Pidgeon is designed for high-performance control applications:
| Benchmark | Time (ns) | Operations/sec | Description |
|---|---|---|---|
pid_compute |
394.23 ns | 2,536,590/s | Single-threaded processing of 100 consecutive updates |
thread_safe_pid_compute |
673.21 ns | 1,485,420/s | Thread-safe controller without concurrent access |
multi_threaded_pid |
26,144 ns | 38,250/s | Concurrent access with updating and reading threads |
cargo bench --package pidgeon --features benchmarks
run_pidgeon_demo.shExperience Pidgeon in action with our comprehensive demo application! The run_pidgeon_demo.sh script launches a complete demonstration environment:
./run_pidgeon_demo.sh
This script starts:
The demo provides:
The web-based interface allows you to observe the PID controller's performance as it manages temperature control, with live graphs showing setpoint, actual temperature, and control signals.
# After starting the demo:
# 1. The script launches the Pidgeoneer web server
# 2. Opens your browser to http://localhost:3000
# 3. Waits for you to press 'S' to start the actual PID controller
# 4. Press Ctrl+C when you're done to clean up all processes
Pidgeon provides comprehensive debugging capabilities to assist with controller tuning and analysis:
Enable debugging by adding the debugging feature to your Cargo.toml:
# In your Cargo.toml
[dependencies]
pidgeon = { version = "1.0", features = ["debugging"] }
Configuration example:
use pidgeon::{ControllerConfig, ThreadSafePidController, DebugConfig};
// Create your controller configuration
let config = ControllerConfig::new()
.with_kp(2.0)
.with_ki(0.1)
.with_kd(0.5)
.with_output_limits(-100.0, 100.0)
.with_anti_windup(true)
.with_setpoint(22.0);
// Create debug configuration to stream data to Iggy
let debug_config = DebugConfig {
iggy_url: "127.0.0.1:8090".to_string(),
stream_name: "pidgeon_debug".to_string(),
topic_name: "controller_data".to_string(),
controller_id: "temperature_controller".to_string(),
sample_rate_hz: Some(10.0), // 10Hz sample rate
};
// Create controller with debugging enabled
let controller = ThreadSafePidController::new(config)
.with_debugging(debug_config)
.expect("Failed to initialize controller with debugging");
// Your controller is now streaming debug data to Iggy
// which can be visualized in real-time using Pidgeoneer!
When you run the application, all controller data is streamed to the configured Iggy server, where it can be visualized and analyzed in real-time through the Pidgeoneer dashboard. This gives you unprecedented visibility into your controller's behavior without compromising performance.
In production environments, monitoring your PID controllers is just as critical as tuning them properly. That's why Pidgeon integrates with Iggy.rs - the blazing-fast, rock-solid streaming platform built in Rust.
Traditional logging methods fall short for real-time control systems:
Iggy.rs provides the perfect solution for streaming controller telemetry:
Every aspect of your controller's performance is captured in real-time:
When we evaluated streaming platforms for Pidgeon, Iggy.rs stood out for several reasons:
As the hottest streaming platform in the Rust ecosystem, Iggy was the obvious choice for Pidgeon. When your PID controller is making mission-critical decisions thousands of times per second, you need diagnostics that can keep up.
A PID (Proportional-Integral-Derivative) controller is a control loop mechanism that continuously calculates an error value as the difference between a desired setpoint and a measured process variable, then applies a correction based on proportional, integral, and derivative terms.
Proportional (P): Produces an output proportional to the current error value. A high proportional gain results in a large change in output for a given change in error.
Integral (I): Accumulates the error over time. It addresses steady-state errors and helps the system reach the setpoint even with persistent disturbances or biases.
Derivative (D): Calculates the rate of change of the error. This helps predict system behavior and reduces overshoot and oscillation.
The control output is calculated as:
u(t) = Kp * e(t) + Ki * ∫e(τ)dτ + Kd * de(t)/dt
Where:
PID controllers have been in use since the early 20th century, with the first formal analysis published by Nicolas Minorsky in 1922. They became widely adopted in industrial control systems in the 1940s and have remained the most commonly used control algorithm for over 80 years.
Despite their relatively simple formulation, PID controllers are used in an astonishing variety of applications:
An estimated 95% of all control loops in industrial automation use PID control, often as the fundamental building block of more complex control systems.
PID controllers remain ubiquitous for several reasons:
While more advanced control algorithms exist (model predictive control, adaptive control, fuzzy logic), PID control often provides the best balance of performance, complexity, and reliability.
In the words of control theorist Karl Åström: "PID control is an important technology that has survived many changes in technology, from mechanics and pneumatics to microprocessors via electronic tubes, transistors, integrated circuits."
[^1] In the Era of Electronic Warfare, Bring Back Pigeons warontherocks.com
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.