pub trait Configurable {
type Config: Copy;
// Required methods
fn config(&self) -> &Self::Config;
fn set_config(&mut self, config: Self::Config) -> Result<(), InvalidConfig>;
}Expand description
A pipeline component whose gains and limits can be read and replaced between ticks.
The config is plain Copy data that the component owns as its single source of truth;
set_config is the one write point and validates before committing,
so a running loop can be retuned without ever flying an invalid config. Implemented by
CopterGuidance and
CopterStabilizer; FlightLoop reaches them
through set_guidance_config and
set_stabilizer_config.
§Examples
use stable_flight::Configurable;
use stable_flight::stabilizers::copter::{CopterStabilizer, CopterStabilizerConfig};
let mut stabilizer = CopterStabilizer::new(CopterStabilizerConfig::default());
let mut retuned = *stabilizer.config();
retuned.body_rate.gains.p = 0.2;
assert!(stabilizer.set_config(retuned).is_ok());
retuned.body_rate.max_integral = -1.0;
assert!(stabilizer.set_config(retuned).is_err());
assert_eq!(stabilizer.config().body_rate.gains.p, 0.2); // unchangedRequired Associated Types§
Required Methods§
Sourcefn set_config(&mut self, config: Self::Config) -> Result<(), InvalidConfig>
fn set_config(&mut self, config: Self::Config) -> Result<(), InvalidConfig>
Replaces the config if it is valid; otherwise keeps the current one and returns the
error. Call it between ticks: the new config applies from the next tick, and runtime
state (integrals, derivative history, timers) is kept. A changed integral gain rescales
its integral so the I term carries over without a bump; across a zero gain the
integral resets (architecture.md#config-ownership).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".