ch.aplu.nxt
Class CompassHTSensor

java.lang.Object
  extended by ch.aplu.nxt.Part
      extended by ch.aplu.nxt.Sensor
          extended by ch.aplu.nxt.I2CSensor
              extended by ch.aplu.nxt.CompassHTSensor
All Implemented Interfaces:
SharedConstants

public class CompassHTSensor
extends I2CSensor

Class that represents a compass sensor from HiTechnics. Most of the code and the documentation taken from the leJOS library (lejos.sourceforge.net, with thanks to the autor.


Field Summary
 
Fields inherited from interface ch.aplu.nxt.SharedConstants
ABOUT, ACCELEROMETERPOLLDELAY, ANGLE, ANGLESTEPSMODE, AXELENGTH, BOOLEANMODE, BOOT, BRAKE, BRAKEDELAY, CELSIUSMODE, CLOSE, COLORPOLLDELAY, COMPASSPOLLDELAY, CRAWLERROTATIONFACTOR, CRAWLERROTATIONSPEED, CRAWLERSPEED, CRAWLERSTEPFACTOR, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, DEBUGLEVEL, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GEARSPEED, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, GYROPOLLDELAY, HIGH_SPEED_BUFFER, INFRAREDSEEKERPOLLDELAY, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LIGHTPOLLDELAY, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTIONDETECTORPOLLDELAY, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, MOTORSPEED, MOTORSPEEDFACTOR, MOTORSPEEDMULTIPLIER, NO_OF_SENSOR_TYPES, NO_SENSOR, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, PROTOTYPEPOLLDELAY, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, RFIDPOLLDELAY, SENSOREVENTDELAY, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, SOUNDPOLLDELAY, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TITLE, TITLEMP, TOUCHPOLLDELAY, TRANSITIONCNTMODE, TURTLEROTATIONFACTOR, TURTLEROTATIONSPEED, TURTLESPEED, TURTLESTEPFACTOR, ULTRASONICPOLLDELAY, VERSION, WRITE
 
Constructor Summary
CompassHTSensor()
          Creates a sensor instance connected to port S1.
CompassHTSensor(SensorPort port)
          Creates a sensor instance connected to the given port.
 
Method Summary
 void addCompassListener(CompassListener compassListener)
          Registers the given compass listener with default trigger level 180.
 void addCompassListener(CompassListener compassListener, double triggerLevel)
          Registers the given compass listener for the given trigger level.
 double getDegrees()
          Polls the sensor.
 lejos.nxt.addon.CompassHTSensor getLejosSensor()
          Returns the reference of the the underlying lejos.nxt.CompassSensor.
 double setTriggerLevel(double triggerLevel)
          Sets a new trigger level and returns the previous one.
 void startCalibration()
          Starts calibration process.
 void stopCalibration()
          Stops calibration process.
 
Methods inherited from class ch.aplu.nxt.I2CSensor
getData, getLejosI2CSensor, getLejosPort, getProductID, getVersion, sendData, sendData
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompassHTSensor

public CompassHTSensor(SensorPort port)
Creates a sensor instance connected to the given port.

Parameters:
port - the port where the sensor is plugged-in

CompassHTSensor

public CompassHTSensor()
Creates a sensor instance connected to port S1.

Method Detail

addCompassListener

public void addCompassListener(CompassListener compassListener,
                               double triggerLevel)
Registers the given compass listener for the given trigger level. If the touch thread is not yet started, start it now. If the trigger level is outside the interval 0..<360, returns immediately.

Parameters:
compassListener - the CompassListener to become registered.
triggerLevel - the trigger level where the callback is triggered (0..<360)

addCompassListener

public void addCompassListener(CompassListener compassListener)
Registers the given compass listener with default trigger level 180.

Parameters:
compassListener - the CompassListener to become registered.

setTriggerLevel

public double setTriggerLevel(double triggerLevel)
Sets a new trigger level and returns the previous one.

Parameters:
triggerLevel - the new trigger level
Returns:
the previous trigger level

getDegrees

public double getDegrees()
Polls the sensor.

Returns:
the current compass reading (0..<360 clockwise, 0 to north)

startCalibration

public void startCalibration()
Starts calibration process. Needs at least 2 full rotations with at least 20 s per rotation before stopCalibration() is called.

See Also:
stopCalibration()

stopCalibration

public void stopCalibration()
Stops calibration process.

See Also:
startCalibration()

getLejosSensor

public lejos.nxt.addon.CompassHTSensor getLejosSensor()
Returns the reference of the the underlying lejos.nxt.CompassSensor.

Returns:
the reference of the CompassSensor