pub struct IdentifyProbe { /* private fields */ }Expand description
Excites one loop with a square wave on its setpoint while recording its axis’s body rate and
moment command, then fits a RateModel to them.
Each tick the host hands it the axis’s body rate and the moment it commanded on the last tick; the probe returns the offset to add to the loop’s setpoint. Every loop stays closed, so the fit sees the airframe through its own controllers.
The fit asks how the moment commanded, through a motor lag and a delay, accelerates the
axis. It first fits the rate’s change per tick by least squares to the last two rates and
the recorded moments at each delay from 1 to MAX_DELAY_TICKS, keeping the delay with
the least residual (the shortest of a near-tie) among those whose moment pushes the axis
the way it was pushed (among all when none does). That is exact without noise.
In closed loop, though, the gyro noise is in the measured rate, and the moment carries the
controller’s answer to it, so that fit reads the noise as part of the airframe. When it
leaves more than 0.017 rad/s of the rate’s change per tick unexplained (RMS), the window is
noisy: the probe goes on exciting it to the config’s noisy
length and amplitude, then fits it another way. It filters the recorded moment through each
lag on a grid and each delay, half ticks included, and fits the rate to it (a gain and a
constant for the trim), with both sides integrated: the measured rate only the target, so
the noise in it doesn’t bend the airframe’s terms, and the integration keeps most of the
target’s noise out of the moments it’s fitted to (a
leaky integrator).
Gyro noise still fills that fit’s residual, so the delay with the least residual wins
outright. A noisy window whose moments mostly sit at
the rate loop’s limit (a start that rings) aborts, as no fit reads a clipped moment
through noise.
The probe records the window (26 KB) and fits it on the tick the excitation ends. The
least squares costs about 0.1 ms there on a desktop, the integrated fit about 11 ms (128
lags × 20 delays over an 8 s window), so a noisy window’s last tick runs long. A non-finite
rate or moment is recorded as the last finite one for the integrated fit; the least squares
skips that tick and the next MAX_DELAY_TICKS + 2 while its history refills.
§Examples
use stable_flight::tuning::autotune::COPTER_IDENTIFY;
use stable_flight::tuning::{IdentifyProbe, IdentifyStatus};
let mut probe = IdentifyProbe::new(COPTER_IDENTIFY);
// The square wave starts high: the first tick's offset is the step less its washout.
let offset = probe.step(0.004, 0.0, 0.0);
assert!(offset > 0.0 && offset <= COPTER_IDENTIFY.amplitude);
assert!(matches!(probe.status(), IdentifyStatus::Running { .. }));Implementations§
Source§impl IdentifyProbe
impl IdentifyProbe
Sourcepub fn new(config: IdentifyConfig) -> Self
pub fn new(config: IdentifyConfig) -> Self
Sourcepub fn step(&mut self, dt: f32, rate_radps: f32, last_moment: f32) -> f32
pub fn step(&mut self, dt: f32, rate_radps: f32, last_moment: f32) -> f32
Advances the probe by dt seconds with the axis’s body rate this tick (rad/s) and its
moment command on the last tick, and returns the offset to add to the loop’s setpoint
(0 once it has finished). Fits the model on the tick the excitation ends, past the
config’s duration_s when the window reads noisy there.
§Panics
If dt is not positive and finite.
Sourcepub fn status(&self) -> IdentifyStatus
pub fn status(&self) -> IdentifyStatus
Where the probe stands.
Trait Implementations§
Source§impl Clone for IdentifyProbe
impl Clone for IdentifyProbe
Source§impl Debug for IdentifyProbe
impl Debug for IdentifyProbe
Source§impl PartialEq for IdentifyProbe
impl PartialEq for IdentifyProbe
impl StructuralPartialEq for IdentifyProbe
Auto Trait Implementations§
impl Forget for IdentifyProbe
impl Freeze for IdentifyProbe
impl Move for IdentifyProbe
impl RefUnwindSafe for IdentifyProbe
impl Send for IdentifyProbe
impl Sync for IdentifyProbe
impl Unpin for IdentifyProbe
impl UnsafeUnpin for IdentifyProbe
impl UnwindSafe for IdentifyProbe
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.