lejos.robotics.objectdetection
Class FusorDetector

java.lang.Object
  extended by lejos.robotics.objectdetection.FusorDetector
All Implemented Interfaces:
FeatureDetector, FeatureListener

public class FusorDetector
extends Object
implements FeatureDetector, FeatureListener

If you have a robot with multiple sensors (touch and range) and would like them to report to one listener, or if you want to control them at the same time (such as disabling them all at once) you can use this class.

This class maintains its own thread for checking the FeatureDetectors.

Author:
BB

Constructor Summary
FusorDetector()
           
 
Method Summary
 void addDetector(FeatureDetector detector)
          This method adds another FeatureDetector to the FusorDetector.
 void addListener(FeatureListener listener)
          Adds a listener to the FeatureDetector.
 void enableDetection(boolean on)
          This method enables/disables automatic scanning and listener reporting for this object and all FeatureDetectors used in this FusorDetector object.
 void featureDetected(Feature feature, FeatureDetector detector)
          This method must deal with different delays from different sensors.
 int getDelay()
          The minimum delay between notification of readings from the feature detector.
 boolean isEnabled()
          Indicates if automatic scanning mode and listener notification is currently enabled.
 Feature scan()
          This method scans all the sensors added to this object and returns the amalgamated results.
 void setDelay(int delay)
          Sets the minimum delay between readings from the feature detector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FusorDetector

public FusorDetector()
Method Detail

addDetector

public void addDetector(FeatureDetector detector)
This method adds another FeatureDetector to the FusorDetector. This method will set the delay for this class to the largest delay if comes across from all the FeatureDetector objects added to it.

Parameters:
detector -

scan

public Feature scan()
This method scans all the sensors added to this object and returns the amalgamated results. NOTE: This method is not called by the thread code.

Specified by:
scan in interface FeatureDetector
Returns:
A feature it has detected. null if nothing found.

featureDetected

public void featureDetected(Feature feature,
                            FeatureDetector detector)
This method must deal with different delays from different sensors. e.g. Touch is 50 ms, while ultrasonic is 250 ms. But must amalgamate readings that are captured over same period. SOLUTION: Use listeners. Get max scan time (e.g. 250 ms) and wait that long for each listener to report in before reporting all at once.

Specified by:
featureDetected in interface FeatureListener
Parameters:
feature - The RangeReading, which contains angle and range.

addListener

public void addListener(FeatureListener listener)
Description copied from interface: FeatureDetector
Adds a listener to the FeatureDetector. The FeatureListener will be notified when objects are detected.

Specified by:
addListener in interface FeatureDetector
Parameters:
listener - The FeatureListener that is notified every time a feature is detected.

enableDetection

public void enableDetection(boolean on)
This method enables/disables automatic scanning and listener reporting for this object and all FeatureDetectors used in this FusorDetector object.

Specified by:
enableDetection in interface FeatureDetector
Parameters:
on - true enables detection and notifications, false disables this class until it is enabled again.

getDelay

public int getDelay()
Description copied from interface: FeatureDetector
The minimum delay between notification of readings from the feature detector. If no objects are detected, no notification will occur. Some sensors, such as touch sensors, check the sensor more frequently than other sensors, such as range sensors.

Specified by:
getDelay in interface FeatureDetector
Returns:
The delay between sensor readings.

isEnabled

public boolean isEnabled()
Description copied from interface: FeatureDetector
Indicates if automatic scanning mode and listener notification is currently enabled. (true by default)

Specified by:
isEnabled in interface FeatureDetector
Returns:
true if enabled, false if not

setDelay

public void setDelay(int delay)
Description copied from interface: FeatureDetector
Sets the minimum delay between readings from the feature detector. The notification thread will notify FeatureListener objects every delay milliseconds, unless it takes longer to retrieve readings from the sensor.

Specified by:
setDelay in interface FeatureDetector
Parameters:
delay - The FeatureDetector will return one new set of readings every delay milliseconds.