lejos.nxt.addon
Class NXTLineLeader

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

public class NXTLineLeader
extends I2CSensor

This class manages the sensor NXT Line Leader from Mindsensors. The sensor add a sensor row to detect black/white lines. This sensor is perfect to build a robot which has the mission to follow a line.

Author:
Juan Antonio Brenha Moral, Eric Pascual (EP)

Nested Class Summary
static class NXTLineLeader.Command
           
static class NXTLineLeader.LineColor
          Color selector for white reading limit
 
Field Summary
 
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
NXTLineLeader(I2CPort port)
          Constructor
NXTLineLeader(I2CPort port, int address)
          Constructor
 
Method Summary
 void calibrate(NXTLineLeader.LineColor color)
          Calibrate the white and black levels.
 int getAverage()
          Get the average value
 int getCalibratedSensorReading(int index)
          Get the calibrated reading of a given sensor
 int getCalibrationData(int index, NXTLineLeader.LineColor color)
          Get the calibration data for white and black colors for a given sensor
 int getKD()
          Get KD value
 int getKDDivisor()
          Get KD divisor
 int getKI()
          Get KI value
 int getKIDivisor()
          Get KI divisor
 int getKP()
          Get KP value
 int getKPDivisor()
          Get KP divisor
 int getReadingLimit(int index, NXTLineLeader.LineColor color)
          Get the calibration value for white and black colors for a given sensor
 int getResult()
          Get result value
 int getSensorStatus(int index)
          Deprecated.  
 int getSetPoint()
          Get the set point of the PID.
 int getSteering()
          Get the steering value
 void sendCommand(char cmd)
          Deprecated. use sendCommand(Command) instead
 void sendCommand(NXTLineLeader.Command cmd)
          Send a single byte command represented by a letter
 void setKD(int KD)
          Set KD value
 void setKDDivisor(int value)
          Set the KD divisor
 void setKI(int KI)
          Set KI value
 void setKIDivisor(int value)
          Set the KI divisor
 void setKP(int KP)
          Set KP value
 void setKPDivisor(int value)
          Set the KP divisor
 void setSetPoint(int value)
          Set the set point of the PID
 void sleep()
          Sleep the sensor
 void wakeUp()
          Wake up the sensor
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getAddress, getData, getData, getPort, 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
 

Constructor Detail

NXTLineLeader

public NXTLineLeader(I2CPort port,
                     int address)
Constructor

Parameters:
port -
address - I2C address for the device

NXTLineLeader

public NXTLineLeader(I2CPort port)
Constructor

Parameters:
port -
Method Detail

sendCommand

public void sendCommand(NXTLineLeader.Command cmd)
Send a single byte command represented by a letter

Parameters:
cmd - the command to be sent

sendCommand

@Deprecated
public void sendCommand(char cmd)
Deprecated. use sendCommand(Command) instead

Original version of sendCOmmand, left for compatibility with legacy code.

This version has no checking of the validity of the passed command, so it is advised to use sendCommand(Command) instead.

Parameters:
cmd - the character based command

sleep

public void sleep()
Sleep the sensor


wakeUp

public void wakeUp()
Wake up the sensor


calibrate

public void calibrate(NXTLineLeader.LineColor color)
Calibrate the white and black levels.

Parameters:
color - color selector

getSteering

public int getSteering()
Get the steering value

Steering is a signed value in the range [-100,+100] representing the amount of power to be added/subtracted to motors power setting. In case we cannot read the sensor, Integer.MIN_VALUE is returned to notify the anomaly.


getAverage

public int getAverage()
Get the average value


getResult

public int getResult()
Get result value


getSetPoint

public int getSetPoint()
Get the set point of the PID.


setSetPoint

public void setSetPoint(int value)
Set the set point of the PID


getKP

public int getKP()
Get KP value


setKP

public void setKP(int KP)
Set KP value


getKPDivisor

public int getKPDivisor()
Get KP divisor


setKPDivisor

public void setKPDivisor(int value)
Set the KP divisor


getKI

public int getKI()
Get KI value


setKI

public void setKI(int KI)
Set KI value


getKIDivisor

public int getKIDivisor()
Get KI divisor


setKIDivisor

public void setKIDivisor(int value)
Set the KI divisor


getKD

public int getKD()
Get KD value


setKD

public void setKD(int KD)
Set KD value


getKDDivisor

public int getKDDivisor()
Get KD divisor


setKDDivisor

public void setKDDivisor(int value)
Set the KD divisor


getSensorStatus

@Deprecated
public int getSensorStatus(int index)
Deprecated. 

Get status from each sensor in the raw


getCalibratedSensorReading

public int getCalibratedSensorReading(int index)
Get the calibrated reading of a given sensor

Parameters:
index - sensor index (must be in range [1..8])
Returns:
sensor reading (in range [0..100]), or -1 if reading error
Throws:
IllegalArgumentException - if index not in range

getReadingLimit

public int getReadingLimit(int index,
                           NXTLineLeader.LineColor color)
Get the calibration value for white and black colors for a given sensor

Parameters:
index - sensor index (must be in range [1..8])
color - color selector
Returns:
calibration value (in range [0..255]), or -1 if reading error
Throws:
IllegalArgumentException - if index not in range

getCalibrationData

public int getCalibrationData(int index,
                              NXTLineLeader.LineColor color)
Get the calibration data for white and black colors for a given sensor

Parameters:
index - sensor index (must be in range [1..8])
color - color selector
Returns:
calibration data (in range [0..255]), or -1 if reading error
Throws:
IllegalArgumentException - if index not in range