|
SunSPOT API V6.0 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.spot.resources.Resource
com.sun.spot.sensorboard.peripheral.Accelerometer3D
com.sun.spot.sensorboard.peripheral.LIS3L02AQAccelerometer
public class LIS3L02AQAccelerometer
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.
Note: By default the maximum rate that the accelerometer can be read is ~58 Hz, i.e. reading all three axis every 17.1 milliseconds. For faster readings the ADT7411 must be set to use its fast conversion rate that will allow reading all three axis every 0.579 milliseconds (or 1667 Hz). Note that setting the ADT7411 to fast mode may cause readings of A0 to become inaccurate.
| 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 |
protected boolean |
isInSelfTest
|
protected int[] |
scale
|
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 |
protected int |
scaleIndex
|
| 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 | |
|---|---|
LIS3L02AQAccelerometer(IScalarInput xInput,
IScalarInput yInput,
IScalarInput zInput,
IOutputPin selfTest,
IOutputPin fullScale)
Constructor for the accelerometer. |
|
| Method Summary | |
|---|---|
void |
addILIS3L02AQAccelerometerThresholdListener(ILIS3L02AQAccelerometerThresholdListener who)
Add an ILIS3L02AQAccelerometerThresholdListener to the list of callbacks. |
void |
addIMeasurementRangeListener(IMeasurementRangeListener who)
Add an IMeasurementRangeListener to the list of callbacks. |
protected boolean |
areThresholdEventsEnabledAux(int axis)
Return whether threshold events are enabled or not. |
protected void |
disableInterrupts()
|
protected void |
enableInterrupts()
|
protected void |
enableThresholdEventsAux(int axis,
boolean enable)
Enable or disable threshold events. |
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. |
int |
getCurrentScale()
Deprecated. please use IMeasurementRange getCurrentRange() instead. |
String |
getDescription()
This method returns a readable description of the sensor. |
double[][] |
getGains()
Return the current array of gains used to convert from voltages to G's. |
protected double |
getHighThresholdAux(int axis,
boolean relative)
Return the current high threshold value. |
ILIS3L02AQAccelerometerThresholdListener[] |
getILIS3L02AQAccelerometerThresholdListeners()
Return all of the ILIS3L02AQAccelerometerThresholdListener callbacks. |
IMeasurementRangeListener[] |
getIMeasurementRangeListeners()
Return all of the IMeasurementRangeListener callbacks. |
protected double |
getLowThresholdAux(int axis,
boolean relative)
Return the current low threshold value. |
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 |
getRaw(int axis)
Read the current acceleration along the indicated axis. |
int[] |
getRawAccelValues()
Return all the current raaw values. |
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 |
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. |
double[][] |
getRestOffsets()
Deprecated. |
int[] |
getScales()
Deprecated. please use IMeasurementRange getMaxValue(int) instead. |
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 |
removeILIS3L02AQAccelerometerThresholdListener(ILIS3L02AQAccelerometerThresholdListener who)
Remove an ILIS3L02AQAccelerometerThresholdListener from the list of callbacks. |
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. |
void |
saveCalibration()
Save the gain, zero and offset calibration arrays out to the EDemoBoard flash. |
void |
scaleChanged(int scale)
Deprecated. should never have been called by user code |
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 |
setGains(double[][] gains)
Set the gains used to convert from voltages to G's. |
void |
setRestOffsets()
Deprecated. |
void |
setRestOffsets(double[][] offs)
Deprecated. |
void |
setScale(int newScaleIndex)
Deprecated. please use IMeasurementRange setCurrentRange() instead. |
protected void |
setScaleAux(int newScaleIndex)
Set the scale for this accelerometer to use. |
protected void |
setThresholdsAux(int axis,
double low,
double high,
boolean relative)
Set the low and high threshold values for this accelerometer. |
void |
setZeroOffsets(double[][] offs)
Set the zero offsets used to convert from voltages to G's. |
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 com.sun.spot.sensorboard.peripheral.Accelerometer3D |
|---|
addIAccelerometer3DThresholdListener, areThresholdEventsEnabled, copyCalibArray, createSensorEvent, enableThresholdEvents, getAccel, getAccel, getAccelValues, getCalibString, getHighThreshold, getIAccelerometer3DThresholdListeners, getLowThreshold, getRelativeAccel, getRelativeAccel, getTilt, getTiltX, getTiltY, getTiltZ, p2, parseCalibrationString, removeIAccelerometer3DThresholdListener, saveEventState, setCalibArray, setThresholds, 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 |
|---|
public static final String ACCELEROMETER_ZERO_OFFSETS_PROPERTY
public static final String ACCELEROMETER_REST_OFFSETS_PROPERTY
public static final String ACCELEROMETER_GAINS_PROPERTY
public static final int SCALE_2G
public static final int SCALE_6G
protected boolean isInSelfTest
protected int scaleIndex
protected int[] scale
| Constructor Detail |
|---|
public LIS3L02AQAccelerometer(IScalarInput xInput,
IScalarInput yInput,
IScalarInput zInput,
IOutputPin selfTest,
IOutputPin fullScale)
EDemoBoard.getAccelerometer().
xInput - a RangeInput that will be used to access values for the x axisyInput - a RangeInput that will be used to access values for the y axiszInput - a RangeInput that will be used to access values for the z axisselfTest - a SingleBitOutput to be used for self-testingfullScale - a SingleBitOutput to be used in switching between the 2G and 6G scales| Method Detail |
|---|
public void saveCalibration()
public double[][] getGains()
public double[][] getZeroOffsets()
public double[][] getRestOffsets()
public void setGains(double[][] gains)
gains - the array[scale][axis] of gains: A = (V - Z) / Gpublic void setZeroOffsets(double[][] offs)
offs - the array[scale][axis] of zero offsets: A = (V - Z) / Gpublic void setRestOffsets(double[][] offs)
offs - the array[scale][axis] of rest offsets: relative A = (V - R) / Gpublic void reset()
public int getRawX()
throws IOException
IOException
public int getRawY()
throws IOException
IOException
public int getRawZ()
throws IOException
IOException
public int[] getRawAccelValues()
throws IOException
IOException
public int getRaw(int axis)
throws IOException
axis - which axis to return (ALL_AXES = total acceleration)
IOException
public double getAccelX()
throws IOException
getAccelX in interface IAccelerometer3DgetAccelX in class Accelerometer3DIOException
public double getAccelY()
throws IOException
getAccelY in interface IAccelerometer3DgetAccelY in class Accelerometer3DIOException
public double getAccelZ()
throws IOException
getAccelZ in interface IAccelerometer3DgetAccelZ in class Accelerometer3DIOException
public void setRestOffsets()
throws IOException
setRestOffsets in class Accelerometer3DIOException
public double getRelativeAccelX()
throws IOException
getRelativeAccelX in class Accelerometer3DIOException
public double getRelativeAccelY()
throws IOException
getRelativeAccelY in class Accelerometer3DIOException
public double getRelativeAccelZ()
throws IOException
getRelativeAccelZ in class Accelerometer3DIOExceptionpublic void selfTest(boolean setSelfTestMode)
setSelfTestMode - if true the accelerometer is put into self-test mode;
if false, the accelerometer is taken out of self-test mode.public boolean isInSelfTest()
public int[] getScales()
public void setScale(int newScaleIndex)
throws IOException
Any threshold values that had been set are automatically converted to the new scale and limited to the available range of the new scale.
newScaleIndex - the scale to use specified as an offset into the array returned by getScales()
IOExceptionpublic int getCurrentScale()
protected void setScaleAux(int newScaleIndex)
newScaleIndex - the scale to use specified as an offset into the array returned by getScales()public void scaleChanged(int scale)
scale - the new scale setting.protected void enableInterrupts()
protected void disableInterrupts()
protected void setThresholdsAux(int axis,
double low,
double high,
boolean relative)
setThresholdsAux in class Accelerometer3Daxis - 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.
protected double getLowThresholdAux(int axis,
boolean relative)
getLowThresholdAux in class Accelerometer3Daxis - which axis to return Note: specifying ALL_AXES will throw an IllegalArgumentException.relative - if true then threshold is relative to the current rest offset.
protected double getHighThresholdAux(int axis,
boolean relative)
getHighThresholdAux in class Accelerometer3Daxis - which axis to return Note: specifying ALL_AXES will throw an IllegalArgumentException.relative - if true then threshold is relative to the current rest offset.
protected void enableThresholdEventsAux(int axis,
boolean enable)
enableThresholdEventsAux in class Accelerometer3Daxis - which axis to enableenable - if true then listeners will be notified if the scalar input
reading goes above the high threshold or below the low threshold.protected boolean areThresholdEventsEnabledAux(int axis)
areThresholdEventsEnabledAux in class Accelerometer3Daxis - which axis to return Note: specifying ALL_AXES will return true
only if all three axes are enabled.
public void thresholdExceeded(IScalarInput in,
int val)
thresholdExceeded in interface IScalarInputThresholdListenerin - the IScalarInput that has crossed a threshold.val - the current scalar input reading.
public void thresholdChanged(IScalarInput in,
int low,
int high)
thresholdChanged in interface IScalarInputThresholdListenerin - the IScalarInput that had its threshold values changed.low - the new scalar input low threshold value.high - the new scalar input high threshold value.public String getDescription()
ITransducer
getDescription in interface ITransducerpublic double getMaxSamplingRate()
ITransducer
getMaxSamplingRate in interface ITransducerpublic double getMinValue()
IMeasurementInfo
getMinValue in interface IMeasurementInfopublic double getMaxValue()
IMeasurementInfo
getMaxValue in interface IMeasurementInfopublic double getResolution()
IMeasurementInfo
getResolution in interface IMeasurementInfopublic double getAccuracy()
IMeasurementInfo
getAccuracy in interface IMeasurementInfopublic int getNumberRanges()
IMeasurementRange
getNumberRanges in interface IMeasurementRangepublic int getCurrentRange()
IMeasurementRange
getCurrentRange in interface IMeasurementRangepublic void setCurrentRange(int range)
IMeasurementRange
setCurrentRange in interface IMeasurementRangerange - the index of the measurement range to be set.public double getMinValue(int index)
IMeasurementRange
getMinValue in interface IMeasurementRangepublic double getMaxValue(int index)
IMeasurementRange
getMaxValue in interface IMeasurementRangepublic double getResolution(int index)
IMeasurementRange
getResolution in interface IMeasurementRangepublic double getAccuracy(int index)
IMeasurementRange
getAccuracy in interface IMeasurementRangepublic void addIMeasurementRangeListener(IMeasurementRangeListener who)
addIMeasurementRangeListener in interface IMeasurementRangewho - the IMeasurementRangeListener to addpublic void removeIMeasurementRangeListener(IMeasurementRangeListener who)
removeIMeasurementRangeListener in interface IMeasurementRangewho - the IMeasurementRangeListener to removepublic IMeasurementRangeListener[] getIMeasurementRangeListeners()
getIMeasurementRangeListeners in interface IMeasurementRangepublic void addILIS3L02AQAccelerometerThresholdListener(ILIS3L02AQAccelerometerThresholdListener who)
who - the ILIS3L02AQAccelerometerThresholdListener to addpublic void removeILIS3L02AQAccelerometerThresholdListener(ILIS3L02AQAccelerometerThresholdListener who)
who - the ILIS3L02AQAccelerometerThresholdListener to removepublic ILIS3L02AQAccelerometerThresholdListener[] getILIS3L02AQAccelerometerThresholdListeners()
public String getCalibration()
public void setCalibration(String calibration)
calibration - calibration values to be set.
IllegalArgumentException - - if the given string cannot be parsed
|
SunSPOT API V6.0 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||