Accelerometer Data

edited April 2016 in Android
Hi I need to work with 3 accelerometer axes of metawear. Now I am using only x axes but dont fix. Someone can help me please. I attach the code.
Adding, Can I compare, plus, sustract the values of the axes for example (x axes value - y axes value) or something like that? How have I manage the adquisition of data?
Code:
        findViewById(R.id.start_accel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
accelModule.enableAxisSampling();
accelModule.start();
}
});
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
serviceBinder = (MetaWearBleService.LocalBinder) service;
String mwMacAddress="C3:DA:B6:74:FF:05";
BluetoothManager btManager=(BluetoothManager)getSystemService(BLUETOOTH_SERVICE);
BluetoothDevice btDevice=btManager.getAdapter().getRemoteDevice(mwMacAddress);

mwBoard=serviceBinder.getMetaWearBoard(btDevice);
mwBoard.setConnectionStateHandler(new MetaWearBoard.ConnectionStateHandler() {
@Override
public void disconnected() {
Log.i(LOG_TAG,"Disconnected");
}

@Override
public void connected() {
Log.i(LOG_TAG, "Connected");
try {

accelModule=mwBoard.getModule(Accelerometer.class);
accelModule.setOutputDataRate(50f);
accelModule.setAxisSamplingRange((float) 2);
accelModule.routeData().fromXAxis()
.process(new Sample(sampleSize))
.process(X_DATA,new Passthrough(Passthrough.Mode.COUNT,(short) 0))
.stream(X_DATA)
.process(new Time(Time.OutputMode.ABSOLUTE,2))
.commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe(X_DATA, new RouteManager.MessageHandler() {
@Override
public void process(Message message) {
Log.i("X Axis", " " + message.getData(Float.class));
}
});
}
});

debugModule=mwBoard.getModule(Debug.class);

} catch (UnsupportedModuleException e) {
Log.e(LOG_TAG,"Cannot find module",e);
}


}

});
mwBoard.connect();
}

@Override
public void onServiceDisconnected(ComponentName name) {

}
}

Comments

  • 1) The passthrough filter you are using, as presently configured, is blocking all incoming data.

    2) You should be able to manipulate accelerometer data in that fashion (math ops, comp, etc.) using feedback loops.  What specifically are you trying to compute?

    3) Depends on how you want to use the data.  You can use an ArrayList to temporarily store data, an SQLlite database for persistance, or use an CSV file / cloud solution for exporting data to other machines.
  • Thanks Eric,
    You are very helpfully. For my project I want to implement this code,where  (x,y,z) are accelerometer data (x,y,z) and analice 50 data each time

    suma=0;

    muestras=50;

    est_ant=1;

    r=y-z;

    vu=-0.1;

    %%This process have to repeat all the time

    while muestras~=0

    if r<=vu

        suma=suma-1;

    else

        suma=suma+1;

    end

    muestra=muestra-1;

    end

    if muestra==0

        if suma==49||
    suma==50

        disp('message 1')

        est_ant=1;

        else

            if
    suma==-49|| suma==-50

            disp ('message
    2')

            est_ant=-1;

            else

                if
    est_ant==-1

                disp('message
    2')

                else

                    if
    est_ant==1

                       
    disp('message 1')

                    end

                end

            end

        end

    end

     muestras=50;

     suma=0;

     After I want to reemplace the disp('message 1') for some
    action like a sound, a message... In addition I need to save  how many time appear the message 1 and message
    2 result in a day or during a period of time the app was used. I can save this
    information in a document to send or only show before close the app.

  • edited May 2016
    I'm not sure if you can build a data processing chain that can accomplish the same thing as your code.  The biggest roadblock is the accumulator variable (suma) that is either incremented or decremented based on some condition; there is direct equivalent of this in the data processor.  Furthermore, there is no boolean logic in the data processor.  In your case, an OR operation should be ok if you have 2 separate signals that trigger the same action.




    I played around with the API a bit and came up with this way to compute "y-x" using solely the data processing.
    final Accelerometer accModule= mwBoard.getModule(Accelerometer.class);
    accModule.routeData().fromYAxis().process(new Sample((byte) 1)).process("y-axis", new Maths(Maths.Operation.SUBTRACT, 0)).stream("difference")
    .commit().onComplete(new CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    result.subscribe("difference", new RouteManager.MessageHandler() {
    @Override
    public void process(Message msg) {
    Bmi160SingleAxisMessage bmi160Msg= (Bmi160SingleAxisMessage) msg;
    short unscaled= (short) (bmi160Msg.getData()[0] | (bmi160Msg.getData()[1] << 8));
    Log.i("test", "Difference= " + (unscaled / bmi160Msg.getScale()));
    }
    });
    }
    });
    accModule.routeData().fromXAxis().monitor(new ActivityHandler() {
    @Override
    public void onSignalActive(Map<String, DataProcessor> processors, DataToken token) {
    processors.get("y-axis").modifyConfiguration(new Maths(Maths.Operation.SUBTRACT, token));
    }
    }).commit();
This discussion has been closed.