Only Y axis filtered from Accelerometer
I need to check the sensor inclination.If the inclination is over 45° i need to do samethink.
I read the accelerometer with :
accelModule.routeData()
.fromAxes()
.stream("accelSub")/*.log("accelLogger")*/
.commit()
.onComplete(new CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("accelSub", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
final CartesianShort axisData = msg.getData(CartesianShort.class);
int inclination = (int) (axisData.y()/11.41);
String val = String.format("%s %d°", axisData.toString(),inclination);
Log.i("test", "Stream: "+val);
}
});
.......
}
});
Ok, work fine. But i would like to filter the data under 45° because i think this limit battery usage.
I try to read acceletometer only for the Y axies,(because i read the Comparison is not possibile on all axies), with fromYAxis but the value is very different.
accelModule.routeData()
.fromYAxis()
.process(new Comparison(Comparison.Operation.GTE, 500))
.stream("accelSub")
/*.log("accelLogger")*/
.commit()
.onComplete(new CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("accelSub", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
Bmi160SingleAxisMessage bmi160Msg= (Bmi160SingleAxisMessage) msg;
Log.i("test","SingleAxisMessage Y = "+msg.getData(Float.class));
}
});
.....
}
});
If i read CartesianShort with fromAxes the Y is beetween 0 - 1030
but if i read Bmi160SingleAxisMessage with fromYAxis the interval is 500 (correct because i Comparison it) - 49000
Same one have an explanation or same suggestions
I read the accelerometer with :
accelModule.routeData()
.fromAxes()
.stream("accelSub")/*.log("accelLogger")*/
.commit()
.onComplete(new CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("accelSub", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
final CartesianShort axisData = msg.getData(CartesianShort.class);
int inclination = (int) (axisData.y()/11.41);
String val = String.format("%s %d°", axisData.toString(),inclination);
Log.i("test", "Stream: "+val);
}
});
.......
}
});
Ok, work fine. But i would like to filter the data under 45° because i think this limit battery usage.
I try to read acceletometer only for the Y axies,(because i read the Comparison is not possibile on all axies), with fromYAxis but the value is very different.
accelModule.routeData()
.fromYAxis()
.process(new Comparison(Comparison.Operation.GTE, 500))
.stream("accelSub")
/*.log("accelLogger")*/
.commit()
.onComplete(new CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("accelSub", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
Bmi160SingleAxisMessage bmi160Msg= (Bmi160SingleAxisMessage) msg;
Log.i("test","SingleAxisMessage Y = "+msg.getData(Float.class));
}
});
.....
}
});
If i read CartesianShort with fromAxes the Y is beetween 0 - 1030
but if i read Bmi160SingleAxisMessage with fromYAxis the interval is 500 (correct because i Comparison it) - 49000
Same one have an explanation or same suggestions
This discussion has been closed.
Comments
I understand there is a little bug and the API return Y and Z value instead only Y.
But in this way the (unscaled / bmi160Msg.getScale()) is often a low value.
If i don't move the sensor, Y value are same time correct, and same time very low (under 0).
In fromAxes this not occur. The read is more accurate.
With fromYAxis() i cannot you the
process(new Comparison(Comparison.Operation.GTE, 500))
because, i imagine, the comparison is with YZ value and not only on Y axies.
Correct ?
But i want to limit only Y.
I start to think it's not possible, to actual firmware version, to use fromYAxis for limit the information transmitted on BT.
I don't know if i understand well "set the axis sampling range before you construct the data processing chain".
My source is :
accelModule.routeData()
.fromYAxis()
.process(new Maths(Maths.Operation.ADD, 0))
.process(new Comparison(Comparison.Operation.LTE, 0.5))
.stream("accelSub")
.commit()
.onComplete(new CompletionHandler() {
@Override
public void success(RouteManager result) {
result.subscribe("accelSub", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
try {
Bmi160SingleAxisMessage bmi160Msg = (Bmi160SingleAxisMessage) msg;
short unscaled = (short) (bmi160Msg.getData()[0] | (bmi160Msg.getData()[1] << 8));
final Float yAxisData = (unscaled / bmi160Msg.getScale()) * 1000;
int inclination = (int) (yAxisData / 11.41);
String val = String.format("%f %d°", yAxisData, inclination);
Log.i("test", "Stream: " + val);
((TextView) findViewById(R.id.textView3)).setText(val);
}catch (Exception ex) {
Log.e("test","Error in CompletionHandler process : ",ex);
ex.printStackTrace();
}
}
});
accelModule.setOutputDataRate(50.f);
accelSetup = true;
loggingModule.startLogging();
accelModule.enableAxisSampling();
accelModule.start();
}
@Override
public void failure(Throwable error) {
Log.e("test", "Error committing route", error);
accelSetup = false;
}
});
In this way i received often many Y-axis zero, this not occur if i use fromAxes.
Have you a forecast or the new firmware upgrade with the corrected fromYAxis() ?
i remove the bit manipulation and cast the data to a float, and now all work very well.
I update the code if same one need it in the future : Thanks for your support again.