|
SunSPOT API V3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object 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.
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 |
---|
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
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 scalesMethod 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 double getRaw(int axis) throws IOException
axis
- which axis to return (ALL_AXES = total acceleration)
IOException
public double getAccelX() throws IOException
getAccelX
in interface IAccelerometer3D
IOException
public double getAccelY() throws IOException
getAccelY
in interface IAccelerometer3D
IOException
public double getAccelZ() throws IOException
getAccelZ
in interface IAccelerometer3D
IOException
public double getAccel() throws IOException
getAccel
in interface IAccelerometer3D
IOException
public double getAccel(int axis) throws IOException
getAccel
in interface IAccelerometer3D
axis
- which axis to return (ALL_AXES = total acceleration)
IOException
public void setRestOffsets() throws IOException
setRestOffsets
in interface IAccelerometer3D
IOException
public double getRelativeAccelX() throws IOException
getRelativeAccelX
in interface IAccelerometer3D
IOException
public double getRelativeAccelY() throws IOException
getRelativeAccelY
in interface IAccelerometer3D
IOException
public double getRelativeAccelZ() throws IOException
getRelativeAccelZ
in interface IAccelerometer3D
IOException
public double getRelativeAccel() throws IOException
getRelativeAccel
in interface IAccelerometer3D
IOException
public double getRelativeAccel(int axis) throws IOException
getRelativeAccel
in interface IAccelerometer3D
axis
- which axis to return (ALL_AXES = total acceleration)
IOException
public double getTiltX() throws IOException
getTiltX
in interface IAccelerometer3D
IOException
public double getTiltY() throws IOException
getTiltY
in interface IAccelerometer3D
IOException
public double getTiltZ() throws IOException
getTiltZ
in interface IAccelerometer3D
IOException
public double getTilt(int axis) throws IOException
getTilt
in interface IAccelerometer3D
axis
- which axis to return Note: specifying ALL_AXES will throw an IllegalArgumentException.
IOException
public 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)
newScaleIndex
- the scale to use specified as an offset into the array returned by getScales()public int getCurrentScale()
public boolean supportsThresholdEvents()
supportsThresholdEvents
in interface IAccelerometer3D
public void addIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
addIAccelerometer3DThresholdListener
in interface IAccelerometer3D
who
- the accelerometer threshold listener to add.public void removeIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
removeIAccelerometer3DThresholdListener
in interface IAccelerometer3D
who
- the accelerometer threshold listener to remove.public IAccelerometer3DThresholdListener[] getIAccelerometer3DThresholdListeners()
getIAccelerometer3DThresholdListeners
in interface IAccelerometer3D
public void setThresholds(int axis, double low, double high, boolean relative)
setThresholds
in interface IAccelerometer3D
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.public double getLowThreshold(int axis, boolean relative)
getLowThreshold
in interface IAccelerometer3D
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.
public double getHighThreshold(int axis, boolean relative)
getHighThreshold
in interface IAccelerometer3D
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.
public void enableThresholdEvents(int axis, boolean enable)
enableThresholdEvents
in interface IAccelerometer3D
axis
- 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.public boolean areThresholdEventsEnabled(int axis)
areThresholdEventsEnabled
in interface IAccelerometer3D
axis
- 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 IScalarInputThresholdListener
in
- 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 IScalarInputThresholdListener
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.public void scaleChanged(int scale)
scale
- the new scale setting.
|
SunSPOT API V3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |