Skip to content

Commit

Permalink
Rename all occurrences of Zed2i to Zed in airo-mono
Browse files Browse the repository at this point in the history
  • Loading branch information
m-decoster committed Dec 10, 2024
1 parent a611361 commit 3701a33
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ pip install airo-camera-toolkit airo-robots
```
And writing a simple script:
```python
from airo_camera_toolkit.cameras.zed.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed.zed import Zed
from airo_robots.manipulators.hardware.ur_rtde import URrtde
from airo_robots.grippers.hardware.robotiq_2f85_urcap import Robotiq2F85

robot_ip_address = "10.40.0.162"

camera = Zed2i()
camera = Zed()
robot = URrtde(ip_address=robot_ip_address)
gripper = Robotiq2F85(ip_address=robot_ip_address)

Expand Down
4 changes: 2 additions & 2 deletions airo-camera-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pip install .[hand-eye-calibration]
## Getting started with cameras
Camera can be accessed by instantiating the corresponding class:, e.g. for a ZED camera:
```python
from airo_camera_toolkit.cameras.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed import Zed
from airo_camera_toolkit.utils import ImageConverter
import cv2

camera = Zed2i(Zed2i.RESOLUTION_720, fps=30)
camera = Zed(Zed.RESOLUTION_720, fps=30)

while True:
image_rgb_float = camera.get_rgb_image()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def discover_camera(brand: Optional[str], serial_number: Optional[str] = None, *
brand_enum = CameraBrand(brand) # Attempt to convert to enum

if brand_enum == CameraBrand.ZED:
from airo_camera_toolkit.cameras.zed.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed.zed import Zed

camera = Zed2i(serial_number=serial_number, **kwargs)
camera = Zed(serial_number=serial_number, **kwargs)
elif brand_enum == CameraBrand.REALSENSE:
from airo_camera_toolkit.cameras.realsense.realsense import Realsense

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The receiver is subclass of `RGBCamera` which ensures that it follows the interf

## Usage
See the main function in [multiprocess_rgb_camera.py](./multiprocess_rgb_camera.py) for a simple example of how to use these classes with a ZED camera.
The main difference with the regular workflow is that instead of instantiating a `Zed2i` object, you now have to first create a `MultiprocessRGBPublisher` with the class and its kwargs, and then one or more `MultiprocessRGBReceiver`s.
The main difference with the regular workflow is that instead of instantiating a `Zed` object, you now have to first create a `MultiprocessRGBPublisher` with the class and its kwargs, and then one or more `MultiprocessRGBReceiver`s.

> :information_source: Similar to how regular `RGBCamera`s behave, `MultiprocessRGBReceiver`s will block until a new image is available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
"""Instantiates the publisher. Note that the publisher (and its process) will not start until start() is called.
Args:
camera_cls (type): The class e.g. Zed2i that this publisher will instantiate.
camera_cls (type): The class e.g. Zed that this publisher will instantiate.
camera_kwargs (dict, optional): The kwargs that will be passed to the camera_cls constructor.
shared_memory_namespace (str, optional): The string that will be used to prefix the shared memory blocks that this class will create.
"""
Expand Down Expand Up @@ -413,21 +413,21 @@ def __del__(self) -> None:
"""example of how to use the MultiprocessRGBPublisher and MultiprocessRGBReceiver.
You can also use the MultiprocessRGBReceiver in a different process (e.g. in a different python script)
"""
from airo_camera_toolkit.cameras.zed.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed.zed import Zed

multiprocessing.set_start_method("spawn")

resolution = Zed2i.RESOLUTION_2K
resolution = Zed.RESOLUTION_2K
camera_fps = 15
namespace = "camera"

# Creating and starting the publisher
publisher = MultiprocessRGBPublisher(
Zed2i,
Zed,
camera_kwargs={
"resolution": resolution,
"fps": camera_fps,
"depth_mode": Zed2i.NEURAL_DEPTH_MODE,
"depth_mode": Zed.NEURAL_DEPTH_MODE,
},
shared_memory_namespace=namespace,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,19 @@ def __del__(self) -> None:

import multiprocessing

from airo_camera_toolkit.cameras.zed.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed.zed import Zed

multiprocessing.set_start_method("spawn")

resolution = Zed2i.RESOLUTION_2K
resolution = Zed.RESOLUTION_2K
camera_fps = 15

publisher = MultiprocessRGBDPublisher(
Zed2i,
Zed,
camera_kwargs={
"resolution": resolution,
"fps": camera_fps,
"depth_mode": Zed2i.NEURAL_DEPTH_MODE,
"depth_mode": Zed.NEURAL_DEPTH_MODE,
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,22 @@ def __del__(self) -> None:

import multiprocessing

from airo_camera_toolkit.cameras.zed.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed.zed import Zed

multiprocessing.set_start_method("spawn")

resolution = Zed2i.RESOLUTION_2K
resolution = Zed.RESOLUTION_2K
camera_fps = 15

# import os
# os.environ["CUDA_VISIBLE_DEVICES"] = "3"

publisher = MultiprocessStereoRGBDPublisher(
Zed2i,
Zed,
camera_kwargs={
"resolution": resolution,
"fps": camera_fps,
"depth_mode": Zed2i.NEURAL_DEPTH_MODE,
"depth_mode": Zed.NEURAL_DEPTH_MODE,
},
log_debug=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Now We will test whether our `airo_camera_toolkit can access the ZED cameras.
In this directory run:
```
conda activate airo-mono
python zed2i.py
python zed.py
```
Complete the prompts. If everything looks normal, congrats, you successfully completed the installation! :tada:
Expand Down
18 changes: 6 additions & 12 deletions airo-camera-toolkit/airo_camera_toolkit/cameras/zed/zed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, List, Optional

from loguru import logger
from typing_extensions import deprecated

try:
import pyzed.sl as sl
Expand Down Expand Up @@ -90,22 +89,22 @@ def __init__( # type: ignore[no-any-unimported]
self._resolution = resolution
self.fps = fps
self.depth_mode = depth_mode
self.serial_number = serial_number
self.serial_number = int(serial_number) if serial_number else None

self.camera = sl.Camera()

# TODO: create a configuration class for the camera parameters
self.camera_params = sl.InitParameters()

if serial_number:
self.camera_params.set_from_serial_number(int(serial_number))
if self.serial_number:
self.camera_params.set_from_serial_number(self.serial_number)

if svo_filepath:
input_type = sl.InputType()
input_type.set_from_svo_file(svo_filepath)
self.camera_params = sl.InitParameters(input_t=input_type, svo_real_time_mode=False)

self.camera_params.camera_resolution = Zed2i.resolution_to_identifier_dict[resolution]
self.camera_params.camera_resolution = Zed.resolution_to_identifier_dict[resolution]
self.camera_params.camera_fps = fps
# https://www.stereolabs.com/docs/depth-sensing/depth-settings/
self.camera_params.depth_mode = depth_mode
Expand All @@ -123,7 +122,7 @@ def __init__( # type: ignore[no-any-unimported]
status = self.camera.open(self.camera_params)
if status == sl.ERROR_CODE.SUCCESS:
break
logger.info(f"Opening Zed2i camera failed, attempt {i + 1}/{N_OPEN_ATTEMPTS}")
logger.info(f"Opening Zed camera failed, attempt {i + 1}/{N_OPEN_ATTEMPTS}")
if self.serial_number:
logger.info(f"Rebooting {self.serial_number}")
sl.Camera.reboot(self.serial_number)
Expand All @@ -132,7 +131,7 @@ def __init__( # type: ignore[no-any-unimported]
self.camera = sl.Camera()

if status != sl.ERROR_CODE.SUCCESS:
raise IndexError(f"Could not open Zed2i camera, error = {status}")
raise IndexError(f"Could not open Zed camera, error = {status}")

# TODO: create a configuration class for the runtime parameters
self.runtime_params = sl.RuntimeParameters()
Expand Down Expand Up @@ -295,11 +294,6 @@ def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
self.camera.close()


@deprecated("Use Zed instead.")
class Zed2i(Zed):
"""Present for backwards compatibility, use Zed instead."""


def _test_zed_implementation() -> None:
"""this script serves as a 'test' for the zed implementation."""
from airo_camera_toolkit.cameras.manual_test_hw import manual_test_stereo_rgbd_camera, profile_rgb_throughput
Expand Down
9 changes: 8 additions & 1 deletion airo-camera-toolkit/airo_camera_toolkit/cameras/zed/zed2i.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""This file is present for backwards compatibility, when we only supported Zed2i cameras, and the Zed2i class was in this file."""
from airo_camera_toolkit.cameras.zed.zed import * # noqa: F401, F403
from airo_camera_toolkit.cameras.zed.zed import _test_zed_implementation
from airo_camera_toolkit.cameras.zed.zed import Zed, _test_zed_implementation
from typing_extensions import deprecated


@deprecated("Use Zed instead.")
class Zed2i(Zed):
"""Present for backwards compatibility, use Zed instead."""


if __name__ == "__main__":
_test_zed_implementation()
4 changes: 2 additions & 2 deletions airo-camera-toolkit/scripts/live_charuco_pose.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cv2
from airo_camera_toolkit.calibration.fiducial_markers import detect_charuco_board, draw_frame_on_image
from airo_camera_toolkit.cameras.zed.zed2i import Zed2i
from airo_camera_toolkit.cameras.zed.zed import Zed
from airo_camera_toolkit.utils.image_converter import ImageConverter

camera = Zed2i(fps=30)
camera = Zed(fps=30)
intrinsics = camera.intrinsics_matrix()

window_name = "Charuco Pose"
Expand Down

0 comments on commit 3701a33

Please sign in to comment.