summaryrefslogtreecommitdiffstats
path: root/services/sensorservice
diff options
context:
space:
mode:
Diffstat (limited to 'services/sensorservice')
-rw-r--r--services/sensorservice/Android.mk7
-rw-r--r--services/sensorservice/CorrectedGyroSensor.cpp2
-rw-r--r--services/sensorservice/Fusion.cpp16
-rw-r--r--services/sensorservice/GravitySensor.cpp2
-rw-r--r--services/sensorservice/LinearAccelerationSensor.cpp2
-rw-r--r--services/sensorservice/OrientationSensor.cpp5
-rw-r--r--services/sensorservice/RotationVectorSensor.cpp4
-rw-r--r--services/sensorservice/SensorFusion.cpp27
-rw-r--r--services/sensorservice/SensorFusion.h4
-rw-r--r--services/sensorservice/SensorService.cpp76
-rw-r--r--services/sensorservice/SensorService.h19
11 files changed, 77 insertions, 87 deletions
diff --git a/services/sensorservice/Android.mk b/services/sensorservice/Android.mk
index dd698c5..14a4e55 100644
--- a/services/sensorservice/Android.mk
+++ b/services/sensorservice/Android.mk
@@ -12,11 +12,12 @@ LOCAL_SRC_FILES:= \
SensorDevice.cpp \
SensorFusion.cpp \
SensorInterface.cpp \
- SensorService.cpp \
-
+ SensorService.cpp
LOCAL_CFLAGS:= -DLOG_TAG=\"SensorService\"
+LOCAL_CFLAGS += -fvisibility=hidden
+
LOCAL_SHARED_LIBRARIES := \
libcutils \
libhardware \
@@ -27,8 +28,6 @@ LOCAL_SHARED_LIBRARIES := \
libui \
libgui
-
-
LOCAL_MODULE:= libsensorservice
include $(BUILD_SHARED_LIBRARY)
diff --git a/services/sensorservice/CorrectedGyroSensor.cpp b/services/sensorservice/CorrectedGyroSensor.cpp
index 1857443..09f60a9 100644
--- a/services/sensorservice/CorrectedGyroSensor.cpp
+++ b/services/sensorservice/CorrectedGyroSensor.cpp
@@ -69,7 +69,7 @@ status_t CorrectedGyroSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor CorrectedGyroSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Corrected Gyroscope Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 1;
hwSensor.handle = '_cgy';
hwSensor.type = SENSOR_TYPE_GYROSCOPE;
diff --git a/services/sensorservice/Fusion.cpp b/services/sensorservice/Fusion.cpp
index 93d6127..4f63c31 100644
--- a/services/sensorservice/Fusion.cpp
+++ b/services/sensorservice/Fusion.cpp
@@ -220,22 +220,6 @@ void Fusion::initFusion(const vec4_t& q, float dT)
// initial covariance: Var{ x(t0) }
// TODO: initialize P correctly
P = 0;
-
- // it is unclear how to set the initial covariance. It does affect
- // how quickly the fusion converges. Experimentally it would take
- // about 10 seconds at 200 Hz to estimate the gyro-drift with an
- // initial covariance of 0, and about a second with an initial covariance
- // of about 1 deg/s.
- const float covv = 0;
- const float covu = 0.5f * (float(M_PI) / 180);
- mat33_t& Pv = P[0][0];
- Pv[0][0] = covv;
- Pv[1][1] = covv;
- Pv[2][2] = covv;
- mat33_t& Pu = P[1][1];
- Pu[0][0] = covu;
- Pu[1][1] = covu;
- Pu[2][2] = covu;
}
bool Fusion::hasEstimate() const {
diff --git a/services/sensorservice/GravitySensor.cpp b/services/sensorservice/GravitySensor.cpp
index c57715f..0bf20db 100644
--- a/services/sensorservice/GravitySensor.cpp
+++ b/services/sensorservice/GravitySensor.cpp
@@ -77,7 +77,7 @@ status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor GravitySensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Gravity Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 3;
hwSensor.handle = '_grv';
hwSensor.type = SENSOR_TYPE_GRAVITY;
diff --git a/services/sensorservice/LinearAccelerationSensor.cpp b/services/sensorservice/LinearAccelerationSensor.cpp
index f0054f2..25ae473 100644
--- a/services/sensorservice/LinearAccelerationSensor.cpp
+++ b/services/sensorservice/LinearAccelerationSensor.cpp
@@ -62,7 +62,7 @@ Sensor LinearAccelerationSensor::getSensor() const {
Sensor gsensor(mGravitySensor.getSensor());
sensor_t hwSensor;
hwSensor.name = "Linear Acceleration Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = gsensor.getVersion();
hwSensor.handle = '_lin';
hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION;
diff --git a/services/sensorservice/OrientationSensor.cpp b/services/sensorservice/OrientationSensor.cpp
index 037adaa..b146332 100644
--- a/services/sensorservice/OrientationSensor.cpp
+++ b/services/sensorservice/OrientationSensor.cpp
@@ -33,6 +33,9 @@ OrientationSensor::OrientationSensor()
: mSensorDevice(SensorDevice::getInstance()),
mSensorFusion(SensorFusion::getInstance())
{
+ // FIXME: instead of using the SensorFusion code, we should use
+ // the SENSOR_TYPE_ROTATION_VECTOR instead. This way we could use the
+ // HAL's implementation.
}
bool OrientationSensor::process(sensors_event_t* outEvent,
@@ -73,7 +76,7 @@ status_t OrientationSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor OrientationSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Orientation Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 1;
hwSensor.handle = '_ypr';
hwSensor.type = SENSOR_TYPE_ORIENTATION;
diff --git a/services/sensorservice/RotationVectorSensor.cpp b/services/sensorservice/RotationVectorSensor.cpp
index 5ea9568..725deb4 100644
--- a/services/sensorservice/RotationVectorSensor.cpp
+++ b/services/sensorservice/RotationVectorSensor.cpp
@@ -63,7 +63,7 @@ status_t RotationVectorSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor RotationVectorSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Rotation Vector Sensor";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 3;
hwSensor.handle = '_rov';
hwSensor.type = SENSOR_TYPE_ROTATION_VECTOR;
@@ -112,7 +112,7 @@ status_t GyroDriftSensor::setDelay(void* ident, int handle, int64_t ns) {
Sensor GyroDriftSensor::getSensor() const {
sensor_t hwSensor;
hwSensor.name = "Gyroscope Bias (debug)";
- hwSensor.vendor = "Google Inc.";
+ hwSensor.vendor = "AOSP";
hwSensor.version = 1;
hwSensor.handle = '_gbs';
hwSensor.type = SENSOR_TYPE_ACCELEROMETER;
diff --git a/services/sensorservice/SensorFusion.cpp b/services/sensorservice/SensorFusion.cpp
index d23906d..a0a17da 100644
--- a/services/sensorservice/SensorFusion.cpp
+++ b/services/sensorservice/SensorFusion.cpp
@@ -28,6 +28,7 @@ SensorFusion::SensorFusion()
mEnabled(false), mGyroTime(0)
{
sensor_t const* list;
+ Sensor uncalibratedGyro;
ssize_t count = mSensorDevice.getSensorList(&list);
if (count > 0) {
for (size_t i=0 ; i<size_t(count) ; i++) {
@@ -39,28 +40,38 @@ SensorFusion::SensorFusion()
}
if (list[i].type == SENSOR_TYPE_GYROSCOPE) {
mGyro = Sensor(list + i);
- // 200 Hz for gyro events is a good compromise between precision
- // and power/cpu usage.
- mGyroRate = 200;
- mTargetDelayNs = 1000000000LL/mGyroRate;
}
+ if (list[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
+ uncalibratedGyro = Sensor(list + i);
+ }
+ }
+
+ // Use the uncalibrated gyroscope for sensor fusion when available
+ if (uncalibratedGyro.getType() == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
+ mGyro = uncalibratedGyro;
}
+
+ // 200 Hz for gyro events is a good compromise between precision
+ // and power/cpu usage.
+ mEstimatedGyroRate = 200;
+ mTargetDelayNs = 1000000000LL/mEstimatedGyroRate;
mFusion.init();
}
}
void SensorFusion::process(const sensors_event_t& event) {
- if (event.type == SENSOR_TYPE_GYROSCOPE) {
+ if (event.type == mGyro.getType()) {
if (mGyroTime != 0) {
const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
+ mFusion.handleGyro(vec3_t(event.data), dT);
+ // here we estimate the gyro rate (useful for debugging)
const float freq = 1 / dT;
if (freq >= 100 && freq<1000) { // filter values obviously wrong
const float alpha = 1 / (1 + dT); // 1s time-constant
- mGyroRate = freq + (mGyroRate - freq)*alpha;
+ mEstimatedGyroRate = freq + (mEstimatedGyroRate - freq)*alpha;
}
}
mGyroTime = event.timestamp;
- mFusion.handleGyro(vec3_t(event.data), 1.0f/mGyroRate);
} else if (event.type == SENSOR_TYPE_MAGNETIC_FIELD) {
const vec3_t mag(event.data);
mFusion.handleMag(mag);
@@ -132,7 +143,7 @@ void SensorFusion::dump(String8& result, char* buffer, size_t SIZE) {
"b=< %g, %g, %g >\n",
mEnabled ? "enabled" : "disabled",
mClients.size(),
- mGyroRate,
+ mEstimatedGyroRate,
fusion.getAttitude().x,
fusion.getAttitude().y,
fusion.getAttitude().z,
diff --git a/services/sensorservice/SensorFusion.h b/services/sensorservice/SensorFusion.h
index 4c99bcb..3c2244e 100644
--- a/services/sensorservice/SensorFusion.h
+++ b/services/sensorservice/SensorFusion.h
@@ -44,7 +44,7 @@ class SensorFusion : public Singleton<SensorFusion> {
Sensor mGyro;
Fusion mFusion;
bool mEnabled;
- float mGyroRate;
+ float mEstimatedGyroRate;
nsecs_t mTargetDelayNs;
nsecs_t mGyroTime;
vec4_t mAttitude;
@@ -60,7 +60,7 @@ public:
mat33_t getRotationMatrix() const { return mFusion.getRotationMatrix(); }
vec4_t getAttitude() const { return mAttitude; }
vec3_t getGyroBias() const { return mFusion.getBias(); }
- float getEstimatedRate() const { return mGyroRate; }
+ float getEstimatedRate() const { return mEstimatedGyroRate; }
status_t activate(void* ident, bool enabled);
status_t setDelay(void* ident, int64_t ns);
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index ebf5cf0..4718447 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -93,6 +93,7 @@ void SensorService::onFirstRef()
orientationIndex = i;
break;
case SENSOR_TYPE_GYROSCOPE:
+ case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
hasGyro = true;
break;
case SENSOR_TYPE_GRAVITY:
@@ -108,54 +109,44 @@ void SensorService::onFirstRef()
// registered)
const SensorFusion& fusion(SensorFusion::getInstance());
+ // build the sensor list returned to users
+ mUserSensorList = mSensorList;
+
if (hasGyro) {
- // Always instantiate Android's virtual sensors. Since they are
- // instantiated behind sensors from the HAL, they won't
- // interfere with applications, unless they looks specifically
- // for them (by name).
+ Sensor aSensor;
- registerVirtualSensor( new RotationVectorSensor() );
- registerVirtualSensor( new GravitySensor(list, count) );
- registerVirtualSensor( new LinearAccelerationSensor(list, count) );
+ // Add Android virtual sensors if they're not already
+ // available in the HAL
- // these are optional
- registerVirtualSensor( new OrientationSensor() );
- registerVirtualSensor( new CorrectedGyroSensor(list, count) );
- }
+ aSensor = registerVirtualSensor( new RotationVectorSensor() );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
+ mUserSensorList.add(aSensor);
+ }
- // build the sensor list returned to users
- mUserSensorList = mSensorList;
+ aSensor = registerVirtualSensor( new GravitySensor(list, count) );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_GRAVITY)) {
+ mUserSensorList.add(aSensor);
+ }
- if (hasGyro) {
- // virtual debugging sensors are not added to mUserSensorList
- registerVirtualSensor( new GyroDriftSensor() );
- }
+ aSensor = registerVirtualSensor( new LinearAccelerationSensor(list, count) );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_LINEAR_ACCELERATION)) {
+ mUserSensorList.add(aSensor);
+ }
- if (hasGyro &&
- (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR))) {
- // if we have the fancy sensor fusion, and it's not provided by the
- // HAL, use our own (fused) orientation sensor by removing the
- // HAL supplied one form the user list.
- if (orientationIndex >= 0) {
- mUserSensorList.removeItemsAt(orientationIndex);
+ aSensor = registerVirtualSensor( new OrientationSensor() );
+ if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
+ // if we are doing our own rotation-vector, also add
+ // the orientation sensor and remove the HAL provided one.
+ mUserSensorList.replaceAt(aSensor, orientationIndex);
}
+
+ // virtual debugging sensors are not added to mUserSensorList
+ registerVirtualSensor( new CorrectedGyroSensor(list, count) );
+ registerVirtualSensor( new GyroDriftSensor() );
}
// debugging sensor list
- for (size_t i=0 ; i<mSensorList.size() ; i++) {
- switch (mSensorList[i].getType()) {
- case SENSOR_TYPE_GRAVITY:
- case SENSOR_TYPE_LINEAR_ACCELERATION:
- case SENSOR_TYPE_ROTATION_VECTOR:
- if (strstr(mSensorList[i].getVendor().string(), "Google")) {
- mUserSensorListDebug.add(mSensorList[i]);
- }
- break;
- default:
- mUserSensorListDebug.add(mSensorList[i]);
- break;
- }
- }
+ mUserSensorListDebug = mSensorList;
run("SensorService", PRIORITY_URGENT_DISPLAY);
mInitCheck = NO_ERROR;
@@ -163,7 +154,7 @@ void SensorService::onFirstRef()
}
}
-void SensorService::registerSensor(SensorInterface* s)
+Sensor SensorService::registerSensor(SensorInterface* s)
{
sensors_event_t event;
memset(&event, 0, sizeof(event));
@@ -175,12 +166,15 @@ void SensorService::registerSensor(SensorInterface* s)
mSensorMap.add(sensor.getHandle(), s);
// create an entry in the mLastEventSeen array
mLastEventSeen.add(sensor.getHandle(), event);
+
+ return sensor;
}
-void SensorService::registerVirtualSensor(SensorInterface* s)
+Sensor SensorService::registerVirtualSensor(SensorInterface* s)
{
- registerSensor(s);
+ Sensor sensor = registerSensor(s);
mVirtualSensorList.add( s );
+ return sensor;
}
SensorService::~SensorService()
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index 25e5f76..67489cc 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -50,12 +50,13 @@ class SensorService :
public BnSensorServer,
protected Thread
{
- friend class BinderService<SensorService>;
+ friend class BinderService<SensorService>;
- static const nsecs_t MINIMUM_EVENTS_PERIOD = 1000000; // 1000 Hz
- static const char* WAKE_LOCK_NAME;
+ static const nsecs_t MINIMUM_EVENTS_PERIOD = 1000000; // 1000 Hz
+ static const char* WAKE_LOCK_NAME;
- SensorService();
+ static char const* getServiceName() ANDROID_API { return "sensorservice"; }
+ SensorService() ANDROID_API;
virtual ~SensorService();
virtual void onFirstRef();
@@ -113,12 +114,12 @@ class SensorService :
int getSensorType(int handle) const;
void recordLastValue(sensors_event_t const * buffer, size_t count);
static void sortEventBuffer(sensors_event_t* buffer, size_t count);
- void registerSensor(SensorInterface* sensor);
- void registerVirtualSensor(SensorInterface* sensor);
+ Sensor registerSensor(SensorInterface* sensor);
+ Sensor registerVirtualSensor(SensorInterface* sensor);
status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection,
- int handle);
+ int handle);
void cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection,
- sensors_event_t const* buffer, const int count);
+ sensors_event_t const* buffer, const int count);
// constants
Vector<Sensor> mSensorList;
@@ -138,8 +139,6 @@ class SensorService :
KeyedVector<int32_t, sensors_event_t> mLastEventSeen;
public:
- static char const* getServiceName() { return "sensorservice"; }
-
void cleanupConnection(SensorEventConnection* connection);
status_t enable(const sp<SensorEventConnection>& connection, int handle);
status_t disable(const sp<SensorEventConnection>& connection, int handle);