Accelerometer Data
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) {
}
}
This discussion has been closed.
Comments
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.
I played around with the API a bit and came up with this way to compute "y-x" using solely the data processing.