lejos.nxt.addon
Class DIMUAccel

java.lang.Object
  extended by lejos.nxt.I2CSensor
      extended by lejos.nxt.addon.DIMUAccel
All Implemented Interfaces:
SensorConstants, Accelerometer

public class DIMUAccel
extends I2CSensor
implements Accelerometer

This class provides access to the accelerometer of Dexter Industries IMU sensor

Version:
1.0
Author:
Aswin Bouwmeester

Nested Class Summary
static class DIMUAccel.AccelUnits
          List of possible units for acceleration
static class DIMUAccel.TiltUnits
          List of possible units for Tilt
 
Field Summary
protected static int ACCEL
           
protected  DIMUAccel.AccelUnits accelUnit
          The default unit to use when retuning acceleration data from the accelerometer
protected static int DEFAULT_I2C_ADDRESS
           
protected static int MODE_REG
           
protected  float multiplier
          A factor to use when converting raw data from the accelerometer.
protected  float[] offset
           
protected static int samples
           
protected  float[] scale
           
protected  DIMUAccel.TiltUnits tiltUnit
          The default unit to use when retuning tilt data from the accelerometer
 
Fields inherited from class lejos.nxt.I2CSensor
address, port, REG_PRODUCT_ID, REG_VENDOR_ID, REG_VERSION
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
 
Constructor Summary
DIMUAccel(I2CPort port)
           
 
Method Summary
 void calibrateAxis(char axis)
          Calibrates a single axis.
 void fetchAllAccel(float[] ret)
          Acceleration along 3 axis.
 void fetchAllAccel(float[] ret, DIMUAccel.AccelUnits unit)
          Acceleration along 3 axis.
 void fetchAllTilt(float[] ret)
          Tilt along 3 axis
 void fetchAllTilt(float[] ret, DIMUAccel.TiltUnits unit)
          Tilt along 3 axis.
 void fetchRawAccel(int[] ret)
           
 DIMUAccel.AccelUnits getAccelUnit()
          Returns the current acceleration unit
protected  float getMultiplier()
           
 String getProductID()
          Read the sensor's product identifier.
 DIMUAccel.TiltUnits getTiltUnit()
          Returns the current unit for tilt
 String getVendorID()
          Read the sensor's vendor identifier.
 String getVersion()
          Read the sensor's version string.
 int getXAccel()
          Measures the x-axis of the accelerometer, in meters/second^2.
 int getYAccel()
          Measures the y-axis of the accelerometer, in meters/second^2.
 int getZAccel()
          Measures the z-axis of the accelerometer, in meters/second^2.
 void load()
          Loads saved offset and scale values from memory.
 void save()
          Saves the offset and scale factors in Flash memory.
 void setAccelUnit(DIMUAccel.AccelUnits accelUnit)
          Sets the unit for acceleration
 void setTiltUnit(DIMUAccel.TiltUnits tiltUnit)
          Sets the unit for tilt
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getAddress, getData, getData, getPort, sendData, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEL

protected static final int ACCEL
See Also:
Constant Field Values

MODE_REG

protected static final int MODE_REG
See Also:
Constant Field Values

DEFAULT_I2C_ADDRESS

protected static final int DEFAULT_I2C_ADDRESS
See Also:
Constant Field Values

offset

protected float[] offset

scale

protected float[] scale

samples

protected static int samples

accelUnit

protected DIMUAccel.AccelUnits accelUnit
The default unit to use when retuning acceleration data from the accelerometer


tiltUnit

protected DIMUAccel.TiltUnits tiltUnit
The default unit to use when retuning tilt data from the accelerometer


multiplier

protected float multiplier
A factor to use when converting raw data from the accelerometer. multiplier corresponds to 1 / Number of least significant bits per unit. This number and the unit are given in the documentation of the sensor.

Constructor Detail

DIMUAccel

public DIMUAccel(I2CPort port)
Parameters:
port -
Method Detail

calibrateAxis

public void calibrateAxis(char axis)
Calibrates a single axis. The calibration process consists of determining static acceleration values due to gravity by placing the axis opposite and in the direction of gravity. This gives a minimum and maximum value. The difference between the two is equal to 2G and used to calculate a scale factor. The mean of the two corresponds to 0G and equals the offset value.

Calibration settings are held in memory. To store these values one should use the save() method.

Parameters:
axis - Axis should have the value X,Y or Z

fetchAllAccel

public void fetchAllAccel(float[] ret)
Acceleration along 3 axis.


fetchAllAccel

public void fetchAllAccel(float[] ret,
                          DIMUAccel.AccelUnits unit)
Acceleration along 3 axis.

Parameters:
unit - of acceleration

fetchAllTilt

public void fetchAllTilt(float[] ret)
Tilt along 3 axis


fetchAllTilt

public void fetchAllTilt(float[] ret,
                         DIMUAccel.TiltUnits unit)
Tilt along 3 axis. Calculation of tilt is based acceleration and on the fact that under static circumstances (no acceleration) the accleration (in G) equals the cosine of the tilt angle.

Parameters:
unit - of tilt

fetchRawAccel

public void fetchRawAccel(int[] ret)

getAccelUnit

public DIMUAccel.AccelUnits getAccelUnit()
Returns the current acceleration unit

Returns:
accelUnit

getMultiplier

protected float getMultiplier()
Returns:
A factor to use when converting raw data from the accelerometer.

getProductID

public String getProductID()
Description copied from class: I2CSensor
Read the sensor's product identifier. This method reads up to 8 bytes and returns the characters before the zero termination byte. Examples: "Sonar", ...

Overrides:
getProductID in class I2CSensor
Returns:
product identifier

getVendorID

public String getVendorID()
Description copied from class: I2CSensor
Read the sensor's vendor identifier. This method reads up to 8 bytes and returns the characters before the zero termination byte. Examples: "LEGO", "HiTechnc", ...

Overrides:
getVendorID in class I2CSensor
Returns:
vendor identifier

getTiltUnit

public DIMUAccel.TiltUnits getTiltUnit()
Returns the current unit for tilt

Returns:

getVersion

public String getVersion()
Description copied from class: I2CSensor
Read the sensor's version string. This method reads up to 8 bytes and returns the characters before the zero termination byte. Examples: "V1.0", ...

Overrides:
getVersion in class I2CSensor
Returns:
version number

load

public void load()
Loads saved offset and scale values from memory. If no saved values are found it will load default values for offset=0 and scale =1;


save

public void save()
Saves the offset and scale factors in Flash memory.


setAccelUnit

public void setAccelUnit(DIMUAccel.AccelUnits accelUnit)
Sets the unit for acceleration

Parameters:
accelUnit -

setTiltUnit

public void setTiltUnit(DIMUAccel.TiltUnits tiltUnit)
Sets the unit for tilt

Parameters:
tiltUnit -

getXAccel

public int getXAccel()
Description copied from interface: Accelerometer
Measures the x-axis of the accelerometer, in meters/second^2.

Specified by:
getXAccel in interface Accelerometer
Returns:
acceleration in m/s^2

getYAccel

public int getYAccel()
Description copied from interface: Accelerometer
Measures the y-axis of the accelerometer, in meters/second^2.

Specified by:
getYAccel in interface Accelerometer
Returns:
acceleration in m/s^2

getZAccel

public int getZAccel()
Description copied from interface: Accelerometer
Measures the z-axis of the accelerometer, in meters/second^2.

Specified by:
getZAccel in interface Accelerometer
Returns:
acceleration in m/s^2