com.drismo.logic
Class Calibration

java.lang.Object
  extended by java.lang.Thread
      extended by com.drismo.logic.Calibration
All Implemented Interfaces:
FilteredAccelerationListener, java.lang.Runnable

public class Calibration
extends java.lang.Thread
implements FilteredAccelerationListener

Calibrates the (roll, pitch and yaw) angles of the device RELATIVE to the cars position and driving direction. By calibrating we can rotate the acceleration vectors relative to the car, which means we can use these vectors to analyze and rate the quality of driving.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  AccelerationHandler accHandler
           
private  double averageBuffer
           
private  int averageCounter
           
private  CalibrationListener calibrationListener
           
private static double DRIVING_THRESHOLD
           
private  boolean levelCalibrated
           
private static int N
           
private  boolean offsetFound
           
private  double xyMagnitudeOffset
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Calibration(AccelerationHandler ah, CalibrationListener cl)
          Stores the acceleration handler and the calibration listener.
 
Method Summary
 void cancel()
          Cancels the calibration.
 void onFilteredAccelerationChange(float[] filteredVectors, float[] rotatedVectors)
          Computes the roll, pitch and yaw angles relative to the car.
 void run()
          Waits 1 second to reduce touch vibration/noise, then initiates the calibration.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

accHandler

private AccelerationHandler accHandler

calibrationListener

private CalibrationListener calibrationListener

xyMagnitudeOffset

private double xyMagnitudeOffset

N

private static final int N
See Also:
Constant Field Values

DRIVING_THRESHOLD

private static final double DRIVING_THRESHOLD
See Also:
Constant Field Values

levelCalibrated

private boolean levelCalibrated

offsetFound

private boolean offsetFound

averageBuffer

private double averageBuffer

averageCounter

private int averageCounter
Constructor Detail

Calibration

public Calibration(AccelerationHandler ah,
                   CalibrationListener cl)
Stores the acceleration handler and the calibration listener. Starts the calibration thread.

Parameters:
ah - The acceleration handler.
cl - The object that listens for changes in calibration.
Method Detail

run

public void run()
Waits 1 second to reduce touch vibration/noise, then initiates the calibration.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

cancel

public void cancel()
Cancels the calibration.


onFilteredAccelerationChange

public void onFilteredAccelerationChange(float[] filteredVectors,
                                         float[] rotatedVectors)
Computes the roll, pitch and yaw angles relative to the car. This means that (by rotating the acceleration vectors) we can detect turns in the X axis, acceleration in the Y axis and bumps in the Z axis. Noise reduced acceleration values is given from the AccelerationHandler object, on change.

Specified by:
onFilteredAccelerationChange in interface FilteredAccelerationListener
Parameters:
filteredVectors - The original weighted moving average acceleration vectors (X,Y,Z).
rotatedVectors - The rotated weighted moving average acceleration vectors (X,Y,Z).
See Also:
AccelerationHandler.onSensorChanged(android.hardware.SensorEvent)