Skip to content

Commit 7017280

Browse files
authored
Merge pull request #211 from luxonis/KVM-install-and-support
KVM installation guide
2 parents 3b32f32 + 44cdb90 commit 7017280

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/source/install.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Fedora `Di
3434
Robot Operating System `Discord <https://discord.com/channels/790680891252932659/795749142793420861>`__
3535
Windows 7 :ref:`WinUSB driver <Windows 7>` `Discord <https://discord.com/channels/790680891252932659/798284448323731456>`__
3636
Docker :ref:`Pull and run official images <Docker>` `Discord <https://discord.com/channels/790680891252932659/796794747275837520>`__
37+
Kernel Virtual Machine :ref:`Run on KVM <KVM>` `Discord <https://discord.com/channels/790680891252932659/819663531003346994>`__
3738
====================== ===================================================== ================================================================================
3839

3940
macOS
@@ -147,6 +148,68 @@ Run the :code:`01_rgb_preview.py` example inside a Docker container on a Linux h
147148
To allow the container to update X11 you may need to run :code:`xhost local:root` on
148149
the host.
149150

151+
KVM
152+
***
153+
154+
To access the OAK-D camera in the `Kernel Virtual Machine <https://www.linux-kvm.org/page/Main_Page>`__, there is a need to attach and detach USB
155+
devices on the fly when the host machine detects changes in the USB bus.
156+
157+
OAK-D camera changes the USB device type when it is used by DepthAI API. This happens in backgound when the camera is used natively.
158+
But when the camera is used in a virtual environment the situation is different.
159+
160+
On your host machine, use the following code:
161+
162+
.. code-block:: bash
163+
164+
SUBSYSTEM=="usb", ACTION=="bind", ENV{ID_VENDOR_ID}=="03e7", MODE="0666", RUN+="/usr/local/bin/movidius_usb_hotplug.sh depthai-vm"
165+
SUBSYSTEM=="usb", ACTION=="remove", ENV{PRODUCT}=="3e7/2485/1", ENV{DEVTYPE}=="usb_device", MODE="0666", RUN+="/usr/local/bin/movidius_usb_hotplug.sh depthai-vm"
166+
SUBSYSTEM=="usb", ACTION=="remove", ENV{PRODUCT}=="3e7/f63b/100", ENV{DEVTYPE}=="usb_device", MODE="0666", RUN+="/usr/local/bin/movidius_usb_hotplug.sh depthai-vm"
167+
168+
The script that the udev rule is calling (movidius_usb_hotplug.sh) should then attach/detach the USB device to the virtual machine.
169+
In this case we need to call :code:`virsh` command. For example, the script could do the following:
170+
171+
.. code-block:: bash
172+
173+
#!/bin/bash
174+
# Abort script execution on errors
175+
set -e
176+
if [ "${ACTION}" == 'bind' ]; then
177+
COMMAND='attach-device'
178+
elif [ "${ACTION}" == 'remove' ]; then
179+
COMMAND='detach-device'
180+
if [ "${PRODUCT}" == '3e7/2485/1' ]; then
181+
ID_VENDOR_ID=03e7
182+
ID_MODEL_ID=2485
183+
fi
184+
if [ "${PRODUCT}" == '3e7/f63b/100' ]; then
185+
ID_VENDOR_ID=03e7
186+
ID_MODEL_ID=f63b
187+
fi
188+
else
189+
echo "Invalid udev ACTION: ${ACTION}" >&2
190+
exit 1
191+
fi
192+
echo "Running virsh ${COMMAND} ${DOMAIN} for ${ID_VENDOR}." >&2
193+
virsh "${COMMAND}" "${DOMAIN}" /dev/stdin <<END
194+
<hostdev mode='subsystem' type='usb'>
195+
<source>
196+
<vendor id='0x${ID_VENDOR_ID}'/>
197+
<product id='0x${ID_MODEL_ID}'/>
198+
</source>
199+
</hostdev>
200+
END
201+
exit 0
202+
203+
204+
Note that when the device is disconnected from the USB bus, some udev environmental variables are not available (:code:`ID_VENDOR_ID` or :code:`ID_MODEL_ID`),
205+
that is why you need to use :code:`PRODUCT` environmental variable to identify which device has been disconnected.
206+
207+
The virtual machine where DepthAI API application is running should have defined a udev rules that identify the OAK-D camera.
208+
The udev rule is decribed `here <https://docs.luxonis.com/en/latest/pages/faq/#does-depthai-work-on-the-nvidia-jetson-series>`__
209+
210+
Solution provided by `Manuel Segarra-Abad <https://github.com/maseabunikie>`__
211+
212+
150213
Install from PyPI
151214
#################
152215

0 commit comments

Comments
 (0)