Skip to main content

Registry

Struct Registry 

Source
pub struct Registry<T = Timestamp>
where T: TimePoint,
{ pub data: HashMap<String, Buffer<T>>, /* private fields */ }
Expand description

A registry for managing transforms between different frames. It can traverse the parent-child tree and calculate the final transform. It will interpolate between two entries if a time is requested that lies in between.

The Registry struct provides methods to add and retrieve transforms between frames

§Examples

use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
    Registry,
};

use core::time::Duration;
let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::now();

let mut registry = Registry::new();
let t1 = Timestamp::zero();

let t2 = t1.clone();

// Define a transform from frame "a" to frame "b"
let t_a_b_1 = Transform {
    translation: Vector3 {
        x: 1.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t1,
    parent: "a".into(),
    child: "b".into(),
};

// For validation
let t_a_b_2 = t_a_b_1.clone();

// Add the transform to the registry
registry.add_transform(t_a_b_1);

// Retrieve the transform from "a" to "b"
let result = registry.get_transform("a", "b", t2);
assert!(result.is_ok());
assert_eq!(result.unwrap(), t_a_b_2);

Fields§

§data: HashMap<String, Buffer<T>>

Implementations§

Source§

impl<T> Registry<T>
where T: TimePoint,

Source

pub fn new(max_age: Duration) -> Registry<T>

Creates a new Registry with the specified max_age duration.

§Arguments
  • max_age - The duration for which transforms are considered valid.
§Returns

A new instance of Registry.

§Examples
use core::time::Duration;
use transforms::{time::Timestamp, Registry};

let mut registry = Registry::<Timestamp>::new(Duration::from_secs(60));
Source

pub fn add_transform(&mut self, t: Transform<T>)

Adds a transform to the registry.

§Arguments
  • t - The transform to add.
§Examples
use transforms::{geometry::Transform, time::Timestamp, Registry};
use core::time::Duration;
let mut registry = Registry::<Timestamp>::new(Duration::from_secs(60));

let mut registry = Registry::<Timestamp>::new();

let transform = Transform::identity();

registry.add_transform(transform);
Source

pub fn get_transform( &self, from: &str, to: &str, timestamp: T, ) -> Result<Transform<T>, TransformError>

Retrieves a transform from the registry.

§Arguments
  • from - The source frame.
  • to - The destination frame.
  • timestamp - The timestamp for which the transform is requested.
§Errors

Returns a TransformError if the transform cannot be found.

§Examples
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
    Registry,
};
use core::time::Duration;

let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::now();

let mut registry = Registry::new();
let t1 = Timestamp::zero();

let t2 = t1.clone();

// Define a transform from frame "a" to frame "b"
let t_a_b_1 = Transform {
    translation: Vector3 {
        x: 1.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t1,
    parent: "a".into(),
    child: "b".into(),
};
// For validation
let t_a_b_2 = t_a_b_1.clone();

registry.add_transform(t_a_b_1);

let result = registry.get_transform("a", "b", t2);
assert!(result.is_ok());
assert_eq!(result.unwrap(), t_a_b_2);
Source

pub fn get_transform_for<U>( &self, value: &U, target_frame: &str, ) -> Result<Transform<T>, TransformError>
where U: Localized<T>,

Retrieves a transform for a specific value into target_frame.

The source frame and timestamp are taken from the value.

If the value is already in target_frame, this returns an identity transform with parent == child == target_frame and the value’s timestamp.

§Errors

Returns a TransformError if a transform cannot be resolved.

Source

pub fn get_transform_at( &self, target_frame: &str, target_time: T, source_frame: &str, source_time: T, fixed_frame: &str, ) -> Result<Transform<T>, TransformError>

Retrieves a transform between two frames at different timestamps using a fixed frame.

This is the “time travel” API that allows you to get the transform from a source frame at one time to a target frame at a different time. This is useful for scenarios like tracking an object that was detected on a moving platform (e.g., a conveyor belt) and getting its current position in a static world frame.

The algorithm works by:

  1. Computing the transform from source_frame to fixed_frame at source_time
  2. Computing the transform from fixed_frame to target_frame at target_time
  3. Chaining these transforms together
§Arguments
  • target_frame - The destination frame for the transform
  • target_time - The time at which to evaluate the target frame’s position
  • source_frame - The source frame for the transform
  • source_time - The time at which to evaluate the source frame’s position
  • fixed_frame - A frame that does not change over time, used as an intermediate reference point (typically a world or map frame)
§Safety

The caller is responsible for ensuring that fixed_frame is actually stationary between source_time and target_time. Passing a frame that moves between the two timestamps will produce a mathematically meaningless result without any error. Root frames (e.g., "world", "map") that have no parent are always safe choices.

§Errors

Returns a TransformError if any of the required transforms cannot be found at the specified times.

§Examples
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
    Registry,
};
use core::time::Duration;

let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::now();
let t2 = (t1 + Duration::from_secs(1)).unwrap();

let mut registry = Registry::new();
let t1 = Timestamp::zero();
let t2 = Timestamp { t: 1_000_000_000 };

// Tree: fixed -> a -> b

// fixed -> a at t1: a is at x=1
registry.add_transform(Transform {
    translation: Vector3 {
        x: 1.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t1,
    parent: "fixed".into(),
    child: "a".into(),
});

// fixed -> a at t2: a has moved to x=2
registry.add_transform(Transform {
    translation: Vector3 {
        x: 2.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t2,
    parent: "fixed".into(),
    child: "a".into(),
});

// a -> b at t1: b is at y=1 relative to a
registry.add_transform(Transform {
    translation: Vector3 {
        x: 0.0,
        y: 1.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t1,
    parent: "a".into(),
    child: "b".into(),
});

// Express b-at-t1 in a-at-t2, using "fixed" as the stationary reference
let result = registry.get_transform_at(
    "a",     // target_frame
    t2,      // target_time
    "b",     // source_frame
    t1,      // source_time
    "fixed", // fixed_frame
);

assert!(result.is_ok());
Source

pub fn delete_transforms_before(&mut self, timestamp: T)

Removes transforms from every buffer based on the given threshold.

Iterates over all buffers and deletes all entries with a timestamp lower than the input argument.

§Fields
  • timestamp: the time to compare all entries in the buffer with.

Auto Trait Implementations§

§

impl<T> Freeze for Registry<T>

§

impl<T> RefUnwindSafe for Registry<T>
where T: RefUnwindSafe,

§

impl<T> Send for Registry<T>
where T: Send,

§

impl<T> Sync for Registry<T>
where T: Sync,

§

impl<T> Unpin for Registry<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Registry<T>

§

impl<T> UnwindSafe for Registry<T>

Blanket Implementations§

Source§

impl<Source> AccessAs for Source

Source§

fn ref_as<T>(&self) -> <Source as IGuardRef<T>>::Guard<'_>
where Source: IGuardRef<T>, T: ?Sized,

Provides immutable access to a type as if it were its ABI-unstable equivalent.
Source§

fn mut_as<T>(&mut self) -> <Source as IGuardMut<T>>::GuardMut<'_>
where Source: IGuardMut<T>, T: ?Sized,

Provides mutable access to a type as if it were its ABI-unstable equivalent.
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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> AsNode<T> for T

Source§

fn as_node(&self) -> &T

Source§

impl<T> AsNodeMut<T> for T

Source§

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

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, As> IGuardMut<As> for T
where T: Into<As>, As: Into<T>,

Source§

type GuardMut<'a> = MutAs<'a, T, As> where T: 'a

The type of the guard which will clean up the temporary after applying its changes to the original.
Source§

fn guard_mut_inner(&mut self) -> <T as IGuardMut<As>>::GuardMut<'_>

Construct the temporary and guard it through a mutable reference.
Source§

impl<T, As> IGuardRef<As> for T
where T: Into<As>, As: Into<T>,

Source§

type Guard<'a> = RefAs<'a, T, As> where T: 'a

The type of the guard which will clean up the temporary.
Source§

fn guard_ref_inner(&self) -> <T as IGuardRef<As>>::Guard<'_>

Construct the temporary and guard it through an immutable reference.
Source§

impl<T> Includes<End> for T

Source§

type Output = End

The result
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more