Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/rcs_realsense/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies = [
"rcs==0.4.0",
"pyrealsense2~=2.55.1",
"apriltag==0.0.16",
"diskcache",
]
readme = "README.md"
maintainers = [
Expand Down
8 changes: 7 additions & 1 deletion extensions/rcs_realsense/src/rcs_realsense/calibration.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
import threading
import typing
from pathlib import Path
from time import sleep

import apriltag
import cv2
import diskcache as dc
import numpy as np
from rcs._core import common
from rcs.camera.hw import CalibrationStrategy
Expand All @@ -19,7 +21,10 @@ class FR3BaseArucoCalibration(CalibrationStrategy):

def __init__(self, camera_name: str):
# base frame to camera, world to base frame
self._extrinsics: np.ndarray[tuple[typing.Literal[4], typing.Literal[4]], np.dtype[np.float64]] | None = None
self._cache = dc.Cache(Path.home() / ".cache" / "rcs")
self._extrinsics: np.ndarray[tuple[typing.Literal[4], typing.Literal[4]], np.dtype[np.float64]] | None = (
self._cache.get(f"{camera_name}_extrinsics")
) # None
self.camera_name = camera_name
self.tag_to_world = common.Pose(
rpy_vector=np.array([np.pi, 0, -np.pi / 2]), translation=np.array([0.145, 0, 0])
Expand Down Expand Up @@ -53,6 +58,7 @@ def calibrate(
cam_to_world = self.tag_to_world @ np.linalg.inv(tag_to_cam)
world_to_cam = np.linalg.inv(cam_to_world)
self._extrinsics = world_to_cam # type: ignore
self._cache.set(f"{self.camera_name}_extrinsics", world_to_cam, expire=3600)
return True

def get_extrinsics(self) -> np.ndarray[tuple[typing.Literal[4], typing.Literal[4]], np.dtype[np.float64]] | None:
Expand Down
10 changes: 5 additions & 5 deletions python/rcs/envs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,15 @@ def __init__(self, env, gripper: common.Gripper, binary: bool = True, open_on_re
self.action_space: gym.spaces.Dict
self.action_space.spaces.update(get_space(GripperDictType).spaces)
self.gripper_key = get_space_keys(GripperDictType)[0]
self._gripper = gripper
self.gripper = gripper
self.binary = binary
self._last_gripper_cmd = None
self.open_on_reset = open_on_reset

def reset(self, **kwargs) -> tuple[dict[str, Any], dict[str, Any]]:
if self.open_on_reset:
# resetting opens the gripper
self._gripper.reset()
self.gripper.reset()
self._last_gripper_cmd = None
return super().reset(**kwargs)

Expand All @@ -712,7 +712,7 @@ def observation(self, observation: dict[str, Any], info: dict[str, Any]) -> tupl
self._last_gripper_cmd if self._last_gripper_cmd is not None else self.BINARY_GRIPPER_OPEN
)
else:
observation[self.gripper_key] = self._gripper.get_normalized_width()
observation[self.gripper_key] = self.gripper.get_normalized_width()

return observation, info

Expand All @@ -725,9 +725,9 @@ def action(self, action: dict[str, Any]) -> dict[str, Any]:
gripper_action = np.clip(gripper_action, 0.0, 1.0)

if self.binary:
self._gripper.grasp() if gripper_action == self.BINARY_GRIPPER_CLOSED else self._gripper.open()
self.gripper.grasp() if gripper_action == self.BINARY_GRIPPER_CLOSED else self.gripper.open()
else:
self._gripper.set_normalized_width(gripper_action)
self.gripper.set_normalized_width(gripper_action)
self._last_gripper_cmd = gripper_action
del action[self.gripper_key]
return action
Expand Down
4 changes: 2 additions & 2 deletions python/rcs/envs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def get_tcp_offset(mjcf: str | Path) -> rcs.common.Pose:
tcp_offset_translation = np.array(model.numeric("tcp_offset_translation").data)
tcp_offset_rotation_matrix = np.array(model.numeric("tcp_offset_rotation_matrix").data)
return rcs.common.Pose(
translation=tcp_offset_translation, rotation=tcp_offset_rotation_matrix.reshape((3, 3))
) # type: ignore
translation=tcp_offset_translation, rotation=tcp_offset_rotation_matrix.reshape((3, 3)) # type: ignore
)
except KeyError:
msg = "No tcp offset found in the model. Using the default tcp offset."
logging.info(msg)
Expand Down