pub struct RecordingTelemetry<const N: usize> { /* private fields */ }Expand description
A telemetry sink that keeps the last N ticks (a fixed-size ring, no allocation) and
counts all of them.
Ticks are stored inline, roughly 200 bytes each, so the recorder is about 200 × N bytes
wherever it lives. Keep N small (hundreds) for a stack-allocated recorder; N = 10_000
overflows a default test thread’s stack. N = 0 only counts.
§Examples
use std::time::Duration;
use stable_flight::testing::RecordingTelemetry;
use stable_flight::{
ActuatorCommand, Command, ControlOutput, Saturation, Setpoint, TelemetryPublisher,
TelemetryRecord, VehicleState,
};
let mut telemetry = RecordingTelemetry::<2>::new();
for thrust in [0.1, 0.2, 0.3] {
telemetry.publish(&TelemetryRecord {
dt: Duration::from_millis(4),
command: &Command::default(),
setpoint: &Setpoint::Attitude(Default::default()),
state: &VehicleState::default(),
control: &ControlOutput { thrust, ..Default::default() },
actuators: &ActuatorCommand::default(),
saturation: Saturation::default(),
failsafe: None,
flight_mode: Default::default(),
wind: None,
});
}
assert_eq!(telemetry.total(), 3);
let kept: Vec<f32> = telemetry.iter().map(|tick| tick.control.thrust).collect();
assert_eq!(kept, [0.2, 0.3]); // oldest first; 0.1 was overwrittenImplementations§
Source§impl<const N: usize> RecordingTelemetry<N>
impl<const N: usize> RecordingTelemetry<N>
Sourcepub fn last(&self) -> Option<&RecordedTick>
pub fn last(&self) -> Option<&RecordedTick>
The most recent tick, if any.
Sourcepub fn iter(&self) -> impl Iterator<Item = &RecordedTick>
pub fn iter(&self) -> impl Iterator<Item = &RecordedTick>
The kept ticks, oldest first (at most N).
Trait Implementations§
Source§impl<const N: usize> Clone for RecordingTelemetry<N>
impl<const N: usize> Clone for RecordingTelemetry<N>
Source§impl<const N: usize> Debug for RecordingTelemetry<N>
impl<const N: usize> Debug for RecordingTelemetry<N>
Source§impl<const N: usize> Default for RecordingTelemetry<N>
impl<const N: usize> Default for RecordingTelemetry<N>
Source§impl<const N: usize> TelemetryPublisher for RecordingTelemetry<N>
impl<const N: usize> TelemetryPublisher for RecordingTelemetry<N>
Source§fn publish(&mut self, record: &TelemetryRecord<'_>)
fn publish(&mut self, record: &TelemetryRecord<'_>)
Publishes one control-loop tick to external systems. Read more
Auto Trait Implementations§
impl<const N: usize> Freeze for RecordingTelemetry<N>
impl<const N: usize> RefUnwindSafe for RecordingTelemetry<N>
impl<const N: usize> Send for RecordingTelemetry<N>
impl<const N: usize> Sync for RecordingTelemetry<N>
impl<const N: usize> Unpin for RecordingTelemetry<N>
impl<const N: usize> UnsafeUnpin for RecordingTelemetry<N>
impl<const N: usize> UnwindSafe for RecordingTelemetry<N>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.