dLife Home Page

dlife.robot.khepera2
Class Khepera2IRSensor

java.lang.Object
  extended by java.util.Observable
      extended by dlife.robot.Device
          extended by dlife.robot.ArraySensor<Integer>
              extended by dlife.robot.khepera2.Khepera2IRSensor
Direct Known Subclasses:
Khepera2ProximitySensor

public class Khepera2IRSensor
extends ArraySensor<Integer>

A class for reading the Khepera2's infrared (IR) sensors. Each IR sensor reports an integer value in the range [0...1023] with smaller values indicating more intense IR light. These sensors are passive, they detect IR light that is present in the robot's environment. The IR sensors are arranged around the robot as shown in Figure 1 below.


Figure 1: A khepera2 robot with the IR/Proximity sensors labeled.
Numerals in the circles correspond to the index of the sensor data
in the Khepera2IRSensor and Khepera2ProximitySensor objects.

Methods are provided for reading the sensors in a variety of ways as illustrated below. The sample code shown assumes that an IR sensor has been created and added to the robot (typically in the startUp method of a Controller) as shown: here:

It is possible to retrieve all or a sub-set of the sensor readings as an ArrayList:

It is also possible to retrieve an individual sensor reading, either by index or by using one of the defined class constants:

Methods are also provided for obtaining the maximum, minimum or average of a group of sensor readings:

Version:
Jan 19, 2011
Author:
Grant Braught, Dickinson College

Nested Class Summary
protected static class Khepera2IRSensor.IRSensorDisplay
          A display for the values of a Khepera2IRSensor.
 
Field Summary
static int[] ALL
          Sensor group containing all of the sensors.
static int[] FRONT_GROUP
          Sensor group for the Khepera2's front sensors.
static int FRONT_LEFT
          The Khepera2's front left sensor.
static int FRONT_RIGHT
          The Khepera2's front right sensor.
static int LEFT
          The Khepera2's left sensor.
static int LEFT_FRONT
          The Khepera2's left front sensor.
static int[] LEFT_GROUP
          Sensor group for the Khepera2's left side sensors.
static int LEFT_REAR
          The Khepera2's left rear sensor.
static int[] REAR_GROUP
          Sensor group for the Khepera2's rear facing sensors.
static int RIGHT
          The Khepera2's right sensor.
static int RIGHT_FRONT
          The Khepera2's right front sensor.
static int[] RIGHT_GROUP
          Sensor group for the Khepera2's right side sensors.
static int RIGHT_REAR
          The Khepera2's right rear sensor.
 
Fields inherited from class dlife.robot.ArraySensor
length, values
 
Fields inherited from class dlife.robot.Device
DEFAULT_GUI_UPDATE_DELAY, DEFAULT_READ_DELAY, myRobot, readCount
 
Constructor Summary
Khepera2IRSensor()
          Construct a new Khepera2IRSensor.
 
Method Summary
protected  DeviceDisplay[] createGUIObjects()
          Get the object that is the GUI for this Khepera2IRSensor.
 void freeze()
          Does nothing.
static void main(String[] args)
          A little test program for the Khepera2IRSensor.
protected  void read(String cmd)
          Protected method to allow the sub-class for the proximity sensor to share this code.
 void readStateFromRobot()
          Get the current IR light sensor readings from the Khepara2.
 
Methods inherited from class dlife.robot.ArraySensor
getAverage, getAverage, getMaximum, getMaximum, getMaximumIndex, getMaximumIndex, getMinimum, getMinimum, getMinimumIndex, getMinimumIndex, getNumValues, getSubset, getValue, getValues
 
Methods inherited from class dlife.robot.Device
getAutoRead, getGUI, getGUIUpdateDelay, getReadDelay, getRobot, getSensorReadCount, getSensorReadRate, 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

FRONT_GROUP

public static final int[] FRONT_GROUP
Sensor group for the Khepera2's front sensors. This group includes sensors 2 and 3 in that order.


RIGHT_GROUP

public static final int[] RIGHT_GROUP
Sensor group for the Khepera2's right side sensors. This group includes sensors 4 and 5 in that order.


LEFT_GROUP

public static final int[] LEFT_GROUP
Sensor group for the Khepera2's left side sensors. This group includes sensors 0 and 1 in that order.


REAR_GROUP

public static final int[] REAR_GROUP
Sensor group for the Khepera2's rear facing sensors. This group includes sensors 6 and 7 in that order.


ALL

public static final int[] ALL
Sensor group containing all of the sensors.


FRONT_LEFT

public static final int FRONT_LEFT
The Khepera2's front left sensor.

See Also:
Constant Field Values

FRONT_RIGHT

public static final int FRONT_RIGHT
The Khepera2's front right sensor.

See Also:
Constant Field Values

LEFT_FRONT

public static final int LEFT_FRONT
The Khepera2's left front sensor.

See Also:
Constant Field Values

RIGHT_FRONT

public static final int RIGHT_FRONT
The Khepera2's right front sensor.

See Also:
Constant Field Values

LEFT

public static final int LEFT
The Khepera2's left sensor.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
The Khepera2's right sensor.

See Also:
Constant Field Values

RIGHT_REAR

public static final int RIGHT_REAR
The Khepera2's right rear sensor.

See Also:
Constant Field Values

LEFT_REAR

public static final int LEFT_REAR
The Khepera2's left rear sensor.

See Also:
Constant Field Values
Constructor Detail

Khepera2IRSensor

public Khepera2IRSensor()
Construct a new Khepera2IRSensor.

Method Detail

readStateFromRobot

public void readStateFromRobot()
Get the current IR light sensor readings from the Khepara2. The new values are copied into the values array defined by the IntegerArraySensor class.

Specified by:
readStateFromRobot in class Device
Throws:
RobotCommunicationException - if unable to communicate with the Khepara2.

freeze

public void freeze()
Does nothing. There is no motion associated with an IR sensor to stop.

Specified by:
freeze in class Device

read

protected void read(String cmd)
Protected method to allow the sub-class for the proximity sensor to share this code.

Parameters:
cmd - the command string for reading the sensor.
Throws:
RobotCommunicationException - if unable to communicate with the Khepara2.

createGUIObjects

protected DeviceDisplay[] createGUIObjects()
Get the object that is the GUI for this Khepera2IRSensor.

Specified by:
createGUIObjects in class Device
Returns:
an array of DeviceDisplay subclass objects that make up the GUI for this Device.

main

public static void main(String[] args)
A little test program for the Khepera2IRSensor. This creates a new Khepera2 and a new Khepera2IRSensor. It displays the GUI for the ir sensor readings until the window is closed.

Parameters:
args - none

dLife Home Page