blob: 8c5ee7f350276236271b7db34ee7ec1fecc45277 [file] [log] [blame]
Kevin Gabayan89ecf822015-05-18 12:10:07 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Kevin Gabayan89ecf822015-05-18 12:10:07 -070019import android.hardware.Sensor;
20import android.hardware.SensorEvent;
21import android.hardware.SensorEventListener;
22import android.hardware.SensorManager;
23import android.os.Handler;
24import android.os.Message;
25import android.os.PowerManager;
26import android.os.SystemClock;
27import android.util.Slog;
28
Kevin Gabayan89ecf822015-05-18 12:10:07 -070029/**
30 * Determines if the device has been set upon a stationary object.
31 */
32public class AnyMotionDetector {
33 interface DeviceIdleCallback {
34 public void onAnyMotionResult(int result);
35 }
36
37 private static final String TAG = "AnyMotionDetector";
38
39 private static final boolean DEBUG = false;
40
41 /** Stationary status is unknown due to insufficient orientation measurements. */
42 public static final int RESULT_UNKNOWN = -1;
43
44 /** Device is stationary, e.g. still on a table. */
45 public static final int RESULT_STATIONARY = 0;
46
47 /** Device has been moved. */
48 public static final int RESULT_MOVED = 1;
49
50 /** Orientation measurements are being performed or are planned. */
51 private static final int STATE_INACTIVE = 0;
52
53 /** No orientation measurements are being performed or are planned. */
54 private static final int STATE_ACTIVE = 1;
55
56 /** Current measurement state. */
57 private int mState;
58
Kevin Gabayan89ecf822015-05-18 12:10:07 -070059 /** Threshold energy above which the device is considered moving. */
60 private final float THRESHOLD_ENERGY = 5f;
61
62 /** The duration of the accelerometer orientation measurement. */
63 private static final long ORIENTATION_MEASUREMENT_DURATION_MILLIS = 2500;
64
65 /** The maximum duration we will collect accelerometer data. */
66 private static final long ACCELEROMETER_DATA_TIMEOUT_MILLIS = 3000;
67
68 /** The interval between accelerometer orientation measurements. */
69 private static final long ORIENTATION_MEASUREMENT_INTERVAL_MILLIS = 5000;
70
Kevin Gabayandcf47012016-07-08 10:41:24 -070071 /** The maximum duration we will hold a wakelock to determine stationary status. */
72 private static final long WAKELOCK_TIMEOUT_MILLIS = 30000;
73
Kevin Gabayan89ecf822015-05-18 12:10:07 -070074 /**
75 * The duration in milliseconds after which an orientation measurement is considered
76 * too stale to be used.
77 */
78 private static final int STALE_MEASUREMENT_TIMEOUT_MILLIS = 2 * 60 * 1000;
79
80 /** The accelerometer sampling interval. */
81 private static final int SAMPLING_INTERVAL_MILLIS = 40;
82
Kevin Gabayan89ecf822015-05-18 12:10:07 -070083 private final Handler mHandler;
Kevin Gabayan89ecf822015-05-18 12:10:07 -070084 private final Object mLock = new Object();
85 private Sensor mAccelSensor;
86 private SensorManager mSensorManager;
87 private PowerManager.WakeLock mWakeLock;
88
Joe LaPenna23d681b2015-08-27 15:12:11 -070089 /** Threshold angle in degrees beyond which the device is considered moving. */
90 private final float mThresholdAngle;
91
Kevin Gabayan89ecf822015-05-18 12:10:07 -070092 /** The minimum number of samples required to detect AnyMotion. */
93 private int mNumSufficientSamples;
94
95 /** True if an orientation measurement is in progress. */
96 private boolean mMeasurementInProgress;
97
Nick Vaccaro7510fbb2016-08-19 12:09:50 -070098 /** True if sendMessageDelayed() for the mMeasurementTimeout callback has been scheduled */
99 private boolean mMeasurementTimeoutIsActive;
100
101 /** True if sendMessageDelayed() for the mWakelockTimeout callback has been scheduled */
102 private boolean mWakelockTimeoutIsActive;
103
104 /** True if sendMessageDelayed() for the mSensorRestart callback has been scheduled */
105 private boolean mSensorRestartIsActive;
106
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700107 /** The most recent gravity vector. */
108 private Vector3 mCurrentGravityVector = null;
109
110 /** The second most recent gravity vector. */
111 private Vector3 mPreviousGravityVector = null;
112
113 /** Running sum of squared errors. */
114 private RunningSignalStats mRunningStats;
115
116 private DeviceIdleCallback mCallback = null;
117
Dianne Hackborn42df4fb2015-08-14 16:43:14 -0700118 public AnyMotionDetector(PowerManager pm, Handler handler, SensorManager sm,
Joe LaPenna23d681b2015-08-27 15:12:11 -0700119 DeviceIdleCallback callback, float thresholdAngle) {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700120 if (DEBUG) Slog.d(TAG, "AnyMotionDetector instantiated.");
Kevin Gabayan5e488442016-03-24 13:05:23 -0700121 synchronized (mLock) {
122 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
123 mWakeLock.setReferenceCounted(false);
124 mHandler = handler;
125 mSensorManager = sm;
126 mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
127 mMeasurementInProgress = false;
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700128 mMeasurementTimeoutIsActive = false;
129 mWakelockTimeoutIsActive = false;
130 mSensorRestartIsActive = false;
Kevin Gabayan5e488442016-03-24 13:05:23 -0700131 mState = STATE_INACTIVE;
132 mCallback = callback;
133 mThresholdAngle = thresholdAngle;
134 mRunningStats = new RunningSignalStats();
135 mNumSufficientSamples = (int) Math.ceil(
136 ((double)ORIENTATION_MEASUREMENT_DURATION_MILLIS / SAMPLING_INTERVAL_MILLIS));
137 if (DEBUG) Slog.d(TAG, "mNumSufficientSamples = " + mNumSufficientSamples);
138 }
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700139 }
140
Robin Leec4d424c2018-12-07 15:09:13 +0100141 /**
142 * If we do not have an accelerometer, we are not going to collect much data.
143 */
144 public boolean hasSensor() {
145 return mAccelSensor != null;
146 }
147
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700148 /*
149 * Acquire accel data until we determine AnyMotion status.
150 */
151 public void checkForAnyMotion() {
Kevin Gabayan5e488442016-03-24 13:05:23 -0700152 if (DEBUG) {
153 Slog.d(TAG, "checkForAnyMotion(). mState = " + mState);
154 }
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700155 if (mState != STATE_ACTIVE) {
Kevin Gabayan5e488442016-03-24 13:05:23 -0700156 synchronized (mLock) {
157 mState = STATE_ACTIVE;
158 if (DEBUG) {
159 Slog.d(TAG, "Moved from STATE_INACTIVE to STATE_ACTIVE.");
160 }
161 mCurrentGravityVector = null;
162 mPreviousGravityVector = null;
163 mWakeLock.acquire();
Kevin Gabayandcf47012016-07-08 10:41:24 -0700164 Message wakelockTimeoutMsg = Message.obtain(mHandler, mWakelockTimeout);
165 mHandler.sendMessageDelayed(wakelockTimeoutMsg, WAKELOCK_TIMEOUT_MILLIS);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700166 mWakelockTimeoutIsActive = true;
Kevin Gabayan5e488442016-03-24 13:05:23 -0700167 startOrientationMeasurementLocked();
168 }
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700169 }
170 }
171
Dianne Hackborn42df4fb2015-08-14 16:43:14 -0700172 public void stop() {
Kevin Gabayandcf47012016-07-08 10:41:24 -0700173 synchronized (mLock) {
174 if (mState == STATE_ACTIVE) {
Kevin Gabayan5e488442016-03-24 13:05:23 -0700175 mState = STATE_INACTIVE;
176 if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE.");
Kevin Gabayandcf47012016-07-08 10:41:24 -0700177 }
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700178 mHandler.removeCallbacks(mMeasurementTimeout);
179 mHandler.removeCallbacks(mSensorRestart);
180 mMeasurementTimeoutIsActive = false;
181 mSensorRestartIsActive = false;
Kevin Gabayandcf47012016-07-08 10:41:24 -0700182 if (mMeasurementInProgress) {
183 mMeasurementInProgress = false;
184 mSensorManager.unregisterListener(mListener);
185 }
Kevin Gabayandcf47012016-07-08 10:41:24 -0700186 mCurrentGravityVector = null;
187 mPreviousGravityVector = null;
188 if (mWakeLock.isHeld()) {
Kevin Gabayandcf47012016-07-08 10:41:24 -0700189 mHandler.removeCallbacks(mWakelockTimeout);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700190 mWakelockTimeoutIsActive = false;
191 mWakeLock.release();
Dianne Hackborn42df4fb2015-08-14 16:43:14 -0700192 }
Dianne Hackborn42df4fb2015-08-14 16:43:14 -0700193 }
194 }
195
Kevin Gabayan5e488442016-03-24 13:05:23 -0700196 private void startOrientationMeasurementLocked() {
197 if (DEBUG) Slog.d(TAG, "startOrientationMeasurementLocked: mMeasurementInProgress=" +
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700198 mMeasurementInProgress + ", (mAccelSensor != null)=" + (mAccelSensor != null));
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700199 if (!mMeasurementInProgress && mAccelSensor != null) {
200 if (mSensorManager.registerListener(mListener, mAccelSensor,
201 SAMPLING_INTERVAL_MILLIS * 1000)) {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700202 mMeasurementInProgress = true;
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700203 mRunningStats.reset();
204 }
Kevin Gabayandcf47012016-07-08 10:41:24 -0700205 Message measurementTimeoutMsg = Message.obtain(mHandler, mMeasurementTimeout);
206 mHandler.sendMessageDelayed(measurementTimeoutMsg, ACCELEROMETER_DATA_TIMEOUT_MILLIS);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700207 mMeasurementTimeoutIsActive = true;
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700208 }
209 }
210
211 private int stopOrientationMeasurementLocked() {
212 if (DEBUG) Slog.d(TAG, "stopOrientationMeasurement. mMeasurementInProgress=" +
213 mMeasurementInProgress);
214 int status = RESULT_UNKNOWN;
215 if (mMeasurementInProgress) {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700216 mHandler.removeCallbacks(mMeasurementTimeout);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700217 mMeasurementTimeoutIsActive = false;
218 mSensorManager.unregisterListener(mListener);
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700219 mMeasurementInProgress = false;
220 mPreviousGravityVector = mCurrentGravityVector;
221 mCurrentGravityVector = mRunningStats.getRunningAverage();
Kevin Gabayandcf47012016-07-08 10:41:24 -0700222 if (mRunningStats.getSampleCount() == 0) {
223 Slog.w(TAG, "No accelerometer data acquired for orientation measurement.");
224 }
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700225 if (DEBUG) {
226 Slog.d(TAG, "mRunningStats = " + mRunningStats.toString());
227 String currentGravityVectorString = (mCurrentGravityVector == null) ?
228 "null" : mCurrentGravityVector.toString();
229 String previousGravityVectorString = (mPreviousGravityVector == null) ?
230 "null" : mPreviousGravityVector.toString();
231 Slog.d(TAG, "mCurrentGravityVector = " + currentGravityVectorString);
232 Slog.d(TAG, "mPreviousGravityVector = " + previousGravityVectorString);
233 }
234 mRunningStats.reset();
235 status = getStationaryStatus();
236 if (DEBUG) Slog.d(TAG, "getStationaryStatus() returned " + status);
237 if (status != RESULT_UNKNOWN) {
Kevin Gabayandcf47012016-07-08 10:41:24 -0700238 if (mWakeLock.isHeld()) {
Kevin Gabayandcf47012016-07-08 10:41:24 -0700239 mHandler.removeCallbacks(mWakelockTimeout);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700240 mWakelockTimeoutIsActive = false;
241 mWakeLock.release();
Kevin Gabayandcf47012016-07-08 10:41:24 -0700242 }
Kevin Gabayan5e488442016-03-24 13:05:23 -0700243 if (DEBUG) {
244 Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE. status = " + status);
245 }
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700246 mState = STATE_INACTIVE;
247 } else {
248 /*
249 * Unknown due to insufficient measurements. Schedule another orientation
250 * measurement.
251 */
252 if (DEBUG) Slog.d(TAG, "stopOrientationMeasurementLocked(): another measurement" +
253 " scheduled in " + ORIENTATION_MEASUREMENT_INTERVAL_MILLIS +
254 " milliseconds.");
255 Message msg = Message.obtain(mHandler, mSensorRestart);
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700256 mHandler.sendMessageDelayed(msg, ORIENTATION_MEASUREMENT_INTERVAL_MILLIS);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700257 mSensorRestartIsActive = true;
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700258 }
259 }
260 return status;
261 }
262
263 /*
264 * Updates mStatus to the current AnyMotion status.
265 */
266 public int getStationaryStatus() {
267 if ((mPreviousGravityVector == null) || (mCurrentGravityVector == null)) {
268 return RESULT_UNKNOWN;
269 }
270 Vector3 previousGravityVectorNormalized = mPreviousGravityVector.normalized();
271 Vector3 currentGravityVectorNormalized = mCurrentGravityVector.normalized();
272 float angle = previousGravityVectorNormalized.angleBetween(currentGravityVectorNormalized);
Joe LaPenna23d681b2015-08-27 15:12:11 -0700273 if (DEBUG) Slog.d(TAG, "getStationaryStatus: angle = " + angle
274 + " energy = " + mRunningStats.getEnergy());
275 if ((angle < mThresholdAngle) && (mRunningStats.getEnergy() < THRESHOLD_ENERGY)) {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700276 return RESULT_STATIONARY;
277 } else if (Float.isNaN(angle)) {
278 /**
279 * Floating point rounding errors have caused the angle calcuation's dot product to
280 * exceed 1.0. In such case, we report RESULT_MOVED to prevent devices from rapidly
281 * retrying this measurement.
282 */
283 return RESULT_MOVED;
284 }
285 long diffTime = mCurrentGravityVector.timeMillisSinceBoot -
286 mPreviousGravityVector.timeMillisSinceBoot;
287 if (diffTime > STALE_MEASUREMENT_TIMEOUT_MILLIS) {
288 if (DEBUG) Slog.d(TAG, "getStationaryStatus: mPreviousGravityVector is too stale at " +
289 diffTime + " ms ago. Returning RESULT_UNKNOWN.");
290 return RESULT_UNKNOWN;
291 }
292 return RESULT_MOVED;
293 }
294
295 private final SensorEventListener mListener = new SensorEventListener() {
296 @Override
297 public void onSensorChanged(SensorEvent event) {
298 int status = RESULT_UNKNOWN;
299 synchronized (mLock) {
300 Vector3 accelDatum = new Vector3(SystemClock.elapsedRealtime(), event.values[0],
301 event.values[1], event.values[2]);
302 mRunningStats.accumulate(accelDatum);
303
304 // If we have enough samples, stop accelerometer data acquisition.
305 if (mRunningStats.getSampleCount() >= mNumSufficientSamples) {
306 status = stopOrientationMeasurementLocked();
307 }
308 }
309 if (status != RESULT_UNKNOWN) {
Kevin Gabayandcf47012016-07-08 10:41:24 -0700310 mHandler.removeCallbacks(mWakelockTimeout);
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700311 mWakelockTimeoutIsActive = false;
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700312 mCallback.onAnyMotionResult(status);
313 }
314 }
315
316 @Override
317 public void onAccuracyChanged(Sensor sensor, int accuracy) {
318 }
319 };
320
321 private final Runnable mSensorRestart = new Runnable() {
322 @Override
323 public void run() {
324 synchronized (mLock) {
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700325 if (mSensorRestartIsActive == true) {
326 mSensorRestartIsActive = false;
327 startOrientationMeasurementLocked();
328 }
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700329 }
330 }
331 };
332
333 private final Runnable mMeasurementTimeout = new Runnable() {
Kevin Gabayandcf47012016-07-08 10:41:24 -0700334 @Override
335 public void run() {
336 int status = RESULT_UNKNOWN;
337 synchronized (mLock) {
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700338 if (mMeasurementTimeoutIsActive == true) {
339 mMeasurementTimeoutIsActive = false;
340 if (DEBUG) Slog.i(TAG, "mMeasurementTimeout. Failed to collect sufficient accel " +
341 "data within " + ACCELEROMETER_DATA_TIMEOUT_MILLIS + " ms. Stopping " +
342 "orientation measurement.");
343 status = stopOrientationMeasurementLocked();
344 if (status != RESULT_UNKNOWN) {
345 mHandler.removeCallbacks(mWakelockTimeout);
346 mWakelockTimeoutIsActive = false;
347 mCallback.onAnyMotionResult(status);
348 }
349 }
Kevin Gabayandcf47012016-07-08 10:41:24 -0700350 }
351 }
352 };
353
354 private final Runnable mWakelockTimeout = new Runnable() {
355 @Override
356 public void run() {
357 synchronized (mLock) {
Nick Vaccaro7510fbb2016-08-19 12:09:50 -0700358 if (mWakelockTimeoutIsActive == true) {
359 mWakelockTimeoutIsActive = false;
360 stop();
361 }
Kevin Gabayandcf47012016-07-08 10:41:24 -0700362 }
363 }
364 };
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700365
366 /**
367 * A timestamped three dimensional vector and some vector operations.
368 */
Kevin Gabayanb0705772016-06-09 15:40:50 -0700369 public static final class Vector3 {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700370 public long timeMillisSinceBoot;
371 public float x;
372 public float y;
373 public float z;
374
375 public Vector3(long timeMillisSinceBoot, float x, float y, float z) {
376 this.timeMillisSinceBoot = timeMillisSinceBoot;
377 this.x = x;
378 this.y = y;
379 this.z = z;
380 }
381
Kevin Gabayanb0705772016-06-09 15:40:50 -0700382 public float norm() {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700383 return (float) Math.sqrt(dotProduct(this));
384 }
385
Kevin Gabayanb0705772016-06-09 15:40:50 -0700386 public Vector3 normalized() {
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700387 float mag = norm();
388 return new Vector3(timeMillisSinceBoot, x / mag, y / mag, z / mag);
389 }
390
391 /**
392 * Returns the angle between this 3D vector and another given 3D vector.
393 * Assumes both have already been normalized.
394 *
395 * @param other The other Vector3 vector.
396 * @return angle between this vector and the other given one.
397 */
398 public float angleBetween(Vector3 other) {
Kevin Gabayanb0705772016-06-09 15:40:50 -0700399 Vector3 crossVector = cross(other);
400 float degrees = Math.abs((float)Math.toDegrees(
401 Math.atan2(crossVector.norm(), dotProduct(other))));
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700402 Slog.d(TAG, "angleBetween: this = " + this.toString() +
Kevin Gabayanb0705772016-06-09 15:40:50 -0700403 ", other = " + other.toString() + ", degrees = " + degrees);
404 return degrees;
405 }
406
407 public Vector3 cross(Vector3 v) {
408 return new Vector3(
409 v.timeMillisSinceBoot,
410 y * v.z - z * v.y,
411 z * v.x - x * v.z,
412 x * v.y - y * v.x);
Kevin Gabayan89ecf822015-05-18 12:10:07 -0700413 }
414
415 @Override
416 public String toString() {
417 String msg = "";
418 msg += "timeMillisSinceBoot=" + timeMillisSinceBoot;
419 msg += " | x=" + x;
420 msg += ", y=" + y;
421 msg += ", z=" + z;
422 return msg;
423 }
424
425 public float dotProduct(Vector3 v) {
426 return x * v.x + y * v.y + z * v.z;
427 }
428
429 public Vector3 times(float val) {
430 return new Vector3(timeMillisSinceBoot, x * val, y * val, z * val);
431 }
432
433 public Vector3 plus(Vector3 v) {
434 return new Vector3(v.timeMillisSinceBoot, x + v.x, y + v.y, z + v.z);
435 }
436
437 public Vector3 minus(Vector3 v) {
438 return new Vector3(v.timeMillisSinceBoot, x - v.x, y - v.y, z - v.z);
439 }
440 }
441
442 /**
443 * Maintains running statistics on the signal revelant to AnyMotion detection, including:
444 * <ul>
445 * <li>running average.
446 * <li>running sum-of-squared-errors as the energy of the signal derivative.
447 * <ul>
448 */
449 private static class RunningSignalStats {
450 Vector3 previousVector;
451 Vector3 currentVector;
452 Vector3 runningSum;
453 float energy;
454 int sampleCount;
455
456 public RunningSignalStats() {
457 reset();
458 }
459
460 public void reset() {
461 previousVector = null;
462 currentVector = null;
463 runningSum = new Vector3(0, 0, 0, 0);
464 energy = 0;
465 sampleCount = 0;
466 }
467
468 /**
469 * Apply a 3D vector v as the next element in the running SSE.
470 */
471 public void accumulate(Vector3 v) {
472 if (v == null) {
473 if (DEBUG) Slog.i(TAG, "Cannot accumulate a null vector.");
474 return;
475 }
476 sampleCount++;
477 runningSum = runningSum.plus(v);
478 previousVector = currentVector;
479 currentVector = v;
480 if (previousVector != null) {
481 Vector3 dv = currentVector.minus(previousVector);
482 float incrementalEnergy = dv.x * dv.x + dv.y * dv.y + dv.z * dv.z;
483 energy += incrementalEnergy;
484 if (DEBUG) Slog.i(TAG, "Accumulated vector " + currentVector.toString() +
485 ", runningSum = " + runningSum.toString() +
486 ", incrementalEnergy = " + incrementalEnergy +
487 ", energy = " + energy);
488 }
489 }
490
491 public Vector3 getRunningAverage() {
492 if (sampleCount > 0) {
493 return runningSum.times((float)(1.0f / sampleCount));
494 }
495 return null;
496 }
497
498 public float getEnergy() {
499 return energy;
500 }
501
502 public int getSampleCount() {
503 return sampleCount;
504 }
505
506 @Override
507 public String toString() {
508 String msg = "";
509 String currentVectorString = (currentVector == null) ?
510 "null" : currentVector.toString();
511 String previousVectorString = (previousVector == null) ?
512 "null" : previousVector.toString();
513 msg += "previousVector = " + previousVectorString;
514 msg += ", currentVector = " + currentVectorString;
515 msg += ", sampleCount = " + sampleCount;
516 msg += ", energy = " + energy;
517 return msg;
518 }
519 }
Kevin Gabayan5e488442016-03-24 13:05:23 -0700520}