SunSPOT API V3.0


com.sun.spot.sensorboard.peripheral
Class LIS3L02AQAccelerometer

java.lang.Object
  extended by com.sun.spot.sensorboard.peripheral.LIS3L02AQAccelerometer
All Implemented Interfaces:
IScalarInputThresholdListener, IAccelerometer3D

public class LIS3L02AQAccelerometer
extends Object
implements IAccelerometer3D, IScalarInputThresholdListener

Class to implement an accelerometer on the demo sensor board and provide access to it via the IAccelerometer3D interface. Provides methods specific to this particular accelerometer. The LIS3L02AQ accelerometer can measure accelerations using either a 2G or 6G scale. The accelerometer reports a voltage to indicate the acceleration along each axis. To convert this voltage to G's requires subtracting the zero acceleration voltage and then dividing by a gain constant: Acceleration in G's = (Voltage - zero offset) / gain A standard zero offset and gain are used by default, but since the accelerometer in each SPOT can differ by up to 10% from the default it is best to calibrate each SPOT and save the offset and gain for each axis and scale. An application to calibrate the accelerometer is provided with the SPOT Demos.

Author:
Ron Goldman

Field Summary
static String ACCELEROMETER_GAINS_PROPERTY
          Name of the property holding the calibrated gains for this accelerometer
static String ACCELEROMETER_REST_OFFSETS_PROPERTY
          Name of the property holding the measured rest offsets for this accelerometer
static String ACCELEROMETER_ZERO_OFFSETS_PROPERTY
          Name of the property holding the calibrated zero offsets for this accelerometer
static int SCALE_2G
          Constant index for setting the accelerometer to use the 2G scale
static int SCALE_6G
          Constant index for setting the accelerometer to use the 6G scale
 
Fields inherited from interface com.sun.spot.sensorboard.peripheral.IAccelerometer3D
ABSOLUTE, ALL_AXES, RELATIVE, X_AXIS, Y_AXIS, Z_AXIS
 
Constructor Summary
LIS3L02AQAccelerometer(IScalarInput xInput, IScalarInput yInput, IScalarInput zInput, IOutputPin selfTest, IOutputPin fullScale)
          Constructor for the accelerometer.
 
Method Summary
 void addIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
          Adds the specified accelerometer threshold listener to receive callbacks from this accelerometer.
 boolean areThresholdEventsEnabled(int axis)
          Return whether threshold events are enabled or not.
 void enableThresholdEvents(int axis, boolean enable)
          Enable or disable threshold events.
 double getAccel()
          Compute the current total acceleration.
 double getAccel(int axis)
          Read the current acceleration along the indicated axis.
 double getAccelX()
          Read the current acceleration along the X axis.
 double getAccelY()
          Read the current acceleration along the Y axis.
 double getAccelZ()
          Read the current acceleration along the Z axis.
 int getCurrentScale()
          Return the index for the current scale being used by the accelerometer.
 double[][] getGains()
          Return the current array of gains used to convert from voltages to G's.
 double getHighThreshold(int axis, boolean relative)
          Return the current high threshold value.
 IAccelerometer3DThresholdListener[] getIAccelerometer3DThresholdListeners()
          Returns an array of all the scalar input threshold listeners registered on this input device.
 double getLowThreshold(int axis, boolean relative)
          Return the current low threshold value.
 double getRaw(int axis)
          Read the current acceleration along the indicated axis.
 int getRawX()
          Return the raw value in volts for the acceleration along the X axis.
 int getRawY()
          Return the raw value in volts for the acceleration along the Y axis.
 int getRawZ()
          Return the raw value in volts for the acceleration along the Z axis.
 double getRelativeAccel()
          Compute the current relative total acceleration.
 double getRelativeAccel(int axis)
          Read the current relative acceleration along the indicated axis.
 double getRelativeAccelX()
          Read the current relative acceleration along the X axis.
 double getRelativeAccelY()
          Read the current relative acceleration along the Y axis.
 double getRelativeAccelZ()
          Read the current relative acceleration along the Z axis.
 double[][] getRestOffsets()
          Return the current array of rest offsets used to convert from voltages to relative G's.
 int[] getScales()
          Get the possible scales this accelerometer supports.
 double getTilt(int axis)
          Compute the inclination of the specified SPOT axis.
 double getTiltX()
          Compute the inclination of the SPOT's X axis.
 double getTiltY()
          Compute the inclination of the SPOT's Y axis.
 double getTiltZ()
          Compute the inclination of the SPOT's Z axis.
 double[][] getZeroOffsets()
          Return the current array of zero offsets used to convert from voltages to G's.
 boolean isInSelfTest()
          Test if the accelerometer is in self-test mode.
 void removeIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
          Removes the specified accelerometer threshold listener so that it no longer receives callbacks from this accelerometer.
 void reset()
          Resets the accelerometer (ensures that it is not in self-test and is not powered down) and sets it to the 2G scale.
 void saveCalibration()
          Save the gain, zero offset and rest offset calibration arrays out to the EDemoBoard flash.
 void scaleChanged(int scale)
          Callback for when the accelerometer scale is changed.
 void selfTest(boolean setSelfTestMode)
          Put the accelerometer into/out of self-test mode.
 void setGains(double[][] gains)
          Set the gains used to convert from voltages to G's.
 void setRestOffsets()
          Compute the current acceleration along each axis and save it.
 void setRestOffsets(double[][] offs)
          Set the rest offsets used to convert from voltages to G's.
 void setScale(int newScaleIndex)
          Set the scale for this accelerometer to use.
 void setThresholds(int axis, double low, double high, boolean relative)
          Set the low and high threshold values for this scalar input.
 void setZeroOffsets(double[][] offs)
          Set the zero offsets used to convert from voltages to G's.
 boolean supportsThresholdEvents()
          Returns whether the underlying hardware supports threshold events.
 void thresholdChanged(IScalarInput in, int low, int high)
          Callback for when the scalar input thresholds are changed.
 void thresholdExceeded(IScalarInput in, int val)
          Callback for when the scalar input value goes above or below the specified thresholds.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCELEROMETER_ZERO_OFFSETS_PROPERTY

public static final String ACCELEROMETER_ZERO_OFFSETS_PROPERTY
Name of the property holding the calibrated zero offsets for this accelerometer

See Also:
Constant Field Values

ACCELEROMETER_REST_OFFSETS_PROPERTY

public static final String ACCELEROMETER_REST_OFFSETS_PROPERTY
Name of the property holding the measured rest offsets for this accelerometer

See Also:
Constant Field Values

ACCELEROMETER_GAINS_PROPERTY

public static final String ACCELEROMETER_GAINS_PROPERTY
Name of the property holding the calibrated gains for this accelerometer

See Also:
Constant Field Values

SCALE_2G

public static final int SCALE_2G
Constant index for setting the accelerometer to use the 2G scale

See Also:
Constant Field Values

SCALE_6G

public static final int SCALE_6G
Constant index for setting the accelerometer to use the 6G scale

See Also:
Constant Field Values
Constructor Detail

LIS3L02AQAccelerometer

public LIS3L02AQAccelerometer(IScalarInput xInput,
                              IScalarInput yInput,
                              IScalarInput zInput,
                              IOutputPin selfTest,
                              IOutputPin fullScale)
Constructor for the accelerometer. Called by the EDemoBoard class. SPOT applications should get a reference to the accelerometer by calling EDemoBoard.getAccelerometer().

Parameters:
xInput - a RangeInput that will be used to access values for the x axis
yInput - a RangeInput that will be used to access values for the y axis
zInput - a RangeInput that will be used to access values for the z axis
selfTest - a SingleBitOutput to be used for self-testing
fullScale - a SingleBitOutput to be used in switching between the 2G and 6G scales
Method Detail

saveCalibration

public void saveCalibration()
Save the gain, zero offset and rest offset calibration arrays out to the EDemoBoard flash. The array values are written in the format: "(x2G, y2G, z2G) (x6G, y6G, z6G)"


getGains

public double[][] getGains()
Return the current array of gains used to convert from voltages to G's. The array is indexed by the accelerometer scale and by the 3 axes.

Returns:
the array[scale][axis] of gains: A = (V - Z) / G

getZeroOffsets

public double[][] getZeroOffsets()
Return the current array of zero offsets used to convert from voltages to G's. The array is indexed by the accelerometer scale and by the 3 axes.

Returns:
the array[scale][axis] of zero offsets: A = (V - Z) / G

getRestOffsets

public double[][] getRestOffsets()
Return the current array of rest offsets used to convert from voltages to relative G's. The array is indexed by the accelerometer scale and by the 3 axes.

Returns:
the array[scale][axis] of gains: relative A = (V - R) / G

setGains

public void setGains(double[][] gains)
Set the gains used to convert from voltages to G's. The array is indexed by the accelerometer scale and by the 3 axes.

Parameters:
gains - the array[scale][axis] of gains: A = (V - Z) / G

setZeroOffsets

public void setZeroOffsets(double[][] offs)
Set the zero offsets used to convert from voltages to G's. The array is indexed by the accelerometer scale and by the 3 axes.

Parameters:
offs - the array[scale][axis] of zero offsets: A = (V - Z) / G

setRestOffsets

public void setRestOffsets(double[][] offs)
Set the rest offsets used to convert from voltages to G's. The array is indexed by the accelerometer scale and by the 3 axes.

Parameters:
offs - the array[scale][axis] of rest offsets: relative A = (V - R) / G

reset

public void reset()
Resets the accelerometer (ensures that it is not in self-test and is not powered down) and sets it to the 2G scale.


getRawX

public int getRawX()
            throws IOException
Return the raw value in volts for the acceleration along the X axis.

Returns:
the current raw voltage for the X axis accelerometer sensor
Throws:
IOException

getRawY

public int getRawY()
            throws IOException
Return the raw value in volts for the acceleration along the Y axis.

Returns:
the current raw voltage for the Y axis accelerometer sensor
Throws:
IOException

getRawZ

public int getRawZ()
            throws IOException
Return the raw value in volts for the acceleration along the Z axis.

Returns:
the current raw voltage for the Z axis accelerometer sensor
Throws:
IOException

getRaw

public double getRaw(int axis)
              throws IOException
Read the current acceleration along the indicated axis.

Parameters:
axis - which axis to return (ALL_AXES = total acceleration)
Returns:
the current acceleration in G's along the indicated axis
Throws:
IOException

getAccelX

public double getAccelX()
                 throws IOException
Read the current acceleration along the X axis.

Specified by:
getAccelX in interface IAccelerometer3D
Returns:
the current acceleration in G's along the X axis
Throws:
IOException

getAccelY

public double getAccelY()
                 throws IOException
Read the current acceleration along the Y axis.

Specified by:
getAccelY in interface IAccelerometer3D
Returns:
the current acceleration in G's along the Y axis
Throws:
IOException

getAccelZ

public double getAccelZ()
                 throws IOException
Read the current acceleration along the Z axis.

Specified by:
getAccelZ in interface IAccelerometer3D
Returns:
the current acceleration in G's along the Z axis
Throws:
IOException

getAccel

public double getAccel()
                throws IOException
Compute the current total acceleration. This is the vector sum of the acceleration along the X, Y & Z axes.

Specified by:
getAccel in interface IAccelerometer3D
Returns:
the current total acceleration in G's
Throws:
IOException

getAccel

public double getAccel(int axis)
                throws IOException
Read the current acceleration along the indicated axis.

Specified by:
getAccel in interface IAccelerometer3D
Parameters:
axis - which axis to return (ALL_AXES = total acceleration)
Returns:
the current acceleration in G's along the indicated axis
Throws:
IOException

setRestOffsets

public void setRestOffsets()
                    throws IOException
Compute the current acceleration along each axis and save it. Take the average of 25 readings along each axis. Do this for both the 2G and 6G scales. This method takes about one second to complete. Use these values to later be able to compute the acceleration relative to the current acceleration.

Specified by:
setRestOffsets in interface IAccelerometer3D
Throws:
IOException

getRelativeAccelX

public double getRelativeAccelX()
                         throws IOException
Read the current relative acceleration along the X axis. This value is relative to the last call to setRestOffsets().

Specified by:
getRelativeAccelX in interface IAccelerometer3D
Returns:
the current relative acceleration in G's along the X axis
Throws:
IOException

getRelativeAccelY

public double getRelativeAccelY()
                         throws IOException
Read the current relative acceleration along the Y axis. This value is relative to the last call to setRestOffsets().

Specified by:
getRelativeAccelY in interface IAccelerometer3D
Returns:
the current relative acceleration in G's along the Y axis
Throws:
IOException

getRelativeAccelZ

public double getRelativeAccelZ()
                         throws IOException
Read the current relative acceleration along the Z axis. This value is relative to the last call to setRestOffsets().

Specified by:
getRelativeAccelZ in interface IAccelerometer3D
Returns:
the current relative acceleration in G's along the Z axis
Throws:
IOException

getRelativeAccel

public double getRelativeAccel()
                        throws IOException
Compute the current relative total acceleration. This is the vector sum of the relative acceleration along the X, Y & Z axes.

Specified by:
getRelativeAccel in interface IAccelerometer3D
Returns:
the current total relative acceleration in G's
Throws:
IOException

getRelativeAccel

public double getRelativeAccel(int axis)
                        throws IOException
Read the current relative acceleration along the indicated axis.

Specified by:
getRelativeAccel in interface IAccelerometer3D
Parameters:
axis - which axis to return (ALL_AXES = total acceleration)
Returns:
the current relative acceleration in G's along the indicated axis
Throws:
IOException

getTiltX

public double getTiltX()
                throws IOException
Compute the inclination of the SPOT's X axis. This angle is with respect to any acceleration if the SPOT is moving.

Specified by:
getTiltX in interface IAccelerometer3D
Returns:
the current angle of the X axis in radians, in the range of -pi/2 through pi/2.
Throws:
IOException

getTiltY

public double getTiltY()
                throws IOException
Compute the inclination of the SPOT's Y axis. This angle is with respect to any acceleration if the SPOT is moving.

Specified by:
getTiltY in interface IAccelerometer3D
Returns:
the current angle of the Y axis in radians, in the range of -pi/2 through pi/2.
Throws:
IOException

getTiltZ

public double getTiltZ()
                throws IOException
Compute the inclination of the SPOT's Z axis. This angle is with respect to any acceleration if the SPOT is moving.

Specified by:
getTiltZ in interface IAccelerometer3D
Returns:
the current angle of the Z axis in radians, in the range of -pi/2 through pi/2.
Throws:
IOException

getTilt

public double getTilt(int axis)
               throws IOException
Compute the inclination of the specified SPOT axis. This angle is with respect to any acceleration if the SPOT is moving.

Specified by:
getTilt in interface IAccelerometer3D
Parameters:
axis - which axis to return Note: specifying ALL_AXES will throw an IllegalArgumentException.
Returns:
the current angle of that axis in radians, in the range of -pi/2 through pi/2.
Throws:
IOException

selfTest

public void selfTest(boolean setSelfTestMode)
Put the accelerometer into/out of self-test mode.

Parameters:
setSelfTestMode - if true the accelerometer is put into self-test mode; if false, the accelerometer is taken out of self-test mode.

isInSelfTest

public boolean isInSelfTest()
Test if the accelerometer is in self-test mode.

Returns:
true if the accelerometer is in self-test mode

getScales

public int[] getScales()
Get the possible scales this accelerometer supports. The LIS3L02AQ accelerometer the scale is either 2G or 6G.

Returns:
the array { 2, 6 }

setScale

public void setScale(int newScaleIndex)
Set the scale for this accelerometer to use. The LIS3L02AQ accelerometer can be set to either SCALE_2G or SCALE_6G. After changing the scale this method sleeps for 100 milliseconds to give the accelerometer time to settle. Any threshold values that had been set are automatically converted to the new scale and limited to the available range of the new scale.

Parameters:
newScaleIndex - the scale to use specified as an offset into the array returned by getScales()

getCurrentScale

public int getCurrentScale()
Return the index for the current scale being used by the accelerometer.

Returns:
the scale in use specified as an offset into the array returned by getScales()

supportsThresholdEvents

public boolean supportsThresholdEvents()
Returns whether the underlying hardware supports threshold events.

Specified by:
supportsThresholdEvents in interface IAccelerometer3D
Returns:
true if threshold events are supported

addIAccelerometer3DThresholdListener

public void addIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
Adds the specified accelerometer threshold listener to receive callbacks from this accelerometer. Callbacks occur when the accelerometer reading falls below or equal to the low threshold value, or when it rises above or equal to the high threshold value.

Specified by:
addIAccelerometer3DThresholdListener in interface IAccelerometer3D
Parameters:
who - the accelerometer threshold listener to add.

removeIAccelerometer3DThresholdListener

public void removeIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
Removes the specified accelerometer threshold listener so that it no longer receives callbacks from this accelerometer. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this input device.

Specified by:
removeIAccelerometer3DThresholdListener in interface IAccelerometer3D
Parameters:
who - the accelerometer threshold listener to remove.

getIAccelerometer3DThresholdListeners

public IAccelerometer3DThresholdListener[] getIAccelerometer3DThresholdListeners()
Returns an array of all the scalar input threshold listeners registered on this input device.

Specified by:
getIAccelerometer3DThresholdListeners in interface IAccelerometer3D
Returns:
all of this scalar input's ILightSensorThresholdListener or an empty array if no scalar input threshold listeners are currently registered.

setThresholds

public void setThresholds(int axis,
                          double low,
                          double high,
                          boolean relative)
Set the low and high threshold values for this scalar input. Callbacks occur when the scalar input reading falls below or equal to the low threshold value, or when it rises above or equal to the high threshold value.

Specified by:
setThresholds in interface IAccelerometer3D
Parameters:
axis - which axis to set threshold values for.
low - the new low threshold value.
high - the new high threshold value.
relative - compute threshold relative to the current rest offset.

getLowThreshold

public double getLowThreshold(int axis,
                              boolean relative)
Return the current low threshold value.

Specified by:
getLowThreshold in interface IAccelerometer3D
Parameters:
axis - which axis to return Note: specifying ALL_AXES will throw an IllegalArgumentException.
relative - if true then threshold is relative to the current rest offset.
Returns:
the current low threshold value.

getHighThreshold

public double getHighThreshold(int axis,
                               boolean relative)
Return the current high threshold value.

Specified by:
getHighThreshold in interface IAccelerometer3D
Parameters:
axis - which axis to return Note: specifying ALL_AXES will throw an IllegalArgumentException.
relative - if true then threshold is relative to the current rest offset.
Returns:
the current high threshold value.

enableThresholdEvents

public void enableThresholdEvents(int axis,
                                  boolean enable)
Enable or disable threshold events.

Specified by:
enableThresholdEvents in interface IAccelerometer3D
Parameters:
axis - which axis to enable
enable - if true then listeners will be notified if the scalar input reading goes above the high threshold or below the low threshold.

areThresholdEventsEnabled

public boolean areThresholdEventsEnabled(int axis)
Return whether threshold events are enabled or not.

Specified by:
areThresholdEventsEnabled in interface IAccelerometer3D
Parameters:
axis - which axis to return Note: specifying ALL_AXES will return true only if all three axes are enabled.
Returns:
true if listeners will be notified if the scalar input reading goes above the high threshold or below the low threshold.

thresholdExceeded

public void thresholdExceeded(IScalarInput in,
                              int val)
Callback for when the scalar input value goes above or below the specified thresholds.

Specified by:
thresholdExceeded in interface IScalarInputThresholdListener
Parameters:
in - the IScalarInput that has crossed a threshold.
val - the current scalar input reading.

thresholdChanged

public void thresholdChanged(IScalarInput in,
                             int low,
                             int high)
Callback for when the scalar input thresholds are changed.

Specified by:
thresholdChanged in interface IScalarInputThresholdListener
Parameters:
in - the IScalarInput that had its threshold values changed.
low - the new scalar input low threshold value.
high - the new scalar input high threshold value.

scaleChanged

public void scaleChanged(int scale)
Callback for when the accelerometer scale is changed.

Parameters:
scale - the new scale setting.

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.