use quaternions instead of MRPs
also use correct time propagation equation
disable the fused sensors when gyro is not present since
they were unusable in practice.
Change-Id: Iad797425784e67dc6c5690e97c71c583418cc5b5
diff --git a/services/sensorservice/GravitySensor.cpp b/services/sensorservice/GravitySensor.cpp
index 541fad2..c57715f 100644
--- a/services/sensorservice/GravitySensor.cpp
+++ b/services/sensorservice/GravitySensor.cpp
@@ -31,10 +31,7 @@
GravitySensor::GravitySensor(sensor_t const* list, size_t count)
: mSensorDevice(SensorDevice::getInstance()),
- mSensorFusion(SensorFusion::getInstance()),
- mAccTime(0),
- mLowPass(M_SQRT1_2, 1.5f),
- mX(mLowPass), mY(mLowPass), mZ(mLowPass)
+ mSensorFusion(SensorFusion::getInstance())
{
for (size_t i=0 ; i<count ; i++) {
if (list[i].type == SENSOR_TYPE_ACCELEROMETER) {
@@ -50,30 +47,14 @@
const static double NS2S = 1.0 / 1000000000.0;
if (event.type == SENSOR_TYPE_ACCELEROMETER) {
vec3_t g;
- if (mSensorFusion.hasGyro()) {
- if (!mSensorFusion.hasEstimate())
- return false;
- const mat33_t R(mSensorFusion.getRotationMatrix());
- // FIXME: we need to estimate the length of gravity because
- // the accelerometer may have a small scaling error. This
- // translates to an offset in the linear-acceleration sensor.
- g = R[2] * GRAVITY_EARTH;
- } else {
- const double now = event.timestamp * NS2S;
- if (mAccTime == 0) {
- g.x = mX.init(event.acceleration.x);
- g.y = mY.init(event.acceleration.y);
- g.z = mZ.init(event.acceleration.z);
- } else {
- double dT = now - mAccTime;
- mLowPass.setSamplingPeriod(dT);
- g.x = mX(event.acceleration.x);
- g.y = mY(event.acceleration.y);
- g.z = mZ(event.acceleration.z);
- }
- g *= (GRAVITY_EARTH / length(g));
- mAccTime = now;
- }
+ if (!mSensorFusion.hasEstimate())
+ return false;
+ const mat33_t R(mSensorFusion.getRotationMatrix());
+ // FIXME: we need to estimate the length of gravity because
+ // the accelerometer may have a small scaling error. This
+ // translates to an offset in the linear-acceleration sensor.
+ g = R[2] * GRAVITY_EARTH;
+
*outEvent = event;
outEvent->data[0] = g.x;
outEvent->data[1] = g.y;
@@ -86,42 +67,24 @@
}
status_t GravitySensor::activate(void* ident, bool enabled) {
- status_t err;
- if (mSensorFusion.hasGyro()) {
- err = mSensorFusion.activate(this, enabled);
- } else {
- err = mSensorDevice.activate(this, mAccelerometer.getHandle(), enabled);
- if (err == NO_ERROR) {
- if (enabled) {
- mAccTime = 0;
- }
- }
- }
- return err;
+ return mSensorFusion.activate(this, enabled);
}
-status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns)
-{
- if (mSensorFusion.hasGyro()) {
- return mSensorFusion.setDelay(this, ns);
- } else {
- return mSensorDevice.setDelay(this, mAccelerometer.getHandle(), ns);
- }
+status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns) {
+ return mSensorFusion.setDelay(this, ns);
}
Sensor GravitySensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Gravity Sensor";
hwSensor.vendor = "Google Inc.";
- hwSensor.version = mSensorFusion.hasGyro() ? 3 : 2;
+ hwSensor.version = 3;
hwSensor.handle = '_grv';
hwSensor.type = SENSOR_TYPE_GRAVITY;
hwSensor.maxRange = GRAVITY_EARTH * 2;
hwSensor.resolution = mAccelerometer.getResolution();
- hwSensor.power = mSensorFusion.hasGyro() ?
- mSensorFusion.getPowerUsage() : mAccelerometer.getPowerUsage();
- hwSensor.minDelay = mSensorFusion.hasGyro() ?
- mSensorFusion.getMinDelay() : mAccelerometer.getMinDelay();
+ hwSensor.power = mSensorFusion.getPowerUsage();
+ hwSensor.minDelay = mSensorFusion.getMinDelay();
Sensor sensor(&hwSensor);
return sensor;
}