Skip to content

Commit bbf4048

Browse files
author
Matevz Morato
committed
Merge remote-tracking branch 'origin/main' into release_v2.24.0.0
2 parents 9f21470 + f5c5796 commit bbf4048

21 files changed

+858
-83
lines changed

docs/docker/dev.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENV CC clang-10
88
ENV CXX clang++-10
99
WORKDIR /app
1010
ADD docs/requirements.txt docs/requirements.txt
11+
ADD docs/requirements_mkdoc.txt docs/requirements_mkdoc.txt
1112
RUN python3 -m pip install -r docs/requirements.txt
1213
ADD . .
1314
CMD docs/docker/docker_run.sh
Loading
Loading
Loading

docs/source/components/device.rst

Lines changed: 169 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Device
44
======
55

6-
Device represents an `OAK camera <https://docs.luxonis.com/projects/hardware/en/latest/>`__. On all of our devices there's a powerful Robotics Vision Core
7-
(`RVC <https://docs.luxonis.com/projects/hardware/en/latest/pages/rvc/rvc2.html#rvc2>`__). The RVC is optimized for performing AI inference algorithms and
8-
for processing sensory inputs (eg. calculating stereo disparity from two cameras).
6+
Device is an `OAK camera <https://docs.luxonis.com/projects/hardware/en/latest/>`__ or a RAE robot. On all of our devices there's a powerful Robotics Vision Core
7+
(`RVC <https://docs.luxonis.com/projects/hardware/en/latest/pages/rvc/rvc2.html#rvc2>`__). The RVC is optimized for performing AI inference, CV operations, and
8+
for processing sensory inputs (eg. stereo depth, video encoders, etc.).
99

1010
Device API
1111
##########
@@ -55,6 +55,36 @@ subnet, you can specify the device (either with MxID, IP, or USB port name) you
5555
with depthai.Device(pipeline, device_info) as device:
5656
# ...
5757
58+
Host clock syncing
59+
==================
60+
61+
When depthai library connects to a device, it automatically syncs device's timestamp to host's timestamp. Timestamp syncing happens continuously at around 5 second intervals,
62+
and can be configured via API (example script below).
63+
64+
.. image:: /_static/images/components/device_timesync.jpg
65+
66+
Device clocks are synced at below 500µs accuracy for PoE cameras, and below 200µs accuracy for USB cameras at 1σ (standard deviation) with host clock.
67+
68+
.. image:: /_static/images/components/clock-syncing.png
69+
70+
A graph representing the accuracy of the device clock with respect to the host clock. We had 3 devices connected (OAK PoE cameras), all were hardware synchronized using `FSYNC Y-adapter <https://docs.luxonis.com/projects/hardware/en/latest/pages/FSYNC_Yadapter/>`__.
71+
Raspberry Pi (the host) had an interrupt pin connected to the FSYNC line, so at the start of each frame the interrupt happened and the host clock was recorded. Then we compared frame (synced) timestamps with
72+
host timestamps and computed the standard deviation. For the histogram above we ran this test for approximately 3 hours.
73+
74+
.. code-block:: python
75+
76+
# Configure host clock syncing example
77+
78+
import depthai as dai
79+
from datetime import timedelta
80+
# Configure pipeline
81+
with dai.Device(pipeline) as device:
82+
# 1st value: Interval between timesync runs
83+
# 2nd value: Number of timesync samples per run which are used to compute a better value
84+
# 3rd value: If true partial timesync requests will be performed at random intervals, otherwise at fixed intervals
85+
device.setTimesync(timedelta(seconds=5), 10, True) # (These are default values)
86+
87+
5888
Multiple devices
5989
################
6090

@@ -63,92 +93,163 @@ If you want to use multiple devices on a host, check :ref:`Multiple DepthAI per
6393
Device queues
6494
#############
6595

66-
After initializing the device, one has to initialize the input/output queues as well. These queues will be located on the host computer (in RAM).
96+
After initializing the device, you can create input/output queues that match :ref:`XLinkIn`/:ref:`XLinkOut` nodes in the pipeline. These queues will be located on the host computer (in RAM).
6797

6898
.. code-block:: python
6999
70-
outputQueue = device.getOutputQueue("output_name")
71-
inputQueue = device.getInputQueue("input_name")
100+
pipeline = dai.Pipeline()
72101
73-
When you define an output queue, the device can push new messages to it at any point in time, and the host can read from it at any point in time.
74-
Usually, when the host is reading very fast from the queue, the queue (regardless of its size) will stay empty most of
75-
the time. But as we add things on the host side (additional processing, analysis, etc), it may happen that the device will be writing to
76-
the queue faster than the host can read from it. And then the messages in the queue will start to add up - and both maxSize and blocking
77-
flags determine the behavior of the queue in this case. You can set these flags with:
102+
xout = pipeline.createXLinkOut()
103+
xout.setStreamName("output_name")
104+
# ...
105+
xin = pipeline.createXLinkIn()
106+
xin.setStreamName("input_name")
107+
# ...
108+
with dai.Device(pipeline) as device:
78109
79-
.. code-block:: python
110+
outputQueue = device.getOutputQueue("output_name", maxSize=5, blocking=False)
111+
inputQueue = device.getInputQueue("input_name")
112+
113+
outputQueue.get() # Read from the queue, blocks until message arrives
114+
outputQueue.tryGet() # Read from the queue, returns None if there's no msg (doesn't block)
115+
if outputQueue.has(): # Check if there are any messages in the queue
80116
81-
# When initializing the queue
82-
queue = device.getOutputQueue(name="name", maxSize=5, blocking=False)
83117
84-
# Or afterwards
85-
queue.setMaxSize(10)
86-
queue.setBlocking(True)
118+
When you define an output queue, the device can push new messages to it at any time, and the host can read from it at any time.
87119

88-
Specifying arguments for :code:`getOutputQueue` method
89-
######################################################
90120

91-
When obtaining the output queue (example code below), the :code:`maxSize` and :code:`blocking` arguments should be set depending on how
92-
the messages are intended to be used, where :code:`name` is the name of the outputting stream.
121+
Output queue - `maxSize` and `blocking`
122+
#######################################
93123

94-
Since queues are on the host computer, memory (RAM) usually isn't that scarce. But if you are using a small SBC like RPI Zero, where there's only 0.5GB RAM,
95-
you might need to specify max queue size as well.
124+
When the host is reading very fast from the queue (inside `while True` loop), the queue, regardless of its size, will stay empty most of
125+
the time. But as we add things on the host side (additional processing, analysis, etc), it may happen that the device will be pushing messages to
126+
the queue faster than the host can read from it. And then the messages in the queue will start to increase - and both `maxSize` and `blocking`
127+
flags determine the behavior of the queue in this case. Two common configurations are:
96128

97129
.. code-block:: python
98130
99131
with dai.Device(pipeline) as device:
100-
queueLeft = device.getOutputQueue(name="manip_left", maxSize=8, blocking=False)
101-
102-
If only the latest results are relevant and previous do not matter, one can set :code:`maxSize = 1` and :code:`blocking = False`.
103-
That way only latest message will be kept (:code:`maxSize = 1`) and it might also be overwritten in order to avoid waiting for
104-
the host to process every frame, thus providing only the latest data (:code:`blocking = False`).
105-
However, if there are a lot of dropped/overwritten frames, because the host isn't able to process them fast enough
106-
(eg. one-threaded environment which does some heavy computing), the :code:`maxSize` could be set to a higher
107-
number, which would increase the queue size and reduce the number of dropped frames.
108-
Specifically, at 30 FPS, a new frame is received every ~33ms, so if your host is able to process a frame in that time, the :code:`maxSize`
109-
could be set to :code:`1`, otherwise to :code:`2` for processing times up to 66ms and so on.
110-
111-
If, however, there is a need to have some intervals of wait between retrieving messages, one could specify that differently.
112-
An example would be checking the results of :code:`DetectionNetwork` for the last 1 second based on some other event,
113-
in which case one could set :code:`maxSize = 30` and :code:`blocking = False`
114-
(assuming :code:`DetectionNetwork` produces messages at ~30FPS).
115-
116-
The :code:`blocking = True` option is mostly used when correct order of messages is needed.
117-
Two examples would be:
118-
119-
- matching passthrough frames and their original frames (eg. full 4K frames and smaller preview frames that went into NN),
120-
- encoding (most prominently H264/H265 as frame drops can lead to artifacts).
121-
122-
Blocking behaviour
123-
******************
124-
125-
By default, queues are **blocking** and their size is **30**, so when the device fills up a queue and when the limit is
126-
reached, any additional messages from the device will be blocked and the library will wait until it can add new messages to the queue.
127-
It will wait for the host to consume (eg. :code:`queue.get()`) a message before putting a new one into the queue.
128-
129-
.. note::
130-
After the host queue gets filled up, the XLinkOut.input queue on the device will start filling up. If that queue is
131-
set to blocking, other nodes that are sending messages to it will have to wait as well. This is a usual cause for a
132-
blocked pipeline, where one of the queues isn't emptied in timely manner and the rest of the pipeline waits for it
133-
to be empty again.
134-
135-
Non-Blocking behaviour
136-
**********************
137-
Making the queue non-blocking will change the behavior in the situation described above - instead of waiting, the library will discard
138-
the oldest message and add the new one to the queue, and then continue its processing loop (so it won't get blocked).
139-
:code:`maxSize` determines the size of the queue and it also helps to control memory usage.
140-
141-
For example, if a message has 5MB of data, and the queue size is 30, this queue can effectively store
142-
up to 150MB of data in the memory on the host (the messages can also get really big, for instance, a single 4K NV12 encoded frame takes about ~12MB).
132+
# If you want only the latest message, and don't care about previous ones;
133+
# When a new msg arrives to the host, it will overwrite the previous (oldest) one if it's still in the queue
134+
q1 = device.getOutputQueue(name="name1", maxSize=1, blocking=False)
135+
136+
137+
# If you care about every single message (eg. H264/5 encoded video; if you miss a frame, you will get artifacts);
138+
# If the queue is full, the device will wait until the host reads a message from the queue
139+
q2 = device.getOutputQueue(name="name2", maxSize=30, blocking=True) # Also default values (maxSize=30/blocking=True)
140+
141+
We used `maxSize=30` just as an example, but it can be any `int16` number. Since device queues are on the host computer, memory (RAM) usually isn't that scarce, so `maxSize` wouldn't matter that much.
142+
But if you are using a small SBC like RPI Zero (512MB RAM), and are streaming large frames (eg. 4K unencoded), you could quickly run out of memory if you set `maxSize` to a high
143+
value (and don't read from the queue fast enough).
143144

144145
Some additional information
145-
***************************
146+
---------------------------
146147

147-
- Decreasing the queue size to 1 and setting non-blocking behavior will effectively mean "I only want the latest packet from the queue".
148148
- Queues are thread-safe - they can be accessed from any thread.
149149
- Queues are created such that each queue is its own thread which takes care of receiving, serializing/deserializing, and sending the messages forward (same for input/output queues).
150150
- The :code:`Device` object isn't fully thread-safe. Some RPC calls (eg. :code:`getLogLevel`, :code:`setLogLevel`, :code:`getDdrMemoryUsage`) will get thread-safe once the mutex is set in place (right now there could be races).
151151

152+
Watchdog
153+
########
154+
155+
The watchdog is a crucial component in the operation of POE (Power over Ethernet) devices with DepthAI. When DepthAI disconnects from a POE device, the watchdog mechanism is the first to respond,
156+
initiating a reset of the camera. This reset is followed by a complete system reboot, which includes the loading of the DepthAI bootloader and the initialization of the entire networking stack.
157+
158+
The watchdog process is necessary to make the camera available for reconnection and **typically takes about 10 seconds**, which means the fastest possible reconnection time is 10 seconds.
159+
160+
161+
Customizing the Watchdog Timeout
162+
--------------------------------
163+
164+
.. tabs::
165+
166+
.. tab:: **Linux/MacOS**
167+
168+
Set the environment variables `DEPTHAI_WATCHDOG_INITIAL_DELAY` and `DEPTHAI_BOOTUP_TIMEOUT` to your desired timeout values (in milliseconds) as follows:
169+
170+
.. code-block:: bash
171+
172+
DEPTHAI_WATCHDOG_INITIAL_DELAY=<my_value> DEPTHAI_BOOTUP_TIMEOUT=<my_value> python3 script.py
173+
174+
.. tab:: **Windows PowerShell**
175+
176+
For Windows PowerShell, set the environment variables like this:
177+
178+
.. code-block:: powershell
179+
180+
$env:DEPTHAI_WATCHDOG_INITIAL_DELAY=<my_value>
181+
$env:DEPTHAI_BOOTUP_TIMEOUT=<my_value>
182+
python3 script.py
183+
184+
.. tab:: **Windows CMD**
185+
186+
In Windows CMD, you can set the environment variables as follows:
187+
188+
.. code-block:: guess
189+
190+
set DEPTHAI_WATCHDOG_INITIAL_DELAY=<my_value>
191+
set DEPTHAI_BOOTUP_TIMEOUT=<my_value>
192+
python3 script.py
193+
194+
Alternatively, you can set the timeout directly in your code:
195+
196+
.. code-block:: python
197+
198+
pipeline = depthai.Pipeline()
199+
200+
# Create a BoardConfig object
201+
config = depthai.BoardConfig()
202+
203+
# Set the parameters
204+
config.watchdogInitialDelayMs = <my_value>
205+
config.watchdogTimeoutMs = <my_value>
206+
207+
pipeline.setBoardConfig(config)
208+
209+
By adjusting these settings, you can tailor the watchdog functionality to better suit your specific requirements.
210+
211+
212+
Environment Variables
213+
#####################
214+
215+
The following table lists various environment variables used in the system, along with their descriptions:
216+
217+
.. list-table::
218+
:widths: 50 50
219+
:header-rows: 1
220+
221+
* - Environment Variable
222+
- Description
223+
* - `DEPTHAI_LEVEL`
224+
- Sets logging verbosity, options: 'trace', 'debug', 'warn', 'error', 'off'
225+
* - `XLINK_LEVEL`
226+
- Sets logging verbosity of XLink library, options: 'debug', 'info', 'warn', 'error', 'fatal', 'off'
227+
* - `DEPTHAI_INSTALL_SIGNAL_HANDLER`
228+
- Set to 0 to disable installing Backward signal handler for stack trace printing
229+
* - `DEPTHAI_WATCHDOG`
230+
- Sets device watchdog timeout. Useful for debugging (DEPTHAI_WATCHDOG=0), to prevent device reset while the process is paused.
231+
* - `DEPTHAI_WATCHDOG_INITIAL_DELAY`
232+
- Specifies delay after which the device watchdog starts.
233+
* - `DEPTHAI_SEARCH_TIMEOUT`
234+
- Specifies timeout in milliseconds for device searching in blocking functions.
235+
* - `DEPTHAI_CONNECT_TIMEOUT`
236+
- Specifies timeout in milliseconds for establishing a connection to a given device.
237+
* - `DEPTHAI_BOOTUP_TIMEOUT`
238+
- Specifies timeout in milliseconds for waiting the device to boot after sending the binary.
239+
* - `DEPTHAI_PROTOCOL`
240+
- Restricts default search to the specified protocol. Options: any, usb, tcpip.
241+
* - `DEPTHAI_DEVICE_MXID_LIST`
242+
- Restricts default search to the specified MXIDs. Accepts comma separated list of MXIDs. Lists filter results in an "AND" manner and not "OR"
243+
* - `DEPTHAI_DEVICE_ID_LIST`
244+
- Alias to MXID list. Lists filter results in an "AND" manner and not "OR"
245+
* - `DEPTHAI_DEVICE_NAME_LIST`
246+
- Restricts default search to the specified NAMEs. Accepts comma separated list of NAMEs. Lists filter results in an "AND" manner and not "OR"
247+
* - `DEPTHAI_DEVICE_BINARY`
248+
- Overrides device Firmware binary. Mostly for internal debugging purposes.
249+
* - `DEPTHAI_BOOTLOADER_BINARY_USB`
250+
- Overrides device USB Bootloader binary. Mostly for internal debugging purposes.
251+
* - `DEPTHAI_BOOTLOADER_BINARY_ETH`
252+
- Overrides device Network Bootloader binary. Mostly for internal debugging purposes.
152253

153254
Reference
154255
#########

docs/source/components/nodes/script.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ GPIO 40 drives FSYNC signal for both 4-lane cameras, and we have used the code b
138138
toggleVal = not toggleVal
139139
ret = GPIO.write(MX_PIN, toggleVal) # Toggle the GPIO
140140
141+
Time synchronization
142+
####################
143+
144+
Script node has access to both device (internal) clock and also synchronized host clock. Host clock is synchronized with device clock at below 2.5ms precision at 1σ, :ref:`more information here <Host clock syncing>`.
145+
146+
.. code-block:: python
147+
148+
import time
149+
interval = 60
150+
ctrl = CameraControl()
151+
ctrl.setCaptureStill(True)
152+
previous = 0
153+
while True:
154+
time.sleep(0.001)
155+
156+
tnow_full = Clock.nowHost() # Synced clock with host
157+
# Clock.now() -> internal/device clock
158+
# Clock.offsetToHost() -> Offset between internal/device clock and host clock
159+
160+
now = tnow_full.seconds
161+
if now % interval == 0 and now != previous:
162+
previous = now
163+
node.warn(f'{tnow_full}')
164+
node.io['out'].send(ctrl)
165+
141166
Using DepthAI :ref:`Messages <components_messages>`
142167
###################################################
143168

docs/source/components/nodes/uvc.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
UVC
2+
===
3+
4+
The DepthAI UVC (`USB Video Class <https://en.wikipedia.org/wiki/USB_video_device_class>`__) node allows OAK devices to function as standard webcams. This feature is particularly useful for integrating OAK devices into applications that require video input, such as video conferencing tools or custom video processing applications.
5+
6+
What is UVC?
7+
############
8+
9+
UVC refers to the USB Video Class standard, which is a USB device class that describes devices capable of streaming video. This standard allows video devices to interface with computers and other devices without needing specific drivers, making them immediately compatible with a wide range of systems and software.
10+
11+
How Does the UVC Node Work?
12+
###########################
13+
14+
The UVC node in DepthAI leverages this standard to stream video from OAK devices. When the UVC node is enabled, the OAK device is recognized as a standard webcam by the host system. This allows the device to be used in any application that supports webcam input, such as Zoom, Skype, or custom video processing software.
15+
16+
The UVC node streams video data over a USB connection. It is important to use a USB3 cable for this purpose, as USB2 may not provide the necessary bandwidth for stable video streaming.
17+
18+
.. note::
19+
20+
The UVC node can currently handle NV12 video streams from OAK devices. For streams in other formats, conversion to NV12 is necessary, which can be achieved using the :ref:`ImageManip` node. It's important to note that streams incompatible with NV12 conversion, like depth streams, are not supported by the UVC node.
21+
22+
Examples of UVC Node Usage
23+
##########################
24+
25+
1. **DepthAI Demo Script**: The DepthAI demo script includes a UVC application that can be run to enable the UVC node on an OAK device.
26+
27+
.. code-block:: bash
28+
29+
python3 depthai_demo.py --app uvc
30+
31+
2. **Custom Python Script**: A custom Python script can be written to enable the UVC node and configure the video stream parameters. Here are some pre-written examples:
32+
33+
- :ref:`UVC & Color Camera`
34+
- :ref:`UVC & Mono Camera`
35+
- :ref:`UVC & Disparity`
36+
37+
38+
3. **OBS Forwarding**: For applications where direct UVC node usage is not possible, OBS Studio can be used to forward the UVC stream.
39+
40+
41+
Reference
42+
#########
43+
44+
.. tabs::
45+
46+
.. tab:: Python
47+
48+
.. autoclass:: depthai.node.UVC
49+
:members:
50+
:inherited-members:
51+
:noindex:
52+
53+
.. tab:: C++
54+
55+
.. doxygenclass:: dai::node::UVC
56+
:project: depthai-core
57+
:members:
58+
:private-members:
59+
:undoc-members:
60+
61+
62+
.. include:: ../../includes/footer-short.rst

0 commit comments

Comments
 (0)