Class RangeFeatureDetector
- java.lang.Object
-
- lejos.robotics.objectdetection.FeatureDetectorAdapter
-
- lejos.robotics.objectdetection.RangeFeatureDetector
-
- All Implemented Interfaces:
FeatureDetector
public class RangeFeatureDetector extends FeatureDetectorAdapter
The RangeFeatureDetector used a RangeFinder to locate objects (known as features when mapping). This class is unable to identify the feature and merely reports the range and angle to the object.
You can also have the scan identify the object (such as a camera using facial recognition to identify a person). One possibility to implement this is to extend RangeFeatureDetector and add a camera to the constructor. When the FeatureDetector range scanner detects an object, take a picture and look for a face in the image. This is then reported as an extended class of RangeFeature called PersonFeature, which has a getPerson() method containing information on the object that was detected.
To create a more complex FeatureDetector, extend this class and override the
FeatureDetector.scan()method. It is possible to add more complex functionality in this method, such as only returning a "hit" if the scanner detects an object in the same location twice in a row. This type of filtering could also take place in the FeatureListener method, although then singleFeatureDetector.scan()calls will not contain the filtering.- Author:
- BB based on concepts by Lawrie Griffiths
-
-
Constructor Summary
Constructors Constructor Description RangeFeatureDetector(RangeFinder rf, float maxDistance, int delay)This constructor allows you to specify the sensor, the maximum distance to report a detection, and the delay between scanning the sensor.RangeFeatureDetector(RangeFinder rf, float maxDistance, int delay, double angle)This constructor allows you to specify the sensor, the maximum distance to report a detection, the delay between scanning the sensor, and the angle the sensor is pointed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetMaxDistance()Returns the maximum distance the FeatureDetector will return for detected objects.Featurescan()Performs a single scan for an object and returns the results.voidsetMaxDistance(float distance)Sets the maximum distance to register detected objects from the range finder.voidsetPoseProvider(PoseProvider pp)-
Methods inherited from class lejos.robotics.objectdetection.FeatureDetectorAdapter
addListener, enableDetection, getDelay, isEnabled, notifyListeners, setDelay
-
-
-
-
Constructor Detail
-
RangeFeatureDetector
public RangeFeatureDetector(RangeFinder rf, float maxDistance, int delay)
This constructor allows you to specify the sensor, the maximum distance to report a detection, and the delay between scanning the sensor. It assumes the range sensor is pointed straight ahead, so heading is always 0 for the returned RangeReading.- Parameters:
rf- The range finder sensor. e.g. UltrasonicSensormaxDistance- The upper limit of distance it will report. e.g. 40 cm.delay- The interval range finder checks for objects. e.g. 250 ms.
-
RangeFeatureDetector
public RangeFeatureDetector(RangeFinder rf, float maxDistance, int delay, double angle)
This constructor allows you to specify the sensor, the maximum distance to report a detection, the delay between scanning the sensor, and the angle the sensor is pointed.- Parameters:
rf- The range finder sensor. e.g. UltrasonicSensormaxDistance- The upper limit of distance it will report. e.g. 40 cm.delay- The interval range finder checks for objects. e.g. 250 ms.angle- The angle, in degrees, the range sensor is pointed. (0 = forward, +ve = left, -ve = right)
-
-
Method Detail
-
setPoseProvider
public void setPoseProvider(PoseProvider pp)
-
setMaxDistance
public void setMaxDistance(float distance)
Sets the maximum distance to register detected objects from the range finder.- Parameters:
distance- The maximum distance. e.g. 40 cm.
-
getMaxDistance
public float getMaxDistance()
Returns the maximum distance the FeatureDetector will return for detected objects.- Returns:
- The maximum distance. e.g. 40 cm.
-
scan
public Feature scan()
Description copied from interface:FeatureDetectorPerforms a single scan for an object and returns the results. If an object is not detected, this method returns null.
Warning: Make sure to check for a null object before trying to read data from the returned Feature object, otherwise your code will throw a null pointer exception.
- Specified by:
scanin interfaceFeatureDetector- Specified by:
scanin classFeatureDetectorAdapter- Returns:
- A feature it has detected. null if nothing found.
-
-