Skip to content

Commit 275ed1f

Browse files
committed
improved camera set handling and vive script
- vive script more configuration in header: storage path, camera set and gif - proper start and end of video recording - gif folder
1 parent 3125271 commit 275ed1f

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

python/rcsss/control/vive.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@
4242
INCLUDE_ROTATION = True
4343
ROBOT_IP = "192.168.101.1"
4444
ROBOT_INSTANCE = RobotInstance.HARDWARE
45-
DEBUG = True
45+
DEBUG = False
46+
STORAGE_PATH = "teleop_data"
47+
# set camera dict to none disable cameras
48+
CAMERA_DICT = {
49+
"wrist": "244222071045",
50+
# "wrist": "218622278131", # new realsense
51+
"bird_eye": "243522070364",
52+
"side": "243522070385",
53+
}
54+
PRODUCE_GIF = True
55+
4656

4757

4858
class Button(IntFlag):
@@ -210,20 +220,20 @@ def environment_step_loop(self):
210220
rate_limiter(0.001)
211221

212222

213-
def input_loop(env_rel, action_server: UDPViveActionServer, camera_set: RealSenseCameraSet):
223+
def input_loop(env_rel, action_server: UDPViveActionServer, camera_set: RealSenseCameraSet | None):
214224
while True:
215225
i = input("> ")
216226
match i:
217227
case "help":
218228
print("You can use `quit` to stop the program, `episode` to start a new episode")
219229
case "quit":
220-
# camera_set.stop()
221230
sys.exit(0)
222231
case "episode":
223-
# camera_set.clear_buffer()
224232
# record videos
225-
video_path = env_rel.path / "videos"
226-
video_path.mkdir(parents=True, exist_ok=True)
233+
if camera_set is not None:
234+
video_path = env_rel.path / "videos"
235+
video_path.mkdir(parents=True, exist_ok=True)
236+
camera_set.record_video(env_rel.path / "videos", env_rel.episode_count)
227237
print(f'{env_rel.episode_count = }')
228238

229239
thread = threading.Thread(target=action_server.environment_step_loop)
@@ -246,14 +256,7 @@ def main():
246256
with resource_manger:
247257

248258
if ROBOT_INSTANCE == RobotInstance.HARDWARE:
249-
camera_dict = {
250-
"wrist": "244222071045",
251-
# "wrist": "218622278131", # new realsense
252-
"bird_eye": "243522070364",
253-
"side": "243522070385",
254-
}
255-
camera_set = default_realsense(camera_dict)
256-
camera_set = None
259+
camera_set = default_realsense(CAMERA_DICT)
257260
env_rel = fr3_hw_env(
258261
ip=ROBOT_IP,
259262
camera_set = camera_set,
@@ -264,7 +267,6 @@ def main():
264267
gripper_cfg=default_fr3_hw_gripper_cfg(),
265268
max_relative_movement=(0.01, np.deg2rad(5)),
266269
# max_relative_movement=(0.5, np.deg2rad(90)),
267-
# TODO: max should be always according to the last step
268270
# max_relative_movement=np.deg2rad(20),
269271
relative_to=RelativeTo.CONFIGURED_ORIGIN,
270272
async_control=True,
@@ -284,7 +286,7 @@ def main():
284286
env_rel.get_wrapper_attr("sim").open_gui()
285287

286288
if not DEBUG:
287-
env_rel = StorageWrapper(env_rel, path="/home/juelg/code/frankcsy/record_real_christmas", camera_set=camera_set)
289+
env_rel = StorageWrapper(env_rel, path=STORAGE_PATH, camera_set=camera_set, gif=PRODUCE_GIF)
288290
# ip_secondary = "192.168.102.1"
289291
# with Desk.fci(ip_secondary, user, pw):
290292
# f = rcsss.hw.FR3(ip_secondary)
@@ -300,8 +302,7 @@ def main():
300302
with env_rel:
301303
with UDPViveActionServer(VIVE_HOST, VIVE_PORT, env_rel) as action_server:
302304
if not DEBUG:
303-
input_loop(env_rel, action_server, None)
304-
305+
input_loop(env_rel, action_server, camera_set)
305306
else:
306307
action_server.environment_step_loop()
307308

python/rcsss/envs/wrappers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def __init__(
6161
# get git diff
6262
os.system(f'git diff --submodule=diff > {os.path.join(str(self.path), "git_diff.txt")}')
6363

64+
self.gif_path = Path(path) / "gifs"
65+
if self.gif:
66+
self.gif_path.mkdir(parents=True, exist_ok=True)
67+
6468
def flush(self):
6569
"""writes data to disk"""
6670
if len(self.data) == 0 or self.step_count == 0:
@@ -85,7 +89,7 @@ def flush(self):
8589
previous_timestamp = self.data["timestamp"][idx]
8690
imgs.append(Image.fromarray(img))
8791
imgs[0].save(
88-
self.path / self.GIF.format(self.timestamp, self.episode_count, key),
92+
self.gif_path / self.GIF.format(self.timestamp, self.episode_count, key),
8993
save_all=True,
9094
append_images=imgs[1:],
9195
duration=self.GIF_DURATION_S * 1000,
@@ -116,8 +120,6 @@ def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = Non
116120
self.flush()
117121
self.step_count = 0
118122
re = super().reset(seed=seed, options=options)
119-
if self.camera_set is not None:
120-
self.camera_set.record_video(self.path, self.episode_count)
121123
return re
122124

123125
def close(self):

0 commit comments

Comments
 (0)