[−][src]Module msr::pid
PID controller
Example
use msr::{TimeStepController, pid::*}; use std::{thread, time::Duration}; // 1. Create the PID configuration let mut cfg = PidConfig::default(); cfg.k_p = 2.5; // define the proportional coefficient cfg.k_i = 0.7; // define the integral coefficient cfg.k_d = 5.0; // define the derative coefficient // 2. Create the PID controller let mut pid = Pid::new(cfg); // 3. Set the desired target pid.set_target(33.7); // 4. Define the duration between two steps let delta_t = Duration::from_millis(1000); // 5. Calculate the values loop { // 1. Fetch the current sensor value. // Here you'd use s.th. like a `read_sensor` method. let sensor_value = 11.0; // 2. Calculate the next step let actuator_value = pid.next(sensor_value, &delta_t); // 3. Set the actuator // Here you'd use s.th. like a `write_actuator` method. // 4. Wait some time thread::sleep(delta_t); }
Structs
Pid | PID controller implementation |
PidConfig | PID Configuration |
PidState | Internal PID controller state |