Filtering Sensor Fusion Data

Hi!

I would like to log sensor fusion data but apply the following filters:

- Only store data when the device is moving (not static)
- When the device is moving, only store every 10th data point (100Hz data is not required)

Are there any code examples where this, or similar has been achieved?

Would i have to use gyro or accelerometer data to choose when to store the sensor fusion data: ie. when a spike in acceleration is detected, then store the quarternion?

Thanks!!

-Tom

Comments

  • The BMI160 chip has built in features for motion detection.

    You can use a time limiter to reduce the data rate to 10Hz.

    In terms of using these together, I'd use a conditional passthrough limiter that is enabled if no motion is detected and disabled after a period of time using the Timer module.  When no motion is detected, it will also reset the timer.  Ideally you would have the passthrough gate closed when motion is detected however you cannot run different motion detection algorithms simultaneously.
  • Thanks Eric,

    So I need to set up two routes. One to the accelerometer and one to sensor fusion?

    Then I set up the first route to set a passthrough value to 1 if motion is detected. Then, can I use this passthrough value in the second route to dictate when to dictate record sensor fusion data?

    I'm struggling to get the two routes to work simultaneously - I must be doing something wrong?

    Thanks

    -Tom
  • What do you have so far?
  • currently using gyro to determine if the board is moving. But i'll change it to the movement detector you suggested

    gyro = board.getModule(GyroBmi160.class);
    gyro.configure()
    .odr(GyroBmi160.OutputDataRate.ODR_25_HZ)
    .range(GyroBmi160.Range.FSR_2000)
    .commit();
    gyro.angularVelocity().addRouteAsync(new RouteBuilder() {
    @Override
    public void configure(RouteComponent source) {
    source
    .map(Function1.RSS)
    .average((byte) 5)
    .filter(Comparison.GT, 10f)
    .react(new RouteComponent.Action() {
    @Override
    public void execute(DataToken token) {
    // Set filterAcc to 1 if the data is over the threshold
    dataprocessor.edit("filterAcc", DataProcessor.PassthroughEditor.class).set((short) 1);
    Log.i("freefall", "SF Moving");
    }
    })
    .end();
    }
    });

    Log.i("freefall", "Setting Up Fusion 2");

    sensorFusion = board.getModule(SensorFusionBosch.class);
    sensorFusion.configure()
    .mode(SensorFusionBosch.Mode.NDOF)
    .accRange(SensorFusionBosch.AccRange.AR_16G)
    .gyroRange(SensorFusionBosch.GyroRange.GR_2000DPS)
    .commit();
    return sensorFusion.quaternion().addRouteAsync(new RouteBuilder() {
    @Override
    public void configure(RouteComponent source) {
    source
    //.limit(100)
    .limit(Passthrough.CONDITIONAL, (short) 1)
    .name("filterAcc")
    .limit(100)
    .log(new Subscriber() {
    @Override
    public void apply(Data data, Object... env) {
    final String dataTime = data.formattedTimestamp();
    Quaternion dataString = data.value(Quaternion.class);
    dataList.add(dataTime + ", " + dataString.w()+ ", " + dataString.x() + ", " + dataString.y() + ", " + dataString.z());
    Log.i("freefall", "Quaternion = " + dataString.toString());
    dataprocessor.edit("filterAcc", DataProcessor.PassthroughEditor.class).set((short) 0);
    }
    });
    }
    });
  • Hrm, the code looks fine except for 2 things:
    1. Do not configure the gyro when using sensor fusion.
    2. Async tasks need to be chained.
    Have you tested that the routes individually are working as expected?
  • Hi Eric,

    if I don't configure the gyro (or motion detector), how can I use the gyro (or motion detector) to detect movement before logging the sensor fusion data?

    Can I detect motion from within a sensor fusion quarternion route, or do I need two routes?

    Can I chaing a motion detector route with a quarternion route??

    Thanks!

    -Tom
    1. The sensor fusion module configures the required sensors internally.  You can configure motion detection after you have written the sensor fusion configuration, but you should not modify the range and odr.
    2. No, you need two routes.
    3. Yes
This discussion has been closed.