Skip to content

Commit 6e554f2

Browse files
committed
feat: calibration cache for realsense
1 parent c549d3c commit 6e554f2

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

extensions/rcs_realsense/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies = [
1010
"rcs==0.4.0",
1111
"pyrealsense2~=2.55.1",
1212
"apriltag==0.0.16",
13+
"diskcache",
1314
]
1415
readme = "README.md"
1516
maintainers = [

extensions/rcs_realsense/src/rcs_realsense/calibration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from pathlib import Path
23
import threading
34
import typing
45
from time import sleep
@@ -10,6 +11,7 @@
1011
from rcs.camera.hw import CalibrationStrategy
1112
from rcs.camera.interface import Frame
1213
from tqdm import tqdm
14+
import diskcache as dc
1315

1416
logger = logging.getLogger(__name__)
1517

@@ -19,7 +21,8 @@ class FR3BaseArucoCalibration(CalibrationStrategy):
1921

2022
def __init__(self, camera_name: str):
2123
# base frame to camera, world to base frame
22-
self._extrinsics: np.ndarray[tuple[typing.Literal[4], typing.Literal[4]], np.dtype[np.float64]] | None = None
24+
self._cache = dc.Cache(Path.home() / ".cache" / "rcs")
25+
self._extrinsics: np.ndarray[tuple[typing.Literal[4], typing.Literal[4]], np.dtype[np.float64]] | None = self._cache.get(f"{camera_name}_extrinsics") # None
2326
self.camera_name = camera_name
2427
self.tag_to_world = common.Pose(
2528
rpy_vector=np.array([np.pi, 0, -np.pi / 2]), translation=np.array([0.145, 0, 0])
@@ -53,6 +56,7 @@ def calibrate(
5356
cam_to_world = self.tag_to_world @ np.linalg.inv(tag_to_cam)
5457
world_to_cam = np.linalg.inv(cam_to_world)
5558
self._extrinsics = world_to_cam # type: ignore
59+
self._cache.set(f"{self.camera_name}_extrinsics", world_to_cam, expire=3600)
5660
return True
5761

5862
def get_extrinsics(self) -> np.ndarray[tuple[typing.Literal[4], typing.Literal[4]], np.dtype[np.float64]] | None:

0 commit comments

Comments
 (0)