Package lejos.robotics.objectdetection
Class TouchFeatureDetector
- java.lang.Object
-
- lejos.robotics.objectdetection.FeatureDetectorAdapter
-
- lejos.robotics.objectdetection.TouchFeatureDetector
-
- All Implemented Interfaces:
FeatureDetector
public class TouchFeatureDetector extends FeatureDetectorAdapter
This class allows a touch sensor to be used as a defacto range sensor by reporting the position of the touch sensor to the object detection API. The touch sensor will only notify one time when it is pressed and will not be ready to notify again until the touch sensor is released.- Author:
- BB
-
-
Constructor Summary
Constructors Constructor Description TouchFeatureDetector(Touch touchSensor)Creates a touch detector in which the touch sensor is assumed to be situated in the center of the robot.TouchFeatureDetector(Touch touchSensor, double xOffset, double yOffset)If you want the bumpers to report contact relative to the geometry of where they are placed on the robot, you can provide the x, y offsets of each bumper relative to the center of the robot (the center is the halfway point between the drive wheels).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidnotifyListeners(Feature feature)Featurescan()Performs a single scan for an object and returns the results.-
Methods inherited from class lejos.robotics.objectdetection.FeatureDetectorAdapter
addListener, enableDetection, getDelay, isEnabled, setDelay
-
-
-
-
Constructor Detail
-
TouchFeatureDetector
public TouchFeatureDetector(Touch touchSensor)
Creates a touch detector in which the touch sensor is assumed to be situated in the center of the robot. This is fine in situations where the robot only needs to react to a bumper contact. See the alternate constructor if more than one bumper is located around the robot.- Parameters:
touchSensor- The touch sensor bumper.
-
TouchFeatureDetector
public TouchFeatureDetector(Touch touchSensor, double xOffset, double yOffset)
If you want the bumpers to report contact relative to the geometry of where they are placed on the robot, you can provide the x, y offsets of each bumper relative to the center of the robot (the center is the halfway point between the drive wheels). Most bumpers are planar, so generally you would use the center of the bumper as the contact point.- Parameters:
touchSensor- The touch sensor bumper.xOffset- The offset (in units e.g. cm) left or right of center. Right is positive, left is negative.yOffset- The offset (in units e.g. cm) forward or back of center. Forward is positive, back is negative.
-
-
Method Detail
-
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.
-
notifyListeners
protected void notifyListeners(Feature feature)
- Overrides:
notifyListenersin classFeatureDetectorAdapter
-
-