lejos.nxt
Class CompassSensor

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

public class CompassSensor
extends I2CSensor

Abstraction for a HiTechnic or Mindsensors compass.


Field Summary
 
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_CUSTOM, 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
getData, getPort, getProductID, getSensorType, getVersion, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, 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.

Returns:
Cartesian direction.

resetCartesianZero

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


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.


stopCalibration

public void stopCalibration()
Ends calibration sequence.