mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-11 14:49:43 +00:00
feat(robots): use read_latest() camera (#2987)
* feat(robots): use read_latest() camera * fix(test): add read_latest reachy cam mock
This commit is contained in:
@@ -150,7 +150,7 @@ class Camera(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def read_latest(self, max_age_ms: int = 1000) -> NDArray[Any]:
|
def read_latest(self, max_age_ms: int = 500) -> NDArray[Any]:
|
||||||
"""Return the most recent frame captured immediately (Peeking).
|
"""Return the most recent frame captured immediately (Peeking).
|
||||||
|
|
||||||
This method is non-blocking and returns whatever is currently in the
|
This method is non-blocking and returns whatever is currently in the
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ class OpenCVCamera(Camera):
|
|||||||
return frame
|
return frame
|
||||||
|
|
||||||
@check_if_not_connected
|
@check_if_not_connected
|
||||||
def read_latest(self, max_age_ms: int = 1000) -> NDArray[Any]:
|
def read_latest(self, max_age_ms: int = 500) -> NDArray[Any]:
|
||||||
"""Return the most recent frame captured immediately (Peeking).
|
"""Return the most recent frame captured immediately (Peeking).
|
||||||
|
|
||||||
This method is non-blocking and returns whatever is currently in the
|
This method is non-blocking and returns whatever is currently in the
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class Reachy2Camera(Camera):
|
|||||||
return self.read()
|
return self.read()
|
||||||
|
|
||||||
@check_if_not_connected
|
@check_if_not_connected
|
||||||
def read_latest(self, max_age_ms: int = 1000) -> NDArray[Any]:
|
def read_latest(self, max_age_ms: int = 500) -> NDArray[Any]:
|
||||||
"""Return the most recent frame captured immediately (Peeking).
|
"""Return the most recent frame captured immediately (Peeking).
|
||||||
|
|
||||||
This method is non-blocking and returns whatever is currently in the
|
This method is non-blocking and returns whatever is currently in the
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ class RealSenseCamera(Camera):
|
|||||||
|
|
||||||
# NOTE(Steven): Missing implementation for depth for now
|
# NOTE(Steven): Missing implementation for depth for now
|
||||||
@check_if_not_connected
|
@check_if_not_connected
|
||||||
def read_latest(self, max_age_ms: int = 1000) -> NDArray[Any]:
|
def read_latest(self, max_age_ms: int = 500) -> NDArray[Any]:
|
||||||
"""Return the most recent (color) frame captured immediately (Peeking).
|
"""Return the most recent (color) frame captured immediately (Peeking).
|
||||||
|
|
||||||
This method is non-blocking and returns whatever is currently in the
|
This method is non-blocking and returns whatever is currently in the
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class HopeJrArm(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class HopeJrHand(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class KochFollower(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ class LeKiwi(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ class OmxFollower(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class OpenArmFollower(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class Reachy2Robot(Robot):
|
|||||||
|
|
||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
|
|
||||||
return obs_dict
|
return obs_dict
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ class SOFollower(Robot):
|
|||||||
# Capture images from cameras
|
# Capture images from cameras
|
||||||
for cam_key, cam in self.cameras.items():
|
for cam_key, cam in self.cameras.items():
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
obs_dict[cam_key] = cam.async_read()
|
obs_dict[cam_key] = cam.read_latest()
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read {cam_key}: {dt_ms:.1f}ms")
|
||||||
|
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ class UnitreeG1(Robot):
|
|||||||
|
|
||||||
# Cameras - read images from ZMQ cameras
|
# Cameras - read images from ZMQ cameras
|
||||||
for cam_name, cam in self._cameras.items():
|
for cam_name, cam in self._cameras.items():
|
||||||
obs[cam_name] = cam.async_read()
|
obs[cam_name] = cam.read_latest()
|
||||||
|
|
||||||
return obs
|
return obs
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ def _make_reachy2_camera_mock(*args, **kwargs):
|
|||||||
cam.connect = MagicMock()
|
cam.connect = MagicMock()
|
||||||
cam.disconnect = MagicMock()
|
cam.disconnect = MagicMock()
|
||||||
cam.async_read = MagicMock(side_effect=lambda: np.zeros((height, width, 3), dtype=np.uint8))
|
cam.async_read = MagicMock(side_effect=lambda: np.zeros((height, width, 3), dtype=np.uint8))
|
||||||
|
cam.read_latest = MagicMock(side_effect=lambda: np.zeros((height, width, 3), dtype=np.uint8))
|
||||||
return cam
|
return cam
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user