dLife Home Page

dlife.robot.pioneer
Class PioneerBumpers

java.lang.Object
  extended by java.util.Observable
      extended by dlife.robot.Device
          extended by dlife.robot.ArraySensor<Boolean>
              extended by dlife.robot.pioneer.PioneerBumpers

public class PioneerBumpers
extends ArraySensor<Boolean>

A class for reading the state of the Pioneer's bumpers. Each sensor reading corresponds to the value of a single bumper. The assignment between the readings and the particular sensors are expressed by the class constants. Each sensor reading is a boolean value indicating if the bumper is pressed (true) or not (false).

This sensor displays readings for the 10 standard bumpers on the Pioneer (see figure 1). If either the front or rear bumpers are not currently installed then the readings for the non-installed bumpers will be false.



Figure 1: Light blue circles indicate the locations and indices of the Pioneer's bumpers.

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

The state of an individual bumper can be checked by index:

It is also possible to check if any of the bumpers in a group or list is currently triggered:

Version:
June 17, 2008
Author:
Grant Braught, Dickinson College

Field Summary
static int[] ALL
          Sensor group for all of the bumpers.
static int[] FRONT
          Sensor group for all of the front end bumpers.
static int[] LEFT
          Sensor group for the two leftmost bumpers.
static int[] REAR
          Sensor group for all of the rear end bumpers.
static int[] RIGHT
          Sensor group for the two rightmost bumpers.
 
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
PioneerBumpers()
          Construct a new PioneerBumpers.
 
Method Summary
 boolean bump()
          Determine if any of the bumpers are triggered.
 boolean bump(int... bumperList)
          Determine if any of the listed bumpers are triggered.
protected  DeviceDisplay[] createGUIObjects()
          Get the object that is the GUI for this PioneerBumpers sensor.
 void freeze()
          Does nothing.
static void main(String[] args)
          A little test program for the PioneerBumpers.
 void readStateFromRobot()
          Get the current bumper readings from the Pioneer.
 
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

public static final int[] FRONT
Sensor group for all of the front end bumpers. Includes sensors {0, 1, 2, 3, 4}.


REAR

public static final int[] REAR
Sensor group for all of the rear end bumpers. Includes sensors {5, 6, 7, 8, 9}.


LEFT

public static final int[] LEFT
Sensor group for the two leftmost bumpers. Includes sensors {0, 9}.


RIGHT

public static final int[] RIGHT
Sensor group for the two rightmost bumpers. Includes sensors {4, 5}.


ALL

public static final int[] ALL
Sensor group for all of the bumpers.

Constructor Detail

PioneerBumpers

public PioneerBumpers()
Construct a new PioneerBumpers.

Method Detail

bump

public boolean bump(int... bumperList)
Determine if any of the listed bumpers are triggered.

Parameters:
bumperList - a comma delimited list of the indices of the bumpers to check.
Returns:
true if any of the listed bumpers are triggered.
Throws:
IllegalArgumentException - if any of the bumper indices listed are invalid.

bump

public boolean bump()
Determine if any of the bumpers are triggered.

Returns:
true if any bumper is triggered.

readStateFromRobot

public void readStateFromRobot()
Get the current bumper readings from the Pioneer. The new values are copied into the values array defined by the ArraySensor class.

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

freeze

public void freeze()
Does nothing.

Specified by:
freeze in class Device

createGUIObjects

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

Specified by:
createGUIObjects in class Device
Returns:
a reference to the GUI.

main

public static void main(String[] args)
                 throws Exception
A little test program for the PioneerBumpers. This creates a new Pioneer and a new PioneerBumpers. It displays the GUI for the bumper readings and then updates the sensor readings until the window is closed.

Parameters:
args - none
Throws:
Exception

dLife Home Page