lejos.nxt.addon
Class CompassSensor

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

public class CompassSensor
extends I2CSensor
implements DirectionFinder

Abstraction for a HiTechnic or Mindsensors compass.


Field Summary
 
Fields inherited from class lejos.nxt.I2CSensor
PRODUCT_ID, SENSOR_TYPE, VERSION
 
Fields inherited from interface lejos.nxt.SensorConstants
MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, 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
 
Constructor Summary
CompassSensor(I2CPort port)
           
 
Method Summary
 float getDegrees()
          Returns the directional heading in degrees.
 float getDegreesCartesian()
          Compass readings increase clockwise from 0 to 360, but Cartesian coordinate systems increase counter-clockwise.
 void resetCartesianZero()
          Changes the current direction the compass is facing into the zero angle.
 void startCalibration()
          Starts calibration for Mindsensors.com compass.
 void stopCalibration()
          Ends calibration sequence.
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getData, getPort, getProductID, getSensorType, getVersion, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompassSensor

public CompassSensor(I2CPort port)
Method Detail

getDegrees

public float getDegrees()
Returns the directional heading in degrees. (0 to 359.9) 0 is due North (on Mindsensors circuit board a white arrow indicates the direction of compass). Reading increases clockwise.

Returns:
Heading in degrees. Resolution is within 0.1 degrees

getDegreesCartesian

public float getDegreesCartesian()
Compass readings increase clockwise from 0 to 360, but Cartesian coordinate systems increase counter-clockwise. This method returns the Cartesian compass reading. Also, the resetCartesianZero() method can be used to designate any direction as zero, rather than relying on North as being zero.

Specified by:
getDegreesCartesian in interface DirectionFinder
Returns:
Cartesian direction.

resetCartesianZero

public void resetCartesianZero()
Changes the current direction the compass is facing into the zero angle.

Specified by:
resetCartesianZero in interface DirectionFinder

startCalibration

public void startCalibration()
Starts calibration for Mindsensors.com compass. Must rotate *very* slowly ,taking at least 20 seconds per rotation. Mindsensors: At least 2 full rotations. HiTechnic: 1.5 to 2 full rotations. Must call stopCalibration() when done.

Specified by:
startCalibration in interface DirectionFinder

stopCalibration

public void stopCalibration()
Ends calibration sequence.

Specified by:
stopCalibration in interface DirectionFinder