SunSPOT API V6.0


com.sun.spot.sensorboard.peripheral
Class MMA7455LAccelerometer

java.lang.Object
  extended by com.sun.spot.resources.Resource
      extended by com.sun.spot.sensorboard.peripheral.Accelerometer3D
          extended by com.sun.spot.sensorboard.peripheral.MMA7455LAccelerometer
All Implemented Interfaces:
IResource, IAccelerometer3D, IMeasurementInfo, IMeasurementRange, IStandby, ITransducer

public class MMA7455LAccelerometer
extends Accelerometer3D
implements IMeasurementRange, IStandby

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 MMA7455L accelerometer can measure accelerations using either a 2G, 4G or 8G scale.

Note: the sample rate is either 125 or 250 Hz.

The accelerometer directly reports the acceleration along each axis. No conversion is necessary.

Author:
Ron Goldman

Field Summary
static String ACCELEROMETER_DRIFT_OFFSETS_PROPERTY
          Name of the property holding the drift offsets for this accelerometer
static String ACCELEROMETER_GAINS_PROPERTY
          Name of the property holding the calibrated gains for this accelerometer
static int SCALE_2G
          Constant index for setting the accelerometer to use the 2G scale
static int SCALE_4G
          Constant index for setting the accelerometer to use the 4G scale
static int SCALE_8G
          Constant index for setting the accelerometer to use the 8G scale
 
Fields inherited from class com.sun.spot.sensorboard.peripheral.Accelerometer3D
supportsThresholdEvents
 
Fields inherited from interface com.sun.spot.sensorboard.peripheral.IAccelerometer3D
ABSOLUTE, ALL_AXES, RELATIVE, X_AXIS, Y_AXIS, Z_AXIS
 
Fields inherited from interface com.sun.spot.resources.transducers.IAccelerometer3D
ALL_AXES, X_AXIS, Y_AXIS, Z_AXIS
 
Constructor Summary
MMA7455LAccelerometer()
          Constructor for the accelerometer.
 
Method Summary
 void addIMeasurementRangeListener(IMeasurementRangeListener who)
          Add an IMeasurementRangeListener to be called back when the range is changed.
 double[] getAccelValues()
          Return all the current values.
 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.
 double getAccuracy()
          Returns the accuracy of the sensor (in the current measurement range) as a percentage of reading (=data value).
 double getAccuracy(int index)
          Returns the Nth accuracy of the specified measurement range.
 String getCalibration()
          Returns the current calibration values for this sensor.
 int getCurrentRange()
          Returns the index of the current measurement range of the given sensor.
 String getDescription()
          This method returns a readable description of the sensor.
 double[] getDriftOffsets()
          Get the accelerometer's drift offsets.
 double[][] getGains()
          Return the current array of gains used to convert to G's.
 IMeasurementRangeListener[] getIMeasurementRangeListeners()
          Return all of the IMeasurementRangeListener callbacks.
 double getMaxSamplingRate()
          Return the maximum sampling rate per second for this sensor.
 double getMaxValue()
          Returns the current maximum value of the sensor (in the current measurement range).
 double getMaxValue(int index)
          Returns the Nth max value of the specified measurement range.
 double getMinValue()
          Returns the current minimum value of the sensor (in the current measurement range).
 double getMinValue(int index)
          Returns the Nth min value of the specified measurement range.
 int getNumberRanges()
          Returns the number of possible measurement ranges for this given sensor.
 int[] getRawAccelValues()
          Return all the current values without scaling them.
 double getRelativeAccelX()
          Deprecated.  
 double getRelativeAccelY()
          Deprecated.  
 double getRelativeAccelZ()
          Deprecated.  
 double getResolution()
          Returns the resolution of the range (in the current measurement range).
 double getResolution(int index)
          Returns the Nth resolution of the specified measurement range.
 boolean isInSelfTest()
          Check if the accelerometer is in self-test mode.
 boolean isInStandbyMode()
          Check if the accelerometer is in standby mode.
 void removeIMeasurementRangeListener(IMeasurementRangeListener who)
          Remove an IMeasurementRangeListener from the list of callbacks.
 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 with a sampling filter set to 62.5Hz.
 void saveCalibration()
          Save the drift offsets & gains as properties in the EDemoBoard flash.
 void selfTest(boolean setSelfTestMode)
          Put the accelerometer into/out of self-test mode.
 void setCalibration(String calibration)
          Sets the calibration values for this sensor.
 void setCurrentRange(int range)
          Sets the measurement range of the sensor.
 void setDriftOffsets(double x, double y, double z)
          Set the accelerometer's drift offsets.
 void setGains(double[][] gains)
          Set the gains used to convert to G's.
 void setRestOffsets()
          Deprecated.  
 void setSampleFilter(boolean high)
          Set the filter for sampling to either 62.5 or 125Hz.
protected  void setScaleAux(int newScaleIndex)
          Set the scale for this accelerometer to use.
 void setStandbyMode(boolean sleep)
          Put the accelerometer into standby mode to save power.
 
Methods inherited from class com.sun.spot.sensorboard.peripheral.Accelerometer3D
addIAccelerometer3DThresholdListener, areThresholdEventsEnabled, areThresholdEventsEnabledAux, copyCalibArray, createSensorEvent, enableThresholdEvents, enableThresholdEventsAux, getAccel, getAccel, getCalibString, getHighThreshold, getHighThresholdAux, getIAccelerometer3DThresholdListeners, getLowThreshold, getLowThresholdAux, getRelativeAccel, getRelativeAccel, getTilt, getTiltX, getTiltY, getTiltZ, p2, parseCalibrationString, removeIAccelerometer3DThresholdListener, saveEventState, setCalibArray, setThresholds, setThresholdsAux, supportsThresholdEvents
 
Methods inherited from class com.sun.spot.resources.Resource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

Field Detail

ACCELEROMETER_DRIFT_OFFSETS_PROPERTY

public static final String ACCELEROMETER_DRIFT_OFFSETS_PROPERTY
Name of the property holding the drift 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_4G

public static final int SCALE_4G
Constant index for setting the accelerometer to use the 4G scale

See Also:
Constant Field Values

SCALE_8G

public static final int SCALE_8G
Constant index for setting the accelerometer to use the 8G scale

See Also:
Constant Field Values
Constructor Detail

MMA7455LAccelerometer

public MMA7455LAccelerometer()
Constructor for the accelerometer. Called by the EDemoBoard class. SPOT applications should get a reference to the accelerometer by calling EDemoBoard.getAccelerometer().

Method Detail

saveCalibration

public void saveCalibration()
Save the drift offsets & gains as properties in the EDemoBoard flash. The drift offset values are written in the format: "(x, y, z)" The gains array values are written in the format: "(x2G, y2G, z2G) (x4G, y4G, z4G) (x8G, y8G, z8G)"


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 with a sampling filter set to 62.5Hz.


setStandbyMode

public void setStandbyMode(boolean sleep)
Put the accelerometer into standby mode to save power. Note: attempts to read accelerometer values while in standby mode will throw an IllegalStateException.

Specified by:
setStandbyMode in interface IStandby
Parameters:
sleep - if true then put accelerometer into standby mode

isInStandbyMode

public boolean isInStandbyMode()
Check if the accelerometer is in standby mode.

Specified by:
isInStandbyMode in interface IStandby
Returns:
true if the accelerometer is in standby mode

setSampleFilter

public void setSampleFilter(boolean high)
                     throws IOException
Set the filter for sampling to either 62.5 or 125Hz. Note: actual sample rate is either 125 or 250Hz.

Parameters:
high - if true use 125Hz filter setting
Throws:
IOException

getAccelX

public double getAccelX()
                 throws IOException
Read the current acceleration along the X axis. Note: when using 8G scale read it as a full 10-bit value.

Specified by:
getAccelX in interface IAccelerometer3D
Specified by:
getAccelX in class Accelerometer3D
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. Note: when using 8G scale read it as a full 10-bit value.

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

getAccelZ

public double getAccelZ()
                 throws IOException
Read the current acceleration along the Z axis. Note: when using 8G scale read it as a full 10-bit value.

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

getAccelValues

public double[] getAccelValues()
                        throws IOException
Return all the current values. Note: when using 8G scale read them as full 10-bit values. Reading them together is faster than individual reads.

Specified by:
getAccelValues in interface IAccelerometer3D
Overrides:
getAccelValues in class Accelerometer3D
Returns:
all current values as array [ Ax, Ay, Az ]
Throws:
IOException

getRawAccelValues

public int[] getRawAccelValues()
                        throws IOException
Return all the current values without scaling them. Note: when using 8G scale read them as full 10-bit values. Reading them together is faster than individual reads.

Returns:
all current values as array [ Ax, Ay, Az ]
Throws:
IOException

setRestOffsets

public void setRestOffsets()
                    throws IOException
Deprecated. 

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 class Accelerometer3D
Throws:
IOException

getRelativeAccelX

public double getRelativeAccelX()
                         throws IOException
Deprecated. 

Read the current relative acceleration along the X axis. This value is relative to the last call to setRestOffsets().

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

getRelativeAccelY

public double getRelativeAccelY()
                         throws IOException
Deprecated. 

Read the current relative acceleration along the Y axis. This value is relative to the last call to setRestOffsets().

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

getRelativeAccelZ

public double getRelativeAccelZ()
                         throws IOException
Deprecated. 

Read the current relative acceleration along the Z axis. This value is relative to the last call to setRestOffsets().

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

setScaleAux

protected void setScaleAux(int newScaleIndex)
                    throws IOException
Set the scale for this accelerometer to use. The MMA7455LAccelerometer accelerometer can be set to either SCALE_2G, SCALE_4G or SCALE_8G. After changing the scale this method sleeps for 100 milliseconds to give the accelerometer time to settle.

Parameters:
newScaleIndex - the scale to use specified as an offset into the array returned by getScales()
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()
Check if the accelerometer is in self-test mode.

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

getGains

public double[][] getGains()
Return the current array of gains used to convert 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

setGains

public void setGains(double[][] gains)
Set the gains used to convert 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

getDriftOffsets

public double[] getDriftOffsets()
Get the accelerometer's drift offsets.

Returns:
an array containing the [x, Y, Z] drift offsets

setDriftOffsets

public void setDriftOffsets(double x,
                            double y,
                            double z)
                     throws IOException
Set the accelerometer's drift offsets.

Parameters:
x - drift offset for X axis
y - drift offset for Y axis
z - drift offset for Z axis
Throws:
IOException

getDescription

public String getDescription()
Description copied from interface: ITransducer
This method returns a readable description of the sensor. The description should tell the essentials of the sensor, including at least the sensor type (accelerometer, microphone, thermometer). The returned string MUST not be null or an empty string.

Specified by:
getDescription in interface ITransducer
Returns:
the description of the sensor

getMaxSamplingRate

public double getMaxSamplingRate()
Description copied from interface: ITransducer
Return the maximum sampling rate per second for this sensor.

Specified by:
getMaxSamplingRate in interface ITransducer
Returns:
the maximum sampling rate per second for this sensor or 0 if not applicable.

getMinValue

public double getMinValue()
Description copied from interface: IMeasurementInfo
Returns the current minimum value of the sensor (in the current measurement range).

Specified by:
getMinValue in interface IMeasurementInfo
Returns:
the min value of the sensor

getMaxValue

public double getMaxValue()
Description copied from interface: IMeasurementInfo
Returns the current maximum value of the sensor (in the current measurement range).

Specified by:
getMaxValue in interface IMeasurementInfo
Returns:
the max value of the sensor

getResolution

public double getResolution()
Description copied from interface: IMeasurementInfo
Returns the resolution of the range (in the current measurement range). The resolution is the minimum amount of change in the input of a sensor that can be detected as a change in the output. Resolution is a property of the transducer of a sensor but the input and output ranges and word length of the A/D converter usually set the limitations for the resolution of a digital sensor.

Specified by:
getResolution in interface IMeasurementInfo
Returns:
resolution of the sensor

getAccuracy

public double getAccuracy()
Description copied from interface: IMeasurementInfo
Returns the accuracy of the sensor (in the current measurement range) as a percentage of reading (=data value). Because this accuracy value describes the relative measurement error, greater values indicate a less accurate sensor. The accuracy value is within: 0 ≤ accuracy < 1

Specified by:
getAccuracy in interface IMeasurementInfo
Returns:
the accuracy of the sensor. If the accuracy is not known, a value of -1 is returned.

getNumberRanges

public int getNumberRanges()
Description copied from interface: IMeasurementRange
Returns the number of possible measurement ranges for this given sensor.

Specified by:
getNumberRanges in interface IMeasurementRange
Returns:
the number of possible measurement ranges for this given sensor.

getCurrentRange

public int getCurrentRange()
Description copied from interface: IMeasurementRange
Returns the index of the current measurement range of the given sensor.

Specified by:
getCurrentRange in interface IMeasurementRange
Returns:
the current measurement range of the given sensor.

setCurrentRange

public void setCurrentRange(int range)
Description copied from interface: IMeasurementRange
Sets the measurement range of the sensor.

Specified by:
setCurrentRange in interface IMeasurementRange
Parameters:
range - the index of the measurement range to be set.

getMinValue

public double getMinValue(int index)
Description copied from interface: IMeasurementRange
Returns the Nth min value of the specified measurement range.

Specified by:
getMinValue in interface IMeasurementRange
Returns:
the Nth min value of the specified measurement range

getMaxValue

public double getMaxValue(int index)
Description copied from interface: IMeasurementRange
Returns the Nth max value of the specified measurement range.

Specified by:
getMaxValue in interface IMeasurementRange
Returns:
the Nth max value of the specified measurement range

getResolution

public double getResolution(int index)
Description copied from interface: IMeasurementRange
Returns the Nth resolution of the specified measurement range.

Specified by:
getResolution in interface IMeasurementRange
Returns:
the Nth resolution of the specified measurement range

getAccuracy

public double getAccuracy(int index)
Description copied from interface: IMeasurementRange
Returns the Nth accuracy of the specified measurement range.

Specified by:
getAccuracy in interface IMeasurementRange
Returns:
the Nth accuracy of the specified measurement range

addIMeasurementRangeListener

public void addIMeasurementRangeListener(IMeasurementRangeListener who)
Description copied from interface: IMeasurementRange
Add an IMeasurementRangeListener to be called back when the range is changed.

Specified by:
addIMeasurementRangeListener in interface IMeasurementRange
Parameters:
who - the IMeasurementRangeListener to add

removeIMeasurementRangeListener

public void removeIMeasurementRangeListener(IMeasurementRangeListener who)
Remove an IMeasurementRangeListener from the list of callbacks.

Specified by:
removeIMeasurementRangeListener in interface IMeasurementRange
Parameters:
who - the IMeasurementRangeListener to remove

getIMeasurementRangeListeners

public IMeasurementRangeListener[] getIMeasurementRangeListeners()
Return all of the IMeasurementRangeListener callbacks.

Specified by:
getIMeasurementRangeListeners in interface IMeasurementRange
Returns:
an array of the IMeasurementRangeListener callbacks

getCalibration

public String getCalibration()
Returns the current calibration values for this sensor.

Returns:
the current calibration values for this sensor.

setCalibration

public void setCalibration(String calibration)
Sets the calibration values for this sensor.

Parameters:
calibration - calibration values to be set.
Throws:
IllegalArgumentException - - if the given string cannot be parsed

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.