summaryrefslogtreecommitdiffstats
path: root/libs/androidfw
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-06-04 13:13:30 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-06-04 13:13:30 -0700
commitba58221769575d1129c61fe0da9030986eb899bd (patch)
treecca06da3f48e1d399703b31f9bec74bae1188881 /libs/androidfw
parent2fd6baef5911d3bb481d1a603180d7371d43df41 (diff)
parenta5b0698231459ac5b54cf8e8952ac5c2b2b2198b (diff)
downloadframeworks_base-ba58221769575d1129c61fe0da9030986eb899bd.zip
frameworks_base-ba58221769575d1129c61fe0da9030986eb899bd.tar.gz
frameworks_base-ba58221769575d1129c61fe0da9030986eb899bd.tar.bz2
am a5b06982: Implement a second order integrating VT strategy.
* commit 'a5b0698231459ac5b54cf8e8952ac5c2b2b2198b': Implement a second order integrating VT strategy.
Diffstat (limited to 'libs/androidfw')
-rw-r--r--libs/androidfw/VelocityTracker.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/libs/androidfw/VelocityTracker.cpp b/libs/androidfw/VelocityTracker.cpp
index 17cefbe..fc75576 100644
--- a/libs/androidfw/VelocityTracker.cpp
+++ b/libs/androidfw/VelocityTracker.cpp
@@ -182,7 +182,13 @@ VelocityTrackerStrategy* VelocityTracker::createStrategy(const char* strategy) {
// more tolerant of errors. Like 'lsq1', this strategy tends to underestimate
// the velocity of a fling but this strategy tends to respond to changes in
// direction more quickly and accurately.
- return new IntegratingVelocityTrackerStrategy();
+ return new IntegratingVelocityTrackerStrategy(1);
+ }
+ if (!strcmp("int2", strategy)) {
+ // 2nd order integrating filter. Quality: EXPERIMENTAL.
+ // For comparison purposes only. Unlike 'int1' this strategy can compensate
+ // for acceleration but it typically overestimates the effect.
+ return new IntegratingVelocityTrackerStrategy(2);
}
return NULL;
}
@@ -680,7 +686,8 @@ float LeastSquaresVelocityTrackerStrategy::chooseWeight(uint32_t index) const {
// --- IntegratingVelocityTrackerStrategy ---
-IntegratingVelocityTrackerStrategy::IntegratingVelocityTrackerStrategy() {
+IntegratingVelocityTrackerStrategy::IntegratingVelocityTrackerStrategy(uint32_t degree) :
+ mDegree(degree) {
}
IntegratingVelocityTrackerStrategy::~IntegratingVelocityTrackerStrategy() {
@@ -725,18 +732,20 @@ bool IntegratingVelocityTrackerStrategy::getEstimator(uint32_t id,
}
void IntegratingVelocityTrackerStrategy::initState(State& state,
- nsecs_t eventTime, float xpos, float ypos) {
+ nsecs_t eventTime, float xpos, float ypos) const {
state.updateTime = eventTime;
- state.first = true;
+ state.degree = 0;
state.xpos = xpos;
state.xvel = 0;
+ state.xaccel = 0;
state.ypos = ypos;
state.yvel = 0;
+ state.yaccel = 0;
}
void IntegratingVelocityTrackerStrategy::updateState(State& state,
- nsecs_t eventTime, float xpos, float ypos) {
+ nsecs_t eventTime, float xpos, float ypos) const {
const nsecs_t MIN_TIME_DELTA = 2 * NANOS_PER_MS;
const float FILTER_TIME_CONSTANT = 0.010f; // 10 milliseconds
@@ -749,28 +758,45 @@ void IntegratingVelocityTrackerStrategy::updateState(State& state,
float xvel = (xpos - state.xpos) / dt;
float yvel = (ypos - state.ypos) / dt;
- if (state.first) {
+ if (state.degree == 0) {
state.xvel = xvel;
state.yvel = yvel;
- state.first = false;
+ state.degree = 1;
} else {
float alpha = dt / (FILTER_TIME_CONSTANT + dt);
- state.xvel += (xvel - state.xvel) * alpha;
- state.yvel += (yvel - state.yvel) * alpha;
+ if (mDegree == 1) {
+ state.xvel += (xvel - state.xvel) * alpha;
+ state.yvel += (yvel - state.yvel) * alpha;
+ } else {
+ float xaccel = (xvel - state.xvel) / dt;
+ float yaccel = (yvel - state.yvel) / dt;
+ if (state.degree == 1) {
+ state.xaccel = xaccel;
+ state.yaccel = yaccel;
+ state.degree = 2;
+ } else {
+ state.xaccel += (xaccel - state.xaccel) * alpha;
+ state.yaccel += (yaccel - state.yaccel) * alpha;
+ }
+ state.xvel += (state.xaccel * dt) * alpha;
+ state.yvel += (state.yaccel * dt) * alpha;
+ }
}
state.xpos = xpos;
state.ypos = ypos;
}
void IntegratingVelocityTrackerStrategy::populateEstimator(const State& state,
- VelocityTracker::Estimator* outEstimator) {
+ VelocityTracker::Estimator* outEstimator) const {
outEstimator->time = state.updateTime;
- outEstimator->degree = 1;
outEstimator->confidence = 1.0f;
+ outEstimator->degree = state.degree;
outEstimator->xCoeff[0] = state.xpos;
outEstimator->xCoeff[1] = state.xvel;
+ outEstimator->xCoeff[2] = state.xaccel / 2;
outEstimator->yCoeff[0] = state.ypos;
outEstimator->yCoeff[1] = state.yvel;
+ outEstimator->yCoeff[2] = state.yaccel / 2;
}
} // namespace android