dLife Home Page

dlife.robot
Class ArraySensor<VTYPE>

java.lang.Object
  extended by java.util.Observable
      extended by dlife.robot.Device
          extended by dlife.robot.ArraySensor<VTYPE>
Direct Known Subclasses:
AiboAccelSensors, AiboBackButtons, AiboBatterySensor, AiboChinButton, AiboHeadButton, AiboIRSensors, AiboPawButtons, ARDroneFlightData, DeadReckoningSensor, FinchAccelerationSensors, FinchLightSensors, FinchObstacleSensors, FinchTemperatureSensor, FlukeIRSensor, HemissonIRSensor, HemissonLCD, HemissonSonar, HemissonSwitches, Khepera2IRSensor, Khepera3BatterySensor, Khepera3IRSensor, Khepera3SonarSensor, OdometrySensor, PioneerBattery, PioneerBumpers, PioneerSonar, ScribblerBattery, ScribblerLightSensor, ScribblerLineSensor, ScribblerObstacleSensor, ScribblerStallSensor

public abstract class ArraySensor<VTYPE>
extends Device

Abstract base class for a sensor with values that can be represented as an array of values.

Version:
Apr 14, 2007
Author:
Grant Braught, Dickinson College

Field Summary
protected  int length
           
protected  ArrayList<VTYPE> values
           
 
Fields inherited from class dlife.robot.Device
DEFAULT_GUI_UPDATE_DELAY, DEFAULT_READ_DELAY, myRobot, readCount
 
Constructor Summary
ArraySensor(int readDelay, int guiUpdateDelay, int length, VTYPE initValue)
          Create a new ArraySensor that provides length values of the specified type.
ArraySensor(int length, VTYPE initValue)
          Create a new ArraySensor that provides length values of the specified type.
 
Method Summary
 double getAverage()
          Compute the average value reported by the sensors.
 double getAverage(int... sensorList)
          Compute the average value reported by the listed sensors.
 VTYPE getMaximum()
          Find the maximum value reported by all of the sensors.
 VTYPE getMaximum(int... sensorList)
          Find the maximum value reported by the listed sensors.
 int getMaximumIndex()
          Find the index of the sensor that reported the maximum value The ordering of the values is imposed by their compareTo method.
 int getMaximumIndex(int... sensorList)
          Find the index of the sensor that reported the maximum value of the listed sensors.
 VTYPE getMinimum()
          Find the minimum value reported by all of the sensors.
 VTYPE getMinimum(int... sensorList)
          Find the minimum value reported by the listed sensors.
 int getMinimumIndex()
          Find the index of the sensor that reported the minimum value The ordering of the values is imposed by their compareTo method.
 int getMinimumIndex(int... sensorList)
          Find the index of the sensor that reported the minimum value of the listed sensors.
 int getNumValues()
          Get the number of sensor values that are contained in this ArraySensor.
 ArrayList<VTYPE> getSubset(int... sensorList)
          Get a subset of the sensor reading for this sensor.
 VTYPE getValue(int index)
          Get the sensor reading for the sensor with the specified index.
 ArrayList<VTYPE> getValues()
          Get the ArrayList that is holding the latest sensor readings.
 
Methods inherited from class dlife.robot.Device
createGUIObjects, freeze, getAutoRead, getGUI, getGUIUpdateDelay, getReadDelay, getRobot, getSensorReadCount, getSensorReadRate, readStateFromRobot, setAutoRead, setGUIUpdateDelay, setReadDelay, setRobot, shutDown, startAutoReadTimer, startUp, stopAutoReadTimer
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

values

protected ArrayList<VTYPE> values

length

protected int length
Constructor Detail

ArraySensor

public ArraySensor(int readDelay,
                   int guiUpdateDelay,
                   int length,
                   VTYPE initValue)
Create a new ArraySensor that provides length values of the specified type. This constructor also allows us to set the delay between updating the device from the robot and between updates to the GUI.

Parameters:
readDelay - the delay (in ms) between attempts to read the device's state from the robot.
guiUpdateDelay - the minimum time (in ms) that will elapse between consecutive notifications of the GUI.
length - the number of sensor values.
initValue - the value for each sensor before the first time they are read.

ArraySensor

public ArraySensor(int length,
                   VTYPE initValue)
Create a new ArraySensor that provides length values of the specified type.

Parameters:
length - the number of sensor values.
initValue - the value for each sensor before the first time they are read.
Method Detail

getNumValues

public int getNumValues()
Get the number of sensor values that are contained in this ArraySensor.

Returns:
the number of sensor values.

getValues

public ArrayList<VTYPE> getValues()
Get the ArrayList that is holding the latest sensor readings. This is the actual ArrayList, so changes to this list will change the sensor's values.

Returns:
the latest sensor readings.

getValue

public VTYPE getValue(int index)
Get the sensor reading for the sensor with the specified index. The specific mapping from index value to sensor is performed by the concrete implementation of this class.

Parameters:
index - the index of the sensor value to get.
Returns:
the value of the sensor with the specified index.
Throws:
IllegalArgumentException - if the index is not valid for this IntegerArraySensor.

getSubset

public ArrayList<VTYPE> getSubset(int... sensorList)
Get a subset of the sensor reading for this sensor. The subset is indicated by a comma delimited list of indices.

Parameters:
sensorList - the indices of the sensor values to include.
Returns:
the sensor values specified. Note that an empty ArrayList will be returned if the sensorList is empty.
Throws:
IllegalArgumentException - if any index in sensorList is not valid for this IntegerArraySensor.

getMaximum

public VTYPE getMaximum()
Find the maximum value reported by all of the sensors. The ordering of the values is imposed by their compareTo method.

Returns:
the maximum of the sensors.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.

getMaximum

public VTYPE getMaximum(int... sensorList)
Find the maximum value reported by the listed sensors. The ordering of the values is imposed by their compareTo method.

Parameters:
sensorList - a comma separated list of integers indicating the sensors.
Returns:
the maximum of the listed sensors.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.
IllegalArgumentException - if sensorList contains an illegal sensor number.

getMaximumIndex

public int getMaximumIndex()
Find the index of the sensor that reported the maximum value The ordering of the values is imposed by their compareTo method.

Returns:
the index of the sensor that has the maximum value.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.

getMaximumIndex

public int getMaximumIndex(int... sensorList)
Find the index of the sensor that reported the maximum value of the listed sensors. The ordering of the values is imposed by their compareTo method.

Parameters:
sensorList - a comma separated list of integers indicating the sensors.
Returns:
the index of the sensor that has the maximum value of those listed. The index returned is the index of the sensor within the given sensorList.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.
IllegalArgumentException - if sensorList contains an illegal sensor number.

getMinimum

public VTYPE getMinimum()
Find the minimum value reported by all of the sensors. The ordering of the values is imposed by their compareTo method.

Returns:
the minimum of the listed sensors.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.

getMinimum

public VTYPE getMinimum(int... sensorList)
Find the minimum value reported by the listed sensors. The ordering of the values is imposed by their compareTo method.

Parameters:
sensorList - a comma separated list of integers indicating the sensors.
Returns:
the minimum of the listed sensors.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.
IllegalArgumentException - if sensorList contains an illegal sensor number.

getMinimumIndex

public int getMinimumIndex()
Find the index of the sensor that reported the minimum value The ordering of the values is imposed by their compareTo method.

Returns:
the index of the sensor that has the minimum value.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.

getMinimumIndex

public int getMinimumIndex(int... sensorList)
Find the index of the sensor that reported the minimum value of the listed sensors. The ordering of the values is imposed by their compareTo method.

Parameters:
sensorList - a comma separated list of integers indicating the sensors.
Returns:
the index of the sensor that has the minimum value of those listed. The index returned is the index of the sensor within the given sensorList.
Throws:
ClassCastException - if any of the elements in this sensor cannot be compared to each other.
IllegalArgumentException - if sensorList contains an illegal sensor number.

getAverage

public double getAverage()
Compute the average value reported by the sensors.

Returns:
the average value of the sensors.
Throws:
ClassCastException - if any of the elements in this sensor cannot be cast to a Number.

getAverage

public double getAverage(int... sensorList)
Compute the average value reported by the listed sensors.

Parameters:
sensorList - a comma separated list of integers indicating the sensors.
Returns:
the average value of the listed sensors.
Throws:
ClassCastException - if any of the elements in this sensor cannot be cast to a Number.
IllegalArgumentException - if sensorList contains an illegal sensor number.

dLife Home Page