Skip to content

Commit 844d78b

Browse files
juelgCopilot
andcommitted
fix(franka): inference script after testing
Co-authored-by: Copilot <copilot@github.com>
1 parent a31bcc3 commit 844d78b

3 files changed

Lines changed: 46 additions & 26 deletions

File tree

‎docker/Dockerfile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ RUN chmod +x /usr/local/bin/link-editable-source \
5454
&& uv pip install /opt/rcs-src/extensions/rcs_realsense \
5555
&& uv pip install /opt/rcs-src/extensions/rcs_robotiq2f85 \
5656
&& uv pip install /opt/rcs-src/extensions/rcs_zed \
57-
&& uv pip install /opt/rcs-src/examples/teleop/SimPublisher
57+
&& uv pip install /opt/rcs-src/examples/teleop/SimPublisher \
58+
&& uv pip install /opt/rcs-src/2f85-python-driver \
59+
&& uv pip install /opt/rcs-src/vlagents
5860

5961
WORKDIR /workspace/robot-control-stack
6062

‎docker/link-editable-source.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ link_compiled_package "$REPO_ROOT/extensions/rcs_fr3/src/rcs_fr3" "$SITE_PACKAGE
4444
link_pure_python_package "$REPO_ROOT/extensions/rcs_realsense/src/rcs_realsense" "$SITE_PACKAGES/rcs_realsense"
4545
link_pure_python_package "$REPO_ROOT/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85" "$SITE_PACKAGES/rcs_robotiq2f85"
4646
link_pure_python_package "$REPO_ROOT/extensions/rcs_zed/src/rcs_zed" "$SITE_PACKAGES/rcs_zed"
47+
link_pure_python_package "$REPO_ROOT/vlagents" "$SITE_PACKAGES/vlagents"

‎examples/inference/franka.py‎

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import copy
12
import datetime
23
import logging
34
from dataclasses import dataclass
5+
from pathlib import Path
6+
from time import sleep
47
from typing import Any
58

9+
from rcs.utils import SimpleFrameRate
10+
611
import gymnasium as gym
712
import numpy as np
813
from rcs._core.common import BaseCameraConfig, RobotPlatform
@@ -28,22 +33,26 @@
2833
}
2934

3035

31-
ROBOT_INSTANCE = RobotPlatform.SIMULATION
32-
# ROBOT_INSTANCE = RobotPlatform.HARDWARE
36+
# ROBOT_INSTANCE = RobotPlatform.SIMULATION
37+
ROBOT_INSTANCE = RobotPlatform.HARDWARE
3338

3439
# set camera dict to none disable cameras
35-
# CAMERA_DICT = {
36-
# "left_wrist": "230422272017",
37-
# "right_wrist": "230422271040",
38-
# "side": "243522070385",
39-
# "bird_eye": "243522070364",
40-
# }
41-
CAMERA_DICT = None
40+
CAMERA_DICT = {
41+
"left_wrist": "230422272017",
42+
"right_wrist": "230422271040",
43+
# "side": "243522070385",
44+
# "bird_eye": "243522070364",
45+
}
46+
# CAMERA_DICT = None
4247
ZED_CAMERA_DICT = {
43-
"zed": "19928076",
48+
"head": "19928076",
4449
}
4550
INCLUDE_DEPTH = False
4651

52+
ROBOTIQ_SERIAL = {
53+
"left": "DAAQMPDC",
54+
"right": "DAAQMJHX",
55+
}
4756

4857
# DIGIT_DICT = {
4958
# "digit_right_left": "D21182",
@@ -52,16 +61,15 @@
5261
DIGIT_DICT = None
5362

5463

55-
DATASET_PATH = "test_iris"
56-
INSTRUCTION = "pick up cube"
64+
INSTRUCTION = "pick up the black cube with the right arm and place it into the black bowl; pick up the white cube with the left arm and place it into the white bowl"
5765
RECORD_FPS = 30
5866
CONTROL_MODE = ControlMode.JOINTS
5967
RELATIVETO = RelativeTo.NONE
6068
DEBUG = True
6169
VIDEO_PATH = "videos"
62-
MODEL = "pi05"
63-
IP = ""
64-
PORT = 20997
70+
MODEL = "lerobot"
71+
IP = "172.29.5.16"
72+
PORT = 20000
6573

6674

6775
robot2world = {
@@ -93,6 +101,7 @@ def __init__(self, env: gym.Env, cfg: InferenceConfig):
93101
self.remote_agent = RemoteAgent(
94102
cfg.vlagents_host, cfg.vlagents_port, cfg.vlagents_model, cfg.on_same_machine, cfg.jpeg_encoding
95103
)
104+
self.frame_rate = SimpleFrameRate(RECORD_FPS)
96105

97106
def obs_rcs2agents(self, obs: dict, info: dict | None = None) -> Obs:
98107
cameras = {}
@@ -104,32 +113,34 @@ def obs_rcs2agents(self, obs: dict, info: dict | None = None) -> Obs:
104113
state.append(obs[robot]["joints"])
105114
state.append(obs[robot]["gripper"])
106115

107-
return Obs(cameras=None, gripper=None, info=info, state=np.concatenate(state))
116+
return Obs(cameras=cameras, gripper=None, info=info, state=np.concatenate(state))
108117

109118
def action_agents2rcs(self, action: Act) -> dict[str, Any]:
110119
act = {}
111120
for idx, robot in enumerate(self._cfg.robot_keys):
112121
# TODO: this is currently hard coded for franka joints
113122
act[robot] = {}
114123
act[robot]["joints"] = action.action[idx * 8 : idx * 8 + 7]
115-
act[robot]["gripper"] = action.action[idx * 8 + 7]
124+
act[robot]["gripper"] = action.action[idx * 8 + 7 : idx * 8 + 8]
116125
return act
117126

118127
def loop(self):
119128
obs, _ = self.env.reset()
120129

121130
obs_dict = self.obs_rcs2agents(obs)
122131

123-
self.remote_agent.reset(obs_dict, instruction=self._cfg.instruction)
132+
self.remote_agent.reset(copy.deepcopy(obs_dict), instruction=self._cfg.instruction)
124133

125134
while True:
126-
action = self.remote_agent.act(obs_dict)
135+
action = self.remote_agent.act(copy.deepcopy(obs_dict))
127136
if action.done:
128137
logger.info("done issued by agent, shutting down")
129138
break
130-
obs, _, _, _, info = self.env.step(self.action_agents2rcs(action))
139+
a = self.action_agents2rcs(action)
140+
obs, _, _, _, info = self.env.step(a)
131141

132142
obs_dict = self.obs_rcs2agents(obs)
143+
self.frame_rate()
133144

134145

135146
def get_env():
@@ -191,6 +202,12 @@ def get_env():
191202
hw_cfg.max_relative_movement = 0.5 if CONTROL_MODE == ControlMode.JOINTS else (0.5, np.deg2rad(90))
192203
hw_cfg.relative_to = RELATIVETO
193204
hw_cfg.robot_to_shared_base_frame = robot2world
205+
hw_cfg.robot_cfgs["left"].ignore_realtime = True
206+
hw_cfg.robot_cfgs["right"].ignore_realtime = True
207+
hw_cfg.robot_cfgs["left"].speed_factor = 0.3
208+
hw_cfg.robot_cfgs["right"].speed_factor = 0.3
209+
hw_cfg.gripper_cfgs["left"].serial_number = ROBOTIQ_SERIAL["left"]
210+
hw_cfg.gripper_cfgs["right"].serial_number = ROBOTIQ_SERIAL["right"]
194211
env_rel = env_creator.create_env(hw_cfg)
195212
else:
196213
# FR3
@@ -215,16 +232,16 @@ def main():
215232
env_rel = get_env()
216233
env_rel.reset()
217234

218-
VIDEO_PATH.mkdir(parents=True, exist_ok=True)
219-
timestamp = str(datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
235+
# Path(VIDEO_PATH).mkdir(parents=True, exist_ok=True)
236+
# timestamp = str(datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
220237

221-
camera_set = env_rel.get_wrapper_attr("camera_set")
222-
camera_set.record_video(VIDEO_PATH, timestamp)
238+
# camera_set = env_rel.get_wrapper_attr("camera_set")
239+
# camera_set.record_video(Path(VIDEO_PATH), timestamp)
223240

224241
# env = RHCWrapper(env, exec_horizon=1)
225242

226243
cfg = InferenceConfig(
227-
IP, PORT, MODEL, INSTRUCTION, jpeg_encoding=True, on_same_machine=True, robot_keys=["left", "right"]
244+
IP, PORT, MODEL, INSTRUCTION, jpeg_encoding=True, on_same_machine=False, robot_keys=["left", "right"]
228245
)
229246
controller = ModelInference(env_rel, cfg)
230247
input("robot is about to be controlled by AI, press enter to start")

0 commit comments

Comments
 (0)