-
Notifications
You must be signed in to change notification settings - Fork 718
memory2 tf service #2707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+490
−258
Merged
memory2 tf service #2707
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a1ab537
*lio publishes pointclouds in IMU frame, no mention of body
leshy 73f9e67
go2 3d nav odom fix
leshy e57ce74
StreamTF: tf service over a recorded memory2 stream
leshy 8a6ce7e
Merge remote-tracking branch 'origin/main' into fix/ivan/dataset_tf
leshy 90c1f2d
comments cleanup
leshy 42034cb
type fix
leshy b80dc7e
Merge branch 'main' into feat/ivan/memtf
leshy 1ce8306
small cleanup
leshy d7bf5f7
mac skip
leshy 2fabfdd
mac skip
leshy 1508acf
Merge branch 'feat/ivan/memtf' of github.com:dimensionalOS/dimos into…
leshy 181290d
Merge branch 'main' into feat/ivan/memtf
leshy 6cc57ae
Merge remote-tracking branch 'origin/main' into feat/ivan/memtf
leshy b7a9ee9
map uses obs.pose as a backup
leshy d45c284
hold _cv across _ensure's check-clear-reload
leshy 26b6fcd
Merge branch 'feat/ivan/memtf' of github.com:dimensionalOS/dimos into…
leshy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Copyright 2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """TF service backed by a recorded ``tf`` stream.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import math | ||
| from typing import TYPE_CHECKING, Any, cast | ||
|
|
||
| from dimos.memory2.stream import Stream | ||
| from dimos.msgs.tf2_msgs.TFMessage import TFMessage | ||
| from dimos.protocol.tf.tf import MultiTBuffer, TFConfig, TFSpec | ||
|
|
||
| if TYPE_CHECKING: | ||
| from dimos.msgs.geometry_msgs.Transform import Transform | ||
| from dimos.protocol.tf.tf import TFLookup | ||
|
|
||
|
|
||
| class StreamTFConfig(TFConfig): | ||
| stream: Stream[TFMessage] | None = ( | ||
| None # Required field but needs default for config inheritance | ||
| ) | ||
| cache_span: float = 300.0 | ||
|
|
||
|
|
||
| class StreamTF(MultiTBuffer, TFSpec): | ||
| config: StreamTFConfig | ||
|
|
||
| def __init__(self, stream: Stream[TFMessage] | None = None, **kwargs: Any) -> None: | ||
| if stream is not None: | ||
| kwargs["stream"] = stream | ||
| TFSpec.__init__(self, **kwargs) | ||
| MultiTBuffer.__init__(self, buffer_size=math.inf) | ||
|
|
||
| if self.config.stream is None: | ||
| raise ValueError("Stream configuration is missing") | ||
| self.stream = self.config.stream | ||
|
|
||
| self._covered: tuple[float, float] | None = None | ||
|
|
||
| @classmethod | ||
| def from_store(cls, store: Any, stream: str = "tf") -> StreamTF | None: | ||
| if stream not in store.list_streams(): | ||
| return None | ||
| return cls(store.stream(stream, TFMessage)) | ||
|
|
||
| def publish(self, *args: Transform) -> None: | ||
| raise NotImplementedError("StreamTF is a read-only replay service.") | ||
|
|
||
| def publish_static(self, *args: Transform) -> None: | ||
| raise NotImplementedError("StreamTF is a read-only replay service.") | ||
|
|
||
| def _load(self, lo: float, hi: float) -> None: | ||
| for obs in self.stream.at((lo + hi) / 2, (hi - lo) / 2): | ||
| self.receive_transform(*obs.data.transforms) | ||
| self._covered = (lo, hi) | ||
|
leshy marked this conversation as resolved.
|
||
|
|
||
| def _ensure(self, lo: float, hi: float) -> None: | ||
| """Serve ``[lo, hi]`` from the cache, else re-cache ``[lo, hi + cache_span]``.""" | ||
| with self._cv: | ||
| if self._covered is not None: | ||
| clo, chi = self._covered | ||
| if clo <= lo and hi <= chi: | ||
| return | ||
| self.buffers.clear() | ||
| self._covered = None | ||
| self._load(lo, hi + self.config.cache_span) | ||
|
|
||
| def get( | ||
| self, | ||
| parent_frame: str, | ||
| child_frame: str, | ||
| time_point: float | None = None, | ||
| time_tolerance: float | None = None, | ||
| *, | ||
| forward_tolerance: float = 0.0, | ||
| ) -> Transform | None: | ||
| tp = time_point | ||
| if tp is None: | ||
| last = next(iter(self.stream.order_by("ts", desc=True).limit(1)), None) | ||
| tp = last.ts if last is not None else None | ||
|
|
||
| if tp is not None: | ||
| back = time_tolerance if time_tolerance is not None else self.config.buffer_size | ||
| fwd = time_tolerance if time_tolerance is not None else forward_tolerance | ||
| self._ensure(tp - back, tp + fwd) | ||
|
leshy marked this conversation as resolved.
|
||
|
|
||
| return super().get( | ||
| parent_frame, | ||
| child_frame, | ||
| time_point, | ||
| time_tolerance, | ||
| forward_tolerance=0.0, | ||
| ) | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| # mypy conformance check: StreamTF satisfies the read-side tf protocol. | ||
| _lookup_impl: TFLookup = cast("StreamTF", None) | ||
|
leshy marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.