Imu data ready on AE3 / LSM6DSM

Is it possible to check if new accel / gyro data available on AE3 (LSM6DSM STATUS_REG)? So what I can do something like:

csi0.ioctl(csi.IOCTL_SET_TRIGGERED_MODE, True)
while True:
     if imu.data_ready():
          csi0.snapshot()

Thank you very much

Hi Chobisfan,

Note that triggered mode support for the AE3 is not yet merged into master. It’s waiting on a PR. sensors/pag7936: Add support for triggering. by kwagyeman · Pull Request #2564 · openmv/openmv · GitHub

As for controlling the LSM6DSM status reg. Please see the imu — imu sensor - OpenMV MicroPython 1.28 documentation

Using this, and the LSM6DSM datasheet, you have full register access and can read whatever you want. You can also set regs.

Hi @kwagyeman Thank you very much for replying.

In oder to set accel / gyro scale and ODR, I need to use lsm6dsox. But in oder to use __read_reg(), I need to use imu. Is it ok to use these 2 module at the same time?
To init lsm6dsox on AE3, LSM6DSOX(SPI(?), cs=Pin(?)). I check the schematic but not sure about which SPI bus and CS pin number.

Thank you very much for helping.

The AE3 only supports the IMU module. The LSM6DSOX is not on the board. That’s an Arduino Nicla part.

So there is no way to change ODR and scale on AE3 LSM6DSM? Thank you very much

You just read/write the register values using the register addresses from the datasheet of the module.

The read/write reg methods in the IMU module. You can change anything.

Thank you for very helpful and quick reply. Is the default setting for lsm6dsm on AE3 located in openmv/modules/py_imu.c at e5b538651c591aeb7099fcf876e1b61e0e885d91 · openmv/openmv · GitHub ?

Yes, it’s pretty minimal.

Hi @kwagyeman I have a question about PAG7936 triggering
On AE3, I want to trigger PAG7936 when a new imu data available, so that I can align camera image with imu data.

cam = csi.CSI()
cam.ioctl(csi.IOCTL_SET_TRIGGERED_MODE, True)
while True:
    # read STATUS_REG
    data_rdy = imu.__read_reg(0x1e)
    # check if new accel & gyro data available
    if (data_rdy & 3) == 3:
        imu.acceleration_mg()
        imu.angular_rate_mdps()
        cam.snapshot()

Because we are in trigger mode, snapshot() blocks util exposure and readout finished. Is it possible to have a dedicate trigger() function? So that I can trigger the camera when a new imu data available and get the image when it is available.

Thank you ver much

So, I’m confused by what you are asking, because, in trigger mode, snapshot() triggers the camera and then reads out the image.

Are you asking for a way to trigger the camera without waiting for the frame that was triggered to arrive from the camera into ram and then call snapshot later to get the image? If so, it will be better to run the camera in free running mode and then just sync reading the accel/gyro to the camera running by itself.

If you could explain what you are trying to do better it would help.

Hi @kwagyeman Thank you

I set IMU ODR to 100Hz and want to capture an image every 10 imu sample. So that image will align with specific imu data.

cnt = 0
while True:
    # read STATUS_REG
    data_rdy = imu.__read_reg(0x1e)
    # check if new accel & gyro data available
    if (data_rdy & 3) == 3:
        # read IMU data, it will clear STATUS_REG
        imu.acceleration_mg()
        imu.angular_rate_mdps()
        cnt += 1
        if cnt == 10:
           cnt = 0
           cam.snapshot()

Becuase snapshot() block until exposure and readout finished, we will miss following imu data. I try to use snapshot(blocking=False) and check readable(). But when I can snapshot() when readable() == True to get the image, it will trigger another capture.

If so, it will be better to run the camera in free running mode and then just sync reading the accel/gyro to the camera running by itself.

I can not sync imu data to the camera, becuase imu data is sampled in a fixed rate.

Maybe snapshot(trigger=True, blocking=True) to trigger the camera without blocking, so that I can get image later with snapshot(trigger=False) without trigger camera again.

Okay, so, there’s an fifo in the IMU. I’ve never used it, but, that’s going to solve your problem. You can set it up and read/write it using the register interface.

Do this, give an AI coder the IMU datasheet which you can find on the produce page and ask it to implement the necessary code to setup the IMU fifo and have that fifo fill up with samples and make a method that reads the samples out.

You will use these methods then and completely bypass the regular imu methods. Then, you’ll also have the AI write like a trigger method that will start accumulation into the fifo. As for stopping the accumulation, unsure if you need to do that. If you are already forcing the trigger to be on a timed schedule then after you start the IMU collecting data and using it’s fifo you can just leave it running.

By default we bypass the fifo, but, you can enable it and then pull data from that. You won’t loose any samples anymore then. As for alignment, you just need to do this once and then triggering the camera and the fifo should be aligned.

However, I’m not sure if you even need alignment for your app. It sounds like you just want the fifo on and accumulating samples.

Thank you so much for very helpful suggestions

The purpose is to use AE3 for visual-inertial odometry on the drone. In order to archive good result, time alignment between imu and camera is required. I try to implement Nikolic, Janosch, et al. “A synchronized visual-inertial sensor system with FPGA pre-processing for accurate real-time SLAM.” 2014 IEEE international conference on robotics and automation (ICRA) . IEEE, 2014.

I did it before using raspberry pi pico to get imu data and trigger sony imx296 (connected to pi 5). I think AE3 is a good solution for this because of size and well placed imu & camera.

Okay, yeah, then, with the fifo, it will run in the background at a fixed rate.

Thank you very much for helping. I will try to use fifo