icommand.nxt
Class CompassSensor

java.lang.Object
  extended by icommand.nxt.I2CSensor
      extended by icommand.nxt.CompassSensor

public class CompassSensor
extends I2CSensor

Currently supports Mindsensors.com Compass V1.1 and 2.0 (CMPS-Nx) and HiTechnic compass sensors. Auto-detects appropriate model.

Author:
BB

Field Summary
static byte EU_MODE
           
static byte USA_MODE
           
 
Fields inherited from class icommand.nxt.I2CSensor
DEFAULT_ADDRESS, PRODUCT_ID, SENSOR_TYPE, STOP, VERSION
 
Constructor Summary
CompassSensor(SensorPort s)
          Initializes a Compass using USA mode by default.
 
Method Summary
protected  byte[] getData(byte register, int length)
          Override method because of unreliability retrieving more than a single byte at a time with some I2C Sensors (bug in Lego firmware).
 double getDegrees()
          Returns the directional heading in degrees.
 double getDegreesCartesian()
          Compass readings increase clockwise from 0 to 360, but Cartesian coordinate systems increase counter-clockwise.
 double getRadians()
          Returns the directional heading in degrees.
 void resetCartesianZero()
          Changes the current direction the compass is facing into the zero angle.
 void setRegion(byte region)
          Mindsensors only.
 void startCalibration()
          Begins calibrating the compass sensor resulting in more accurate measurements.
 void stopCalibration()
           
 
Methods inherited from class icommand.nxt.I2CSensor
fetchString, getData, getId, getProductID, getSensorType, getVersion, sendData, sendData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USA_MODE

public static final byte USA_MODE
See Also:
Constant Field Values

EU_MODE

public static final byte EU_MODE
See Also:
Constant Field Values
Constructor Detail

CompassSensor

public CompassSensor(SensorPort s)
Initializes a Compass using USA mode by default.

Method Detail

setRegion

public void setRegion(byte region)
Mindsensors only. If you are using the compass in a building that uses household current, you will get better readings by setting the frequency of your power (Europe = 50Hz, USA = 60Hz). (USA 60Hz is default)

Parameters:
region - Use Compass.USA_MODE or Compass.EU_MODE

startCalibration

public void startCalibration()
Begins calibrating the compass sensor resulting in more accurate measurements. Rotate compass at least two times, taking at least 20 seconds per rotation. Issue stopCalibration() when done. NOTE: Once the compass is calibrated, you do not have to recalibrate even when the NXT is turned off. The calibration settings are stored in internal non-volatile memory on the NXT.


stopCalibration

public void stopCalibration()
See Also:
startCalibration()

getRadians

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

Returns:
Heading in radians.

getDegrees

public double 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 double 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.


getData

protected byte[] getData(byte register,
                         int length)
Override method because of unreliability retrieving more than a single byte at a time with some I2C Sensors (bug in Lego firmware). Note: This is slower because it takes more Bluetooth calls.

Overrides:
getData in class I2CSensor
Parameters:
register - e.g. FACTORY_SCALE_DIVISOR, BYTE0, etc....
length - Length of data to read (minimum 1, maximum 16)
Returns:


Copyright 2006. All Rights Reserved.