Skip to content

Commit 13e7a58

Browse files
committed
fix(operator): test teleop
1 parent 5652019 commit 13e7a58

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

python/rcs/envs/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class ArmObsType(TQuatDictType, JointsDictType, TRPYDictType): ...
167167
CartOrJointContType: TypeAlias = TQuatDictType | JointsDictType | TRPYDictType
168168
LimitedCartOrJointContType: TypeAlias = LimitedTQuatRelDictType | LimitedJointsRelDictType | LimitedTRPYRelDictType
169169

170-
class ArmWithGripper(CartOrJointContType, GripperDictType): ...
170+
class ArmWithGripper(TQuatDictType, GripperDictType): ...
171171

172172

173173
class ControlMode(Enum):

python/rcs/operator/franka.py

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from time import sleep
44

55
import numpy as np
6+
import rcs
67
from rcs._core.common import RPY, Pose, RobotPlatform
8+
from rcs._core import common
79
from rcs._core.sim import SimConfig
810
from rcs.camera.hw import HardwareCameraSet
911
from rcs.envs.base import (
@@ -21,20 +23,23 @@
2123
from rcs_fr3.utils import default_fr3_hw_gripper_cfg, default_fr3_hw_robot_cfg
2224
from rcs_realsense.utils import default_realsense
2325
from rcs.operator.quest import QuestConfig, QuestOperator
26+
from rcs.operator.interface import TeleopLoop
2427

2528
logger = logging.getLogger(__name__)
2629

2730

28-
29-
3031
ROBOT2IP = {
3132
# "left": "192.168.102.1",
3233
"right": "192.168.101.1",
3334
}
35+
ROBOT2ID = {
36+
"left": "0",
37+
"right": "1",
38+
}
3439

3540

36-
# ROBOT_INSTANCE = RobotPlatform.SIMULATION
37-
ROBOT_INSTANCE = RobotPlatform.HARDWARE
41+
ROBOT_INSTANCE = RobotPlatform.SIMULATION
42+
# ROBOT_INSTANCE = RobotPlatform.HARDWARE
3843

3944
RECORD_FPS = 30
4045
# set camera dict to none disable cameras
@@ -45,7 +50,7 @@
4550
# "bird_eye": "243522070364",
4651
# }
4752
CAMERA_DICT = None
48-
MQ3_ADDR = "10.42.0.1"
53+
MQ3_ADDR = "192.168.1.219"
4954

5055
# DIGIT_DICT = {
5156
# "digit_right_left": "D21182",
@@ -56,12 +61,9 @@
5661

5762
DATASET_PATH = "test_data_iris_dual_arm14"
5863
INSTRUCTION = "build a tower with the blocks in front of you"
59-
TELEOP = "quest"
6064

61-
configs = {"quest": QuestConfig(robot_keys=ROBOT2IP.keys(), simulation=ROBOT_INSTANCE == RobotPlatform.SIMULATION, mq3_addr=MQ3_ADDR)}
62-
operators = {
63-
"quest": QuestOperator,
64-
}
65+
66+
config = QuestConfig(mq3_addr=MQ3_ADDR, simulation=ROBOT_INSTANCE == RobotPlatform.SIMULATION)
6567

6668

6769
def get_env():
@@ -79,39 +81,70 @@ def get_env():
7981
name2ip=ROBOT2IP,
8082
camera_set=camera_set,
8183
robot_cfg=default_fr3_hw_robot_cfg(async_control=True),
82-
control_mode=operators[TELEOP].control_mode[0],
84+
control_mode=QuestOperator.control_mode[0],
8385
gripper_cfg=default_fr3_hw_gripper_cfg(async_control=True),
8486
max_relative_movement=(0.5, np.deg2rad(90)),
85-
relative_to=operators[TELEOP].control_mode[1],
87+
relative_to=QuestOperator.control_mode[1],
8688
)
8789
env_rel = StorageWrapper(
8890
env_rel, DATASET_PATH, INSTRUCTION, batch_size=32, max_rows_per_group=100, max_rows_per_file=1000
8991
)
92+
operator = QuestOperator(config)
9093
else:
9194
# FR3
92-
robot_cfg = default_sim_robot_cfg("fr3_empty_world")
95+
rcs.scenes["rcs_icra_scene"] = rcs.Scene(
96+
mjcf_scene="/home/tobi/coding/rcs_clones/prs/models/scenes/rcs_icra_scene/scene.xml",
97+
mjcf_robot=rcs.scenes["fr3_simple_pick_up"].mjcf_robot,
98+
robot_type=common.RobotType.FR3,
99+
)
100+
rcs.scenes["pick"] = rcs.Scene(
101+
mjcf_scene="/home/tobi/coding/rcs_clones/prs/assets/scenes/fr3_simple_pick_up/scene.xml",
102+
mjcf_robot=rcs.scenes["fr3_simple_pick_up"].mjcf_robot,
103+
robot_type=common.RobotType.FR3,
104+
)
105+
106+
# robot_cfg = default_sim_robot_cfg("fr3_empty_world")
107+
# robot_cfg = default_sim_robot_cfg("fr3_simple_pick_up")
108+
robot_cfg = default_sim_robot_cfg("rcs_icra_scene")
109+
# robot_cfg = default_sim_robot_cfg("pick")
110+
111+
# resolution = (256, 256)
112+
# cameras = {
113+
# cam: SimCameraConfig(
114+
# identifier=cam,
115+
# type=CameraType.fixed,
116+
# resolution_height=resolution[1],
117+
# resolution_width=resolution[0],
118+
# frame_rate=0,
119+
# )
120+
# for cam in ["side", "wrist"]
121+
# }
93122

94123
sim_cfg = SimConfig()
95124
sim_cfg.async_control = True
96125
env_rel = SimMultiEnvCreator()(
97-
name2id=ROBOT2IP,
126+
name2id=ROBOT2ID,
98127
robot_cfg=robot_cfg,
99-
control_mode=operators[TELEOP].control_mode[0],
128+
control_mode=QuestOperator.control_mode[0],
100129
gripper_cfg=default_sim_gripper_cfg(),
101130
# cameras=default_mujoco_cameraset_cfg(),
102131
max_relative_movement=0.5,
103-
relative_to=operators[TELEOP].control_mode[1],
132+
relative_to=QuestOperator.control_mode[1],
104133
sim_cfg=sim_cfg,
105134
)
106-
sim = env_rel.unwrapped.envs[ROBOT2IP.keys().__iter__().__next__()].sim # type: ignore
135+
# sim = env_rel.unwrapped.envs[ROBOT2IP.keys().__iter__().__next__()].sim # type: ignore
136+
sim = env_rel.get_wrapper_attr("sim")
137+
operator = QuestOperator(config, sim)
107138
sim.open_gui()
108-
return env_rel
139+
return env_rel, operator
140+
109141

110142
def main():
111-
env_rel = get_env()
143+
env_rel, operator = get_env()
112144
env_rel.reset()
113-
with env_rel, operators[TELEOP](env_rel, configs[TELEOP]) as op: # type: ignore
114-
op.environment_step_loop()
145+
tele = TeleopLoop(env_rel, operator)
146+
with env_rel, tele: # type: ignore
147+
tele.environment_step_loop()
115148

116149

117150
if __name__ == "__main__":

python/rcs/operator/interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class BaseOperator(ABC, threading.Thread):
3131
controller_names: list[str] = field(default=["left", "right"])
3232

3333
def __init__(self, config: BaseOperatorConfig, sim: Sim | None = None):
34+
threading.Thread.__init__(self)
3435
self.config = config
3536
self.sim = sim
3637

@@ -123,7 +124,8 @@ def environment_step_loop(self):
123124
print(f"Command: Resetting origin for {robot}...")
124125
assert (
125126
self.operator.control_mode[1] == RelativeTo.CONFIGURED_ORIGIN
126-
and self.env.get_wrapper_attr("relative_to") == RelativeTo.CONFIGURED_ORIGIN
127+
# TODO the following is a dict and can thus not easily be used like this
128+
# and self.env.get_wrapper_attr("relative_to") == RelativeTo.CONFIGURED_ORIGIN
127129
), "both robot env and operator must be configured to relative_to.CONFIGURED_ORIGIN"
128130
self.env.get_wrapper_attr("envs")[robot].set_origin_to_current()
129131

python/rcs/operator/quest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from time import sleep
66

77
import numpy as np
8-
from rcs._core.common import Pose
8+
from rcs._core.common import Pose, RPY
99
from rcs.envs.base import ArmWithGripper, ControlMode, GripperDictType, RelativeActionSpace, RelativeTo, TQuatDictType
1010
from rcs.operator.interface import BaseOperator, BaseOperatorConfig, TeleopCommands
1111
from rcs.sim.sim import Sim
@@ -49,7 +49,6 @@ class QuestOperator(BaseOperator):
4949
def __init__(self, config: QuestConfig, sim: Sim | None = None):
5050
super().__init__(config, sim)
5151
self.config: QuestConfig
52-
self._reader = MetaQuest3("RCSNode")
5352

5453
self._resource_lock = threading.Lock()
5554
self._cmd_lock = threading.Lock()
@@ -89,6 +88,7 @@ def __init__(self, config: QuestConfig, sim: Sim | None = None):
8988
# sim.open_gui()
9089
# MujocoPublisher(sim.model, sim.data, MQ3_ADDR, visible_geoms_groups=list(range(1, 3)))
9190
# env_rel = DigitalTwin(env_rel, twin_env)
91+
self._reader = MetaQuest3("RCSNode")
9292

9393
def _reset_origin_to_current(self, controller: str | None = None):
9494
with self._cmd_lock:
@@ -116,7 +116,7 @@ def reset_operator_state(self):
116116
self._reset_state()
117117
self._reset_origin_to_current()
118118

119-
def get_action(self) -> dict[str, ArmWithGripper]:
119+
def consume_action(self) -> dict[str, ArmWithGripper]:
120120
transforms = {}
121121
with self._resource_lock:
122122
for controller in self.controller_names:

0 commit comments

Comments
 (0)