|
6 | 6 |
|
7 | 7 | import gymnasium as gym |
8 | 8 | import numpy as np |
9 | | -from mergedeep import merge |
10 | 9 | from rcsss import common, sim |
11 | 10 | from rcsss.camera.interface import BaseCameraSet |
12 | 11 | from rcsss.envs.space_utils import ( |
@@ -402,7 +401,7 @@ def __init__(self, env, camera_set: BaseCameraSet, include_depth: bool = False): |
402 | 401 |
|
403 | 402 | self.observation_space: gym.spaces.Dict |
404 | 403 | # rgb is always included |
405 | | - params = { |
| 404 | + params: dict = { |
406 | 405 | "frame": { |
407 | 406 | "height": camera_set.config.resolution_height, |
408 | 407 | "width": camera_set.config.resolution_width, |
@@ -447,22 +446,26 @@ def observation(self, observation: dict, info: dict[str, Any]) -> tuple[dict[str |
447 | 446 | observation[self.camera_key] = {} |
448 | 447 | info["camera_available"] = False |
449 | 448 | return observation, info |
| 449 | + |
| 450 | + def check_depth(depth): |
| 451 | + if self.include_depth and depth is None: |
| 452 | + msg = "Depth is not available in data but still requested." |
| 453 | + raise ValueError(msg) |
| 454 | + return self.include_depth |
| 455 | + |
450 | 456 | frame_dict: dict[str, dict[str, np.ndarray]] = { |
451 | | - camera_name: { |
452 | | - self.RGB_KEY: frame.camera.color.data, |
453 | | - } |
454 | | - for camera_name, frame in frameset.frames.items() |
455 | | - } |
456 | | - if self.include_depth: |
457 | | - merge( |
458 | | - frame_dict, |
| 457 | + camera_name: ( |
459 | 458 | { |
460 | | - camera_name: { |
461 | | - self.DEPTH_KEY: frame.camera.depth.data, |
462 | | - } |
463 | | - for camera_name, frame in frameset.frames.items() |
464 | | - }, |
| 459 | + self.RGB_KEY: frame.camera.color.data, |
| 460 | + } |
| 461 | + if check_depth(frame.camera.depth) |
| 462 | + else { |
| 463 | + self.RGB_KEY: frame.camera.color.data, |
| 464 | + self.DEPTH_KEY: frame.camera.depth.data, # type: ignore |
| 465 | + } |
465 | 466 | ) |
| 467 | + for camera_name, frame in frameset.frames.items() |
| 468 | + } |
466 | 469 | observation[self.camera_key] = frame_dict |
467 | 470 |
|
468 | 471 | info["camera_available"] = True |
|
0 commit comments