pub struct ConstTransformBuffer<T: Copy + Debug + Default + 'static, const N: usize> { /* private fields */ }
Expand description
Constant-size transform buffer using fixed arrays (no dynamic allocation)
Implementations§
Source§impl<T: Copy + Debug + Default + 'static, const N: usize> ConstTransformBuffer<T, N>
impl<T: Copy + Debug + Default + 'static, const N: usize> ConstTransformBuffer<T, N>
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/basic_usage.rs (line 109)
9fn main() {
10 // Example using the typed transform approach
11 println!("Cu Transform - New Typed Approach Demo");
12 println!("=====================================");
13
14 // Create a buffer for world -> robot transforms
15 let mut world_to_robot_buffer: TypedTransformBuffer<f32, WorldFrame, RobotFrame, 10> =
16 TypedTransformBuffer::new();
17
18 // Create a transform message
19 let transform = Transform3D::from_matrix([
20 [1.0, 0.0, 0.0, 1.0], // X translation
21 [0.0, 1.0, 0.0, 2.0], // Y translation
22 [0.0, 0.0, 1.0, 0.0],
23 [0.0, 0.0, 0.0, 1.0],
24 ]);
25
26 let world_to_robot_msg = TypedTransform::new(transform, CuDuration(1000));
27
28 println!(
29 "Created transform from {} to {}",
30 world_to_robot_msg.parent_name(),
31 world_to_robot_msg.child_name()
32 );
33 if let Some(t) = world_to_robot_msg.transform() {
34 let mat = t.to_matrix();
35 println!(
36 " Translation: [{}, {}, {}]",
37 mat[0][3], mat[1][3], mat[2][3]
38 );
39 }
40
41 // Add to buffer
42 world_to_robot_buffer.add_transform(world_to_robot_msg);
43
44 // Create second transform
45 let transform2 = Transform3D::from_matrix([
46 [1.0, 0.0, 0.0, 2.0], // X translation
47 [0.0, 1.0, 0.0, 4.0], // Y translation
48 [0.0, 0.0, 1.0, 0.0],
49 [0.0, 0.0, 0.0, 1.0],
50 ]);
51
52 let world_to_robot_msg2 = TypedTransform::new(transform2, CuDuration(2000));
53 world_to_robot_buffer.add_transform(world_to_robot_msg2);
54
55 // Query the buffer
56 if let Some(latest) = world_to_robot_buffer.get_latest_transform() {
57 println!(
58 "\nLatest transform at time {}:",
59 latest.timestamp().unwrap().as_nanos()
60 );
61 if let Some(t) = latest.transform() {
62 let mat = t.to_matrix();
63 println!(
64 " Translation: [{}, {}, {}]",
65 mat[0][3], mat[1][3], mat[2][3]
66 );
67 }
68 }
69
70 // Query closest to a specific time
71 if let Some(closest) = world_to_robot_buffer.get_closest_transform(CuDuration(1500)) {
72 println!("\nClosest transform to time 1500:");
73 println!(" Actual time: {}", closest.timestamp().unwrap().as_nanos());
74 if let Some(t) = closest.transform() {
75 let mat = t.to_matrix();
76 println!(
77 " Translation: [{}, {}, {}]",
78 mat[0][3], mat[1][3], mat[2][3]
79 );
80 }
81 }
82
83 // Demonstrate time range
84 if let Some(range) = world_to_robot_buffer.get_time_range() {
85 println!(
86 "\nTime range: {} to {}",
87 range.start.as_nanos(),
88 range.end.as_nanos()
89 );
90 }
91
92 // Demonstrate velocity computation
93 if let Some(latest) = world_to_robot_buffer.get_latest_transform() {
94 if let Some(closest) = world_to_robot_buffer.get_closest_transform(CuDuration(1000)) {
95 if let Some(velocity) = latest.compute_velocity(closest) {
96 println!("\nVelocity computation:");
97 println!(
98 " Linear velocity: [{}, {}, {}]",
99 velocity.linear[0], velocity.linear[1], velocity.linear[2]
100 );
101 }
102 }
103 }
104
105 // Demonstrate the stringly typed version of the API.
106 println!("\n\nConstant-Size Buffer Demo");
107 println!("===========================================");
108
109 let mut const_buffer: ConstTransformBuffer<f32, 5> = ConstTransformBuffer::new();
110
111 // Add some stamped transforms
112 let stamped_transform = StampedTransform {
113 transform,
114 stamp: CuDuration(1000),
115 parent_frame: "world".try_into().unwrap(),
116 child_frame: "robot".try_into().unwrap(),
117 };
118
119 const_buffer.add_transform(stamped_transform);
120
121 if let Some(latest_stamped) = const_buffer.get_latest_transform() {
122 println!("Latest transform in constant buffer:");
123 println!(
124 " From: {} to: {}",
125 latest_stamped.parent_frame, latest_stamped.child_frame
126 );
127 println!(" Time: {}", latest_stamped.stamp.as_nanos());
128 let mat = latest_stamped.transform.to_matrix();
129 println!(
130 " Translation: [{}, {}, {}]",
131 mat[0][3], mat[1][3], mat[2][3]
132 );
133 }
134
135 println!("\nThis buffer is stack-allocated with capacity 5 - no heap allocation!");
136
137 // Demonstrate the StampedFrameTransform pattern with TransformTree
138 println!("\n\nStampedFrameTransform Pattern Demo");
139 println!("================================");
140
141 let mut tree = TransformTree::<f32>::new();
142
143 // Create a CuMsg with TransformMsg
144 let frame_transform = FrameTransform::new(
145 transform,
146 FrameIdString::from("world").expect("Frame name too long"),
147 FrameIdString::from("robot").expect("Frame name too long"),
148 );
149
150 let mut sft = StampedFrameTransform::new(Some(frame_transform));
151 sft.tov = Tov::Time(CuDuration(1_000_000_000)); // 1 second
152
153 // Add using the new API
154 tree.add_transform(&sft).expect("Failed to add transform");
155 println!("Added transform using CuMsg<TransformMsg> pattern");
156
157 // Query the transform
158 let robot_clock = cu29::clock::RobotClock::default();
159 let result = tree.lookup_transform("world", "robot", CuDuration(1_000_000_000), &robot_clock);
160
161 match result {
162 Ok(transform) => {
163 let mat = transform.to_matrix();
164 println!(
165 "Retrieved transform: translation=({:.2}, {:.2}, {:.2})",
166 mat[3][0], mat[3][1], mat[3][2]
167 );
168 }
169 Err(e) => println!("Error: {e}"),
170 }
171}
Sourcepub fn add_transform(&mut self, transform: StampedTransform<T>)
pub fn add_transform(&mut self, transform: StampedTransform<T>)
Add a transform to the buffer, maintaining time ordering
Examples found in repository?
examples/basic_usage.rs (line 119)
9fn main() {
10 // Example using the typed transform approach
11 println!("Cu Transform - New Typed Approach Demo");
12 println!("=====================================");
13
14 // Create a buffer for world -> robot transforms
15 let mut world_to_robot_buffer: TypedTransformBuffer<f32, WorldFrame, RobotFrame, 10> =
16 TypedTransformBuffer::new();
17
18 // Create a transform message
19 let transform = Transform3D::from_matrix([
20 [1.0, 0.0, 0.0, 1.0], // X translation
21 [0.0, 1.0, 0.0, 2.0], // Y translation
22 [0.0, 0.0, 1.0, 0.0],
23 [0.0, 0.0, 0.0, 1.0],
24 ]);
25
26 let world_to_robot_msg = TypedTransform::new(transform, CuDuration(1000));
27
28 println!(
29 "Created transform from {} to {}",
30 world_to_robot_msg.parent_name(),
31 world_to_robot_msg.child_name()
32 );
33 if let Some(t) = world_to_robot_msg.transform() {
34 let mat = t.to_matrix();
35 println!(
36 " Translation: [{}, {}, {}]",
37 mat[0][3], mat[1][3], mat[2][3]
38 );
39 }
40
41 // Add to buffer
42 world_to_robot_buffer.add_transform(world_to_robot_msg);
43
44 // Create second transform
45 let transform2 = Transform3D::from_matrix([
46 [1.0, 0.0, 0.0, 2.0], // X translation
47 [0.0, 1.0, 0.0, 4.0], // Y translation
48 [0.0, 0.0, 1.0, 0.0],
49 [0.0, 0.0, 0.0, 1.0],
50 ]);
51
52 let world_to_robot_msg2 = TypedTransform::new(transform2, CuDuration(2000));
53 world_to_robot_buffer.add_transform(world_to_robot_msg2);
54
55 // Query the buffer
56 if let Some(latest) = world_to_robot_buffer.get_latest_transform() {
57 println!(
58 "\nLatest transform at time {}:",
59 latest.timestamp().unwrap().as_nanos()
60 );
61 if let Some(t) = latest.transform() {
62 let mat = t.to_matrix();
63 println!(
64 " Translation: [{}, {}, {}]",
65 mat[0][3], mat[1][3], mat[2][3]
66 );
67 }
68 }
69
70 // Query closest to a specific time
71 if let Some(closest) = world_to_robot_buffer.get_closest_transform(CuDuration(1500)) {
72 println!("\nClosest transform to time 1500:");
73 println!(" Actual time: {}", closest.timestamp().unwrap().as_nanos());
74 if let Some(t) = closest.transform() {
75 let mat = t.to_matrix();
76 println!(
77 " Translation: [{}, {}, {}]",
78 mat[0][3], mat[1][3], mat[2][3]
79 );
80 }
81 }
82
83 // Demonstrate time range
84 if let Some(range) = world_to_robot_buffer.get_time_range() {
85 println!(
86 "\nTime range: {} to {}",
87 range.start.as_nanos(),
88 range.end.as_nanos()
89 );
90 }
91
92 // Demonstrate velocity computation
93 if let Some(latest) = world_to_robot_buffer.get_latest_transform() {
94 if let Some(closest) = world_to_robot_buffer.get_closest_transform(CuDuration(1000)) {
95 if let Some(velocity) = latest.compute_velocity(closest) {
96 println!("\nVelocity computation:");
97 println!(
98 " Linear velocity: [{}, {}, {}]",
99 velocity.linear[0], velocity.linear[1], velocity.linear[2]
100 );
101 }
102 }
103 }
104
105 // Demonstrate the stringly typed version of the API.
106 println!("\n\nConstant-Size Buffer Demo");
107 println!("===========================================");
108
109 let mut const_buffer: ConstTransformBuffer<f32, 5> = ConstTransformBuffer::new();
110
111 // Add some stamped transforms
112 let stamped_transform = StampedTransform {
113 transform,
114 stamp: CuDuration(1000),
115 parent_frame: "world".try_into().unwrap(),
116 child_frame: "robot".try_into().unwrap(),
117 };
118
119 const_buffer.add_transform(stamped_transform);
120
121 if let Some(latest_stamped) = const_buffer.get_latest_transform() {
122 println!("Latest transform in constant buffer:");
123 println!(
124 " From: {} to: {}",
125 latest_stamped.parent_frame, latest_stamped.child_frame
126 );
127 println!(" Time: {}", latest_stamped.stamp.as_nanos());
128 let mat = latest_stamped.transform.to_matrix();
129 println!(
130 " Translation: [{}, {}, {}]",
131 mat[0][3], mat[1][3], mat[2][3]
132 );
133 }
134
135 println!("\nThis buffer is stack-allocated with capacity 5 - no heap allocation!");
136
137 // Demonstrate the StampedFrameTransform pattern with TransformTree
138 println!("\n\nStampedFrameTransform Pattern Demo");
139 println!("================================");
140
141 let mut tree = TransformTree::<f32>::new();
142
143 // Create a CuMsg with TransformMsg
144 let frame_transform = FrameTransform::new(
145 transform,
146 FrameIdString::from("world").expect("Frame name too long"),
147 FrameIdString::from("robot").expect("Frame name too long"),
148 );
149
150 let mut sft = StampedFrameTransform::new(Some(frame_transform));
151 sft.tov = Tov::Time(CuDuration(1_000_000_000)); // 1 second
152
153 // Add using the new API
154 tree.add_transform(&sft).expect("Failed to add transform");
155 println!("Added transform using CuMsg<TransformMsg> pattern");
156
157 // Query the transform
158 let robot_clock = cu29::clock::RobotClock::default();
159 let result = tree.lookup_transform("world", "robot", CuDuration(1_000_000_000), &robot_clock);
160
161 match result {
162 Ok(transform) => {
163 let mat = transform.to_matrix();
164 println!(
165 "Retrieved transform: translation=({:.2}, {:.2}, {:.2})",
166 mat[3][0], mat[3][1], mat[3][2]
167 );
168 }
169 Err(e) => println!("Error: {e}"),
170 }
171}
Sourcepub fn get_latest_transform(&self) -> Option<&StampedTransform<T>>
pub fn get_latest_transform(&self) -> Option<&StampedTransform<T>>
Examples found in repository?
examples/basic_usage.rs (line 121)
9fn main() {
10 // Example using the typed transform approach
11 println!("Cu Transform - New Typed Approach Demo");
12 println!("=====================================");
13
14 // Create a buffer for world -> robot transforms
15 let mut world_to_robot_buffer: TypedTransformBuffer<f32, WorldFrame, RobotFrame, 10> =
16 TypedTransformBuffer::new();
17
18 // Create a transform message
19 let transform = Transform3D::from_matrix([
20 [1.0, 0.0, 0.0, 1.0], // X translation
21 [0.0, 1.0, 0.0, 2.0], // Y translation
22 [0.0, 0.0, 1.0, 0.0],
23 [0.0, 0.0, 0.0, 1.0],
24 ]);
25
26 let world_to_robot_msg = TypedTransform::new(transform, CuDuration(1000));
27
28 println!(
29 "Created transform from {} to {}",
30 world_to_robot_msg.parent_name(),
31 world_to_robot_msg.child_name()
32 );
33 if let Some(t) = world_to_robot_msg.transform() {
34 let mat = t.to_matrix();
35 println!(
36 " Translation: [{}, {}, {}]",
37 mat[0][3], mat[1][3], mat[2][3]
38 );
39 }
40
41 // Add to buffer
42 world_to_robot_buffer.add_transform(world_to_robot_msg);
43
44 // Create second transform
45 let transform2 = Transform3D::from_matrix([
46 [1.0, 0.0, 0.0, 2.0], // X translation
47 [0.0, 1.0, 0.0, 4.0], // Y translation
48 [0.0, 0.0, 1.0, 0.0],
49 [0.0, 0.0, 0.0, 1.0],
50 ]);
51
52 let world_to_robot_msg2 = TypedTransform::new(transform2, CuDuration(2000));
53 world_to_robot_buffer.add_transform(world_to_robot_msg2);
54
55 // Query the buffer
56 if let Some(latest) = world_to_robot_buffer.get_latest_transform() {
57 println!(
58 "\nLatest transform at time {}:",
59 latest.timestamp().unwrap().as_nanos()
60 );
61 if let Some(t) = latest.transform() {
62 let mat = t.to_matrix();
63 println!(
64 " Translation: [{}, {}, {}]",
65 mat[0][3], mat[1][3], mat[2][3]
66 );
67 }
68 }
69
70 // Query closest to a specific time
71 if let Some(closest) = world_to_robot_buffer.get_closest_transform(CuDuration(1500)) {
72 println!("\nClosest transform to time 1500:");
73 println!(" Actual time: {}", closest.timestamp().unwrap().as_nanos());
74 if let Some(t) = closest.transform() {
75 let mat = t.to_matrix();
76 println!(
77 " Translation: [{}, {}, {}]",
78 mat[0][3], mat[1][3], mat[2][3]
79 );
80 }
81 }
82
83 // Demonstrate time range
84 if let Some(range) = world_to_robot_buffer.get_time_range() {
85 println!(
86 "\nTime range: {} to {}",
87 range.start.as_nanos(),
88 range.end.as_nanos()
89 );
90 }
91
92 // Demonstrate velocity computation
93 if let Some(latest) = world_to_robot_buffer.get_latest_transform() {
94 if let Some(closest) = world_to_robot_buffer.get_closest_transform(CuDuration(1000)) {
95 if let Some(velocity) = latest.compute_velocity(closest) {
96 println!("\nVelocity computation:");
97 println!(
98 " Linear velocity: [{}, {}, {}]",
99 velocity.linear[0], velocity.linear[1], velocity.linear[2]
100 );
101 }
102 }
103 }
104
105 // Demonstrate the stringly typed version of the API.
106 println!("\n\nConstant-Size Buffer Demo");
107 println!("===========================================");
108
109 let mut const_buffer: ConstTransformBuffer<f32, 5> = ConstTransformBuffer::new();
110
111 // Add some stamped transforms
112 let stamped_transform = StampedTransform {
113 transform,
114 stamp: CuDuration(1000),
115 parent_frame: "world".try_into().unwrap(),
116 child_frame: "robot".try_into().unwrap(),
117 };
118
119 const_buffer.add_transform(stamped_transform);
120
121 if let Some(latest_stamped) = const_buffer.get_latest_transform() {
122 println!("Latest transform in constant buffer:");
123 println!(
124 " From: {} to: {}",
125 latest_stamped.parent_frame, latest_stamped.child_frame
126 );
127 println!(" Time: {}", latest_stamped.stamp.as_nanos());
128 let mat = latest_stamped.transform.to_matrix();
129 println!(
130 " Translation: [{}, {}, {}]",
131 mat[0][3], mat[1][3], mat[2][3]
132 );
133 }
134
135 println!("\nThis buffer is stack-allocated with capacity 5 - no heap allocation!");
136
137 // Demonstrate the StampedFrameTransform pattern with TransformTree
138 println!("\n\nStampedFrameTransform Pattern Demo");
139 println!("================================");
140
141 let mut tree = TransformTree::<f32>::new();
142
143 // Create a CuMsg with TransformMsg
144 let frame_transform = FrameTransform::new(
145 transform,
146 FrameIdString::from("world").expect("Frame name too long"),
147 FrameIdString::from("robot").expect("Frame name too long"),
148 );
149
150 let mut sft = StampedFrameTransform::new(Some(frame_transform));
151 sft.tov = Tov::Time(CuDuration(1_000_000_000)); // 1 second
152
153 // Add using the new API
154 tree.add_transform(&sft).expect("Failed to add transform");
155 println!("Added transform using CuMsg<TransformMsg> pattern");
156
157 // Query the transform
158 let robot_clock = cu29::clock::RobotClock::default();
159 let result = tree.lookup_transform("world", "robot", CuDuration(1_000_000_000), &robot_clock);
160
161 match result {
162 Ok(transform) => {
163 let mat = transform.to_matrix();
164 println!(
165 "Retrieved transform: translation=({:.2}, {:.2}, {:.2})",
166 mat[3][0], mat[3][1], mat[3][2]
167 );
168 }
169 Err(e) => println!("Error: {e}"),
170 }
171}
pub fn get_time_range(&self) -> Option<CuTimeRange>
pub fn get_transforms_in_range( &self, start_time: CuTime, end_time: CuTime, ) -> Vec<&StampedTransform<T>>
pub fn get_closest_transform( &self, time: CuTime, ) -> Option<&StampedTransform<T>>
Trait Implementations§
Source§impl<T: Clone + Copy + Debug + Default + 'static, const N: usize> Clone for ConstTransformBuffer<T, N>
impl<T: Clone + Copy + Debug + Default + 'static, const N: usize> Clone for ConstTransformBuffer<T, N>
Source§fn clone(&self) -> ConstTransformBuffer<T, N>
fn clone(&self) -> ConstTransformBuffer<T, N>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T, const N: usize> Freeze for ConstTransformBuffer<T, N>
impl<T, const N: usize> RefUnwindSafe for ConstTransformBuffer<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for ConstTransformBuffer<T, N>where
T: Send,
impl<T, const N: usize> Sync for ConstTransformBuffer<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for ConstTransformBuffer<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for ConstTransformBuffer<T, N>where
T: UnwindSafe,
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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