lejos.nxt.addon
Class AngleSensor

java.lang.Object
  extended by lejos.nxt.I2CSensor
      extended by lejos.nxt.addon.AngleSensor
All Implemented Interfaces:
SensorConstants

public class AngleSensor
extends I2CSensor

Supports the angle sensor of HiTechnic. This Java implementation was based on the NXC implementation on http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NAA1030. Works clockwise, i.e. rotating clockwise increases angle value and rotating counter-clockwise decreases angle value.

Author:
Michael Mirwaldt (epcfreak@gmail.com)
date 2nd April 2011

Field Summary
protected static int HTANGLE_MODE_CALIBRATE
           
protected static int HTANGLE_MODE_RESET
           
protected static int REG_ACCUMULATED_ANGLE
           
protected static int REG_ANGLE
           
protected static int REG_SPEED
           
 
Fields inherited from class lejos.nxt.I2CSensor
address, DEFAULT_I2C_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
AngleSensor(I2CPort port)
           
 
Method Summary
 void calibrateAngle()
          Calibrate the zero position of angle.
 long getAccAngle()
          reads the current accumulated angle
 long getAccumulatedAngle()
           
 int getAngle()
          reads the current angle
 int getRotationsPerMinute()
           
 int getRPM()
          reads the current rotations per minute
 void resetAccAngle()
          Reset the rotation count of accumulated angle to zero.
 void resetAccumulatedAngle()
           
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getAddress, getData, getData, getData, getId, getProductID, getVendorID, getVersion, sendData, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REG_ANGLE

protected static final int REG_ANGLE
See Also:
Constant Field Values

REG_ACCUMULATED_ANGLE

protected static final int REG_ACCUMULATED_ANGLE
See Also:
Constant Field Values

REG_SPEED

protected static final int REG_SPEED
See Also:
Constant Field Values

HTANGLE_MODE_CALIBRATE

protected static final int HTANGLE_MODE_CALIBRATE
See Also:
Constant Field Values

HTANGLE_MODE_RESET

protected static final int HTANGLE_MODE_RESET
See Also:
Constant Field Values
Constructor Detail

AngleSensor

public AngleSensor(I2CPort port)
Method Detail

getAngle

public int getAngle()
reads the current angle

Returns:
angle. Value lies between 0-359

getAccumulatedAngle

public long getAccumulatedAngle()
See Also:
getAccAngle()

getAccAngle

public long getAccAngle()
reads the current accumulated angle

Returns:
the current accumulated angle. Value lies between -2147483648 to 2147483647.

getRPM

public int getRPM()
reads the current rotations per minute

Returns:
current rotations per minute. Value lies between -1000 to 1000.

getRotationsPerMinute

public int getRotationsPerMinute()
See Also:
getAccAngle()

resetAccumulatedAngle

public void resetAccumulatedAngle()
See Also:
resetAccAngle()

resetAccAngle

public void resetAccAngle()
Reset the rotation count of accumulated angle to zero. Not saved in EEPORM.


calibrateAngle

public void calibrateAngle()
Calibrate the zero position of angle. Zero position is saved in EEPROM on sensor. Thread sleeps for 50ms while that is done.