Skip to content

Commit

Permalink
[RSDK-8402] Migrate from OakCamera to DepthAI v3 (#51)
Browse files Browse the repository at this point in the history
* Add new validating flow; Remove ffc model from meta.json and code; Reorganize files

* Make lint

* Remove immediate model assignment

* Remove undeclared var

* Add impl

* Fix up merge more:

* Make lint

* Address logging craziness

* Change default dimensions

* Change config obj names to better camel case

* Fix this logging stuff ugh

* Make lint

* Change dir structure in preparation for service

* Change logger names one more time for clarity

* Fix hanging event loop bug

* Migrate from OakCamera SDK to DepthAI v3

* Fix weird merge resolution and bolster integration tests

* Change language of log and comments to reflect SDK change

* Don't double set rgb/bgr support

* Fix typo in func name

* Why was canon.yaml gitignored? My bad

* Unhardcode defaults and also clean up defaults const vars

* Exit configure with more clear failure

* Make lint
  • Loading branch information
hexbabe authored Aug 5, 2024
1 parent f4ec2f5 commit 8b43ac8
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 267 deletions.
4 changes: 4 additions & 0 deletions .canon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file provides project-level configuration for the canon dev environment utility. https://github.com/viamrobotics/canon
oak:
default: true
image_arm64: ghcr.io/viamrobotics/cloud-build-base:arm64
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# top level
.build-venv
.canon.yaml
.build-env
.DS_Store
.pytest_cache
.venv
build
module.tar.gz
oak-integration-tests

Expand Down
5 changes: 3 additions & 2 deletions integration-tests/tests/oak_d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ func TestCameraServer(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
})

t.Run("Get images method", func(t *testing.T) {
t.Run("Get images method (two images)", func(t *testing.T) {
images, metadata, err := cam.Images(timeoutCtx)
test.That(t, err, test.ShouldBeNil)
test.That(t, images, test.ShouldNotBeNil)
test.That(t, metadata, test.ShouldNotBeNil)
test.That(t, len(images), test.ShouldEqual, 2)
for _, img := range images {
test.That(t, img.SourceName, test.ShouldEqual, componentName)
bounds := img.Image.Bounds()
Expand All @@ -64,7 +65,7 @@ func TestCameraServer(t *testing.T) {
t.Run("Reconfigure module", func(t *testing.T) {
cfg := resource.Config{
Attributes: utils.AttributeMap{
"sensors": []string{"color"},
"sensors": []string{"depth"},
},
}
err := cam.Reconfigure(timeoutCtx, resource.Dependencies{}, cfg)
Expand Down
26 changes: 21 additions & 5 deletions src/components/helpers/shared.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
from typing import Dict, List, Literal, Optional, Tuple
from numpy.typing import NDArray

from depthai_sdk.components.camera_component import CameraComponent
from depthai import CameraBoardSocket


def get_socket_from_str(s: str) -> CameraBoardSocket:
if s == "cam_a":
return CameraBoardSocket.CAM_A
elif s == "cam_b":
return CameraBoardSocket.CAM_B
elif s == "cam_c":
return CameraBoardSocket.CAM_C
else:
raise Exception(f"Camera socket '{s}' is not recognized or supported.")


class Sensor:
component: Optional[CameraComponent] = None
def get_unique_name(self) -> str:
if self.sensor_type == "color":
return f"{self.socket_str}_rgb"
else:
return f"{self.socket_str}_mono"

def __init__(
self,
socket: Literal["cam_a", "cam_b", "cam_c"],
socket_str: Literal["cam_a", "cam_b", "cam_c"],
sensor_type: Literal["color", "depth"],
width: int,
height: int,
frame_rate: int,
color_order: Literal["rgb", "bgr"] = "rgb",
interleaved: bool = False,
):
self.socket = socket
self.socket_str = socket_str
self.socket = get_socket_from_str(socket_str)
self.sensor_type = sensor_type
self.width = width
self.height = height
Expand All @@ -35,7 +51,7 @@ class Sensors:
def __init__(self, sensors: List[Sensor]):
self._mapping = dict()
for sensor in sensors:
self._mapping[sensor.socket] = sensor
self._mapping[sensor.socket_str] = sensor

self.color_sensors = self._find_color_sensors()
self.stereo_pair = self._find_stereo_pair()
Expand Down
6 changes: 3 additions & 3 deletions src/components/oak.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ async def get_point_cloud(
await self._wait_until_worker_running()

# By default, we do not get point clouds even when color and depth are both requested
# We have to reinitialize the worker/OakCamera to start making point clouds
# We have to reinitialize the worker/pipeline+device to start making point clouds
if not self.worker.user_wants_pc:
self.worker.user_wants_pc = True
self.worker.reset()
await self.worker.configure()
self.worker.start()
self.worker.configure()
await self.worker.start()

while not self.worker.running:
LOGGER.info("Waiting for worker to restart with pcd configured...")
Expand Down
Loading

0 comments on commit 8b43ac8

Please sign in to comment.