Skip to main content

RecordingTelemetry

Struct RecordingTelemetry 

Source
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,
    });
}

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 overwritten

Implementations§

Source§

impl<const N: usize> RecordingTelemetry<N>

Source

pub fn new() -> Self

An empty recorder.

Source

pub fn total(&self) -> u64

Ticks published so far, including ones no longer kept.

Source

pub fn last(&self) -> Option<&RecordedTick>

The most recent tick, if any.

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for RecordingTelemetry<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for RecordingTelemetry<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> TelemetryPublisher for RecordingTelemetry<N>

Source§

fn publish(&mut self, record: &TelemetryRecord<'_>)

Publishes one control-loop tick to external systems. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.