Exception on accelerometer single axis

Hi,

I’m trying to read accelerometer's Z Axis only (or X, Y), I got an exception:

"Subscribing to single axis sources is not supported.  Subscribe to the full data source instead"

Here is my code:

                final Bmi160Accelerometer accel = mwBoard.getModule(Bmi160Accelerometer.class);

                accel.routeData()
                        .fromZAxis()
//                        .process(new Average((byte) 8))
//                        .process(new Threshold(0.9, Threshold.OutputMode.ABSOLUTE, 1.1))
                        .stream("accel_stream")
                        .commit()
                        .onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
                            @Override
                            public void success(RouteManager result) {
                                result.subscribe("accel_stream", new RouteManager.MessageHandler() {
                                    @Override
                                    public void process(Message msg) {
                                        Log.i(TAG, msg.toString());
                                    }
                                });

                                accel.configureAxisSampling()
                                        .setFullScaleRange(Bmi160Accelerometer.AccRange.AR_8G)
                                        .setOutputDataRate(Bmi160Accelerometer.OutputDataRate.ODR_6_25_HZ)
                                        .commit();
                                accel.enableAxisSampling();
                                accel.start();
                            }

                            @Override
                            public void failure(Throwable error) {
                                Log.e(TAG, "Read Accel failed: ", error);
                            }
                        });

Any ideas?


Comments

  • The error message explains the issue at hand.  You cannot subscribe a single axis value, you instead subscribe to the full xyz values where you can extract the z value from the stream.
  • Hi Eric,

    If I subscribe the full xyz values, the threshold filter couldn't work. I got an except of "Cannot detect thresholds on data longer than 4 bytes".

    How can I use the filter on accelerometer data?

    Thanks.





  • Create two route: one for streaming the xyz values and one with your data processing chain.
  • Eric, can you further explain this and maybe provide example code? I've seen many samples that do exactly what leihaiyong is doing (routeData().fromXAxis()...., example here), but I'm getting the same exception. Are these examples incomplete, is the feature deprecated, or is support specific to the board models?

    Like leihaiyong, i'm trying to conserve battery by only sending X-axis data when it exceeds the threshold. By creating two routes like you suggest, do you still accomplish this goal?

    Thanks!
  • None of the code in the link subscribe to a single axis, which is what leihaiyong's code is doing.  The code snippets apply data processors and subscribe to the output from a processor.
This discussion has been closed.