Skip to content

Commit 3a8b7c1

Browse files
committed
Merge remote-tracking branch 'origin/develop' into update_doc
2 parents d75f9d2 + 008b0ff commit 3a8b7c1

13 files changed

+394
-8
lines changed

docs/conf.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extensions = [
5050
"sphinx.ext.autosectionlabel", # https://github.com/sphinx-doc/sphinx/issues/7697 wait for this and implement
5151
"sphinx_rtd_theme",
5252
"zephyr.warnings_filter",
53+
'sphinx.ext.mathjax',
5354
]
5455

5556
# See https://github.com/sphinx-doc/sphinx/issues/7728
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
IMU Accelerometer & Gyroscope
2+
=============================
3+
4+
This example shows accelerometer and gyroscope at a combined/synchronized 500 hz rate using the onboard IMU.
5+
Returns acceleration [m/s^2] and angular velocity [rad/s].
6+
7+
Demo
8+
####
9+
10+
11+
Setup
12+
#####
13+
14+
.. include:: /includes/install_from_pypi.rst
15+
16+
Source code
17+
###########
18+
19+
.. tabs::
20+
21+
.. tab:: Python
22+
23+
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/imu_gyroscope_accelerometer.py>`__
24+
25+
.. literalinclude:: ../../../examples/imu_gyroscope_accelerometer.py
26+
:language: python
27+
:linenos:
28+
29+
.. tab:: C++
30+
31+
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/src/imu_gyroscope_accelerometer.cpp>`__
32+
33+
.. literalinclude:: ../../../depthai-core/examples/src/imu_gyroscope_accelerometer.cpp
34+
:language: cpp
35+
:linenos:
36+
37+
.. include:: /includes/footer-short.rst
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
IMU Rotation Vector
2+
===================
3+
4+
This example shows rotation vector output at 400 hz rate using the onboard IMU.
5+
Returns quaternion.
6+
7+
Demo
8+
####
9+
10+
11+
Setup
12+
#####
13+
14+
.. include:: /includes/install_from_pypi.rst
15+
16+
Source code
17+
###########
18+
19+
.. tabs::
20+
21+
.. tab:: Python
22+
23+
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/imu_rotation_vector.py>`__
24+
25+
.. literalinclude:: ../../../examples/imu_rotation_vector.py
26+
:language: python
27+
:linenos:
28+
29+
.. tab:: C++
30+
31+
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/src/imu_rotation_vector.cpp>`__
32+
33+
.. literalinclude:: ../../../depthai-core/examples/src/imu_rotation_vector.cpp
34+
:language: cpp
35+
:linenos:
36+
37+
.. include:: /includes/footer-short.rst

docs/source/tutorials/code_samples.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Code samples are used for automated testing. They are also a great starting poin
2828
- :ref:`RGB & MobileNetSSD @ 4K` - Runs MobileNetSSD on RGB frames and displays detections on both preview and 4k frames
2929
- :ref:`Mono & MobilenetSSD` - Runs MobileNetSSD on mono frames and displays detections on the frame
3030
- :ref:`Video & MobilenetSSD` - Runs MobileNetSSD on the video from the host
31+
- :ref:`IMU Accelerometer & Gyroscope` - Accelerometer and gyroscope at 500hz rate
32+
- :ref:`IMU Rotation Vector` - Rotation vector at 400 hz rate
3133

3234
.. rubric:: Complex
3335

docs/source/tutorials/simple_samples.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Simple
2020
../samples/rgb_mobilenet_4k.rst
2121
../samples/mono_mobilenet.rst
2222
../samples/video_mobilenet.rst
23+
../samples/imu_accelerometer_gyroscope.rst
24+
../samples/imu_rotation_vector.rst
25+
2326

2427
These samples are great starting point for the gen2 API.
2528

examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,5 @@ add_python_example(object_tracker object_tracker.py)
121121
add_python_example(spatial_object_tracker spatial_object_tracker.py)
122122
add_python_example(object_tracker_video object_tracker_video.py)
123123
add_python_example(stereo_depth_from_host stereo_depth_from_host.py)
124+
add_python_example(imu_gyroscope_accelerometer imu_gyroscope_accelerometer.py)
125+
add_python_example(imu_rotation_vector imu_rotation_vector.py)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
3+
import cv2
4+
import depthai as dai
5+
import time
6+
import math
7+
8+
# Create pipeline
9+
pipeline = dai.Pipeline()
10+
11+
# Define sources and outputs
12+
imu = pipeline.createIMU()
13+
xlinkOut = pipeline.createXLinkOut()
14+
15+
xlinkOut.setStreamName("imu")
16+
17+
# enable ACCELEROMETER_RAW and GYROSCOPE_RAW at 500 hz rate
18+
imu.enableIMUSensor([dai.IMUSensor.ACCELEROMETER_RAW, dai.IMUSensor.GYROSCOPE_RAW], 500)
19+
# above this threshold packets will be sent in batch of X, if the host is not blocked and USB bandwidth is available
20+
imu.setBatchReportThreshold(1)
21+
# maximum number of IMU packets in a batch, if it's reached device will block sending until host can receive it
22+
# if lower or equal to batchReportThreshold then the sending is always blocking on device
23+
# useful to reduce device's CPU load and number of lost packets, if CPU load is high on device side due to multiple nodes
24+
imu.setMaxBatchReports(10)
25+
26+
# Link plugins IMU -> XLINK
27+
imu.out.link(xlinkOut.input)
28+
29+
# Pipeline is defined, now we can connect to the device
30+
with dai.Device(pipeline) as device:
31+
32+
def timeDeltaToMilliS(delta) -> float:
33+
return delta.total_seconds()*1000
34+
35+
# Output queue for imu bulk packets
36+
imuQueue = device.getOutputQueue(name="imu", maxSize=50, blocking=False)
37+
baseTs = None
38+
while True:
39+
imuData = imuQueue.get() # blocking call, will wait until a new data has arrived
40+
41+
imuPackets = imuData.packets
42+
for imuPacket in imuPackets:
43+
acceleroValues = imuPacket.acceleroMeter
44+
gyroValues = imuPacket.gyroscope
45+
46+
acceleroTs = acceleroValues.timestamp.get()
47+
gyroTs = gyroValues.timestamp.get()
48+
if baseTs is None:
49+
baseTs = acceleroTs if acceleroTs < gyroTs else gyroTs
50+
acceleroTs = timeDeltaToMilliS(acceleroTs - baseTs)
51+
gyroTs = timeDeltaToMilliS(gyroTs - baseTs)
52+
53+
imuF = "{:.06f}"
54+
tsF = "{:.03f}"
55+
56+
print(f"Accelerometer timestamp: {tsF.format(acceleroTs)} ms")
57+
print(f"Accelerometer [m/s^2]: x: {imuF.format(acceleroValues.x)} y: {imuF.format(acceleroValues.y)} z: {imuF.format(acceleroValues.z)}")
58+
print(f"Gyroscope timestamp: {tsF.format(gyroTs)} ms")
59+
print(f"Gyroscope [rad/s]: x: {imuF.format(gyroValues.x)} y: {imuF.format(gyroValues.y)} z: {imuF.format(gyroValues.z)} ")
60+
61+
if cv2.waitKey(1) == ord('q'):
62+
break

examples/imu_rotation_vector.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
3+
import cv2
4+
import depthai as dai
5+
import time
6+
import math
7+
8+
# Create pipeline
9+
pipeline = dai.Pipeline()
10+
11+
# Define sources and outputs
12+
imu = pipeline.createIMU()
13+
xlinkOut = pipeline.createXLinkOut()
14+
15+
xlinkOut.setStreamName("imu")
16+
17+
# enable ROTATION_VECTOR at 400 hz rate
18+
imu.enableIMUSensor(dai.IMUSensor.ROTATION_VECTOR, 400)
19+
# above this threshold packets will be sent in batch of X, if the host is not blocked and USB bandwidth is available
20+
imu.setBatchReportThreshold(1)
21+
# maximum number of IMU packets in a batch, if it's reached device will block sending until host can receive it
22+
# if lower or equal to batchReportThreshold then the sending is always blocking on device
23+
# useful to reduce device's CPU load and number of lost packets, if CPU load is high on device side due to multiple nodes
24+
imu.setMaxBatchReports(10)
25+
26+
# Link plugins IMU -> XLINK
27+
imu.out.link(xlinkOut.input)
28+
29+
# Pipeline is defined, now we can connect to the device
30+
with dai.Device(pipeline) as device:
31+
32+
def timeDeltaToMilliS(delta) -> float:
33+
return delta.total_seconds()*1000
34+
35+
# Output queue for imu bulk packets
36+
imuQueue = device.getOutputQueue(name="imu", maxSize=50, blocking=False)
37+
baseTs = None
38+
while True:
39+
imuData = imuQueue.get() # blocking call, will wait until a new data has arrived
40+
41+
imuPackets = imuData.packets
42+
for imuPacket in imuPackets:
43+
rVvalues = imuPacket.rotationVector
44+
45+
rvTs = rVvalues.timestamp.get()
46+
if baseTs is None:
47+
baseTs = rvTs
48+
rvTs = rvTs - baseTs
49+
50+
imuF = "{:.06f}"
51+
tsF = "{:.03f}"
52+
53+
print(f"Rotation vector timestamp: {tsF.format(timeDeltaToMilliS(rvTs))} ms")
54+
print(f"Quaternion: i: {imuF.format(rVvalues.i)} j: {imuF.format(rVvalues.j)} "
55+
f"k: {imuF.format(rVvalues.k)} real: {imuF.format(rVvalues.real)}")
56+
print(f"Accuracy (rad): {imuF.format(rVvalues.accuracy)}")
57+
58+
59+
if cv2.waitKey(1) == ord('q'):
60+
break

0 commit comments

Comments
 (0)