ouster-lidar / ouster-sdk

Ouster, Inc. sample code
Other
468 stars 440 forks source link

IMU data and Lidar packets #522

Open lecramex opened 1 year ago

lecramex commented 1 year ago

Hello,

I would like to retrieve the IMU data and Lidar Range at the same time, there is a function to do this ?

I know you can get the IMU using client.Sensor and the Lidar Range with client.Scans.stream, but I don't see any example to do it at the same time.

Platform

kairenw commented 1 year ago

from the client.Sensor class the iterator actually returns both IMU and Lidar packets. The Scans interface is built on top of that and simply drops the IMU packets.

So, you can simply use something like this example (based off a PCAP but the same idea) where you check the packet type each time before processing it further.

If you find the batching convenient, you can probably try something like my colleague proposed here: https://github.com/ouster-lidar/ouster_example/issues/455#issuecomment-1315675646

Hope that helps a bit!

lecramex commented 1 year ago

from the client.Sensor class the iterator actually returns both IMU and Lidar packets. The Scans interface is built on top of that and simply drops the IMU packets.

So, you can simply use something like this example (based off a PCAP but the same idea) where you check the packet type each time before processing it further.

If you find the batching convenient, you can probably try something like my colleague proposed here: #455 (comment)

Hope that helps a bit!

Thank you, indeed the solution in #455 (comment)](https://github.com/ouster-lidar/ouster_example/issues/455#issuecomment-1315675646) is what I am looking for.

Do you think that this will be integrated in the SDK ?

kairenw commented 1 year ago

I don't believe it will be integrated in the SDK, for various reasons including lack of bandwidth

lecramex commented 1 year ago

I update the code in python/src/ouster/client/core.py to return both IMU and lidar data, so far it is working with my PC and the lidar without any major issue:

--- a/python/src/ouster/client/core.py
+++ b/python/src/ouster/client/core.py
@@ -11,6 +11,7 @@ from typing import cast, Dict, Iterable, Iterator, List, Optional, Tuple, Union
 from threading import Thread
 import time

+import numpy as np
 from more_itertools import take
 from typing_extensions import Protocol

@@ -382,7 +383,7 @@ class Scans:
             fields if fields is not None else
             self._source.metadata.format.udp_profile_lidar)

-    def __iter__(self) -> Iterator[LidarScan]:
+    def __iter__(self) -> Iterator[Tuple[Optional[Dict[str, np.ndarray]], Optional[LidarScan]]]:
         """Get an iterator."""

         w = self._source.metadata.format.columns_per_frame
@@ -408,7 +409,7 @@ class Scans:
             except StopIteration:
                 if ls_write is not None:
                     if not self._complete or ls_write.complete(column_window):
-                        yield ls_write
+                        yield None, ls_write
                 return

             if self._timeout is not None and (time.monotonic() >=
@@ -421,7 +422,7 @@ class Scans:
                 if batch(packet._data, ls_write):
                     # Got a new frame, return it and start another
                     if not self._complete or ls_write.complete(column_window):
-                        yield ls_write
+                        yield None, ls_write
                         start_ts = time.monotonic()
                     ls_write = None

@@ -434,6 +435,11 @@ class Scans:
                         if drop_frames > 0:
                             sensor.flush(drop_frames)
                             batch = _client.ScanBatcher(w, pf)
+            elif isinstance(packet, ImuPacket):
+                yield {
+                    "acceleration": packet.accel,
+                    "angular_velocity": packet.angular_vel
+                }, None

     def close(self) -> None:
         """Close the underlying PacketSource."""
kairenw commented 1 year ago

Awesome, I'm glad. I'm marking this as a desired enhancement. No timeline for support.