public class FusorDetector extends java.lang.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.
Modifier and Type | Class and Description |
---|---|
private class |
FusorDetector.NotifyThread
Thread to periodically notify listeners.
|
Modifier and Type | Field and Description |
---|---|
private int |
delay
The delay (in ms) between notifying listeners of detected features (if any are detected).
|
private java.util.ArrayList<FeatureDetector> |
detectors |
private boolean |
enabled |
private java.util.ArrayList<FeatureListener> |
listeners |
private java.util.ArrayList<RangeReadings> |
readings |
Constructor and Description |
---|
FusorDetector() |
Modifier and Type | Method and Description |
---|---|
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.
|
private void |
notifyListeners(Feature feature) |
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.
|
private java.util.ArrayList<FeatureDetector> detectors
private java.util.ArrayList<RangeReadings> readings
private int delay
private boolean enabled
private java.util.ArrayList<FeatureListener> listeners
public void addDetector(FeatureDetector detector)
detector
- public Feature scan()
scan
in interface FeatureDetector
public void featureDetected(Feature feature, FeatureDetector detector)
featureDetected
in interface FeatureListener
feature
- The RangeReading, which contains angle and range.private void notifyListeners(Feature feature)
public void addListener(FeatureListener listener)
FeatureDetector
addListener
in interface FeatureDetector
listener
- The FeatureListener that is notified every time a feature is detected.public void enableDetection(boolean on)
enableDetection
in interface FeatureDetector
on
- true enables detection and notifications, false disables this class until it is enabled again.public int getDelay()
FeatureDetector
getDelay
in interface FeatureDetector
public boolean isEnabled()
FeatureDetector
isEnabled
in interface FeatureDetector
public void setDelay(int delay)
FeatureDetector
setDelay
in interface FeatureDetector
delay
- The FeatureDetector will return one new set of readings every delay milliseconds.