-
Notifications
You must be signed in to change notification settings - Fork 1
/
ObjectDetector.java
69 lines (63 loc) · 1.94 KB
/
ObjectDetector.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package trotty02;
import lejos.hardware.ev3.LocalEV3;
import lejos.hardware.sensor.EV3ColorSensor;
import lejos.robotics.SampleProvider;
import trotty02.UltrasonicPoller;
import lejos.hardware.lcd.TextLCD;
/**
*
* @author Adam
*@since 3.0
*/
public class ObjectDetector {
private SampleProvider usSensor;
private float[] usData;
private UltrasonicPoller usPoller;
private boolean objectDetected = false;
public String detectionMessage = "";
private boolean block = false;
//EV3ColorSensor cS = new EV3ColorSensor(LocalEV3.get().getPort("S2"));
//SampleProvider colorSensor = cS.getColorIDMode();
//int sampleSize = colorSensor.sampleSize();
//float[] sample = new float[sampleSize];
//TextLCD t = LocalEV3.get().getTextLCD();
/**
* constructs an object detector
* @param usSensor the ultrasonic sensor sample provider
* @param usData the samples taken by the usSensor
* @param usPoller the object in charge of taking and processing samples
*/
public ObjectDetector(SampleProvider usSensor, float[] usData, UltrasonicPoller usPoller) {
this.usSensor = usSensor;
this.usData = usData;
this.usPoller = usPoller;
}
/**
* looks for nearby object
* @return the message to display depending on if there is an object or not
*/
public String detectObj(){
//if the robot sees something, stay in loop
if(usPoller.seesSomething() || usPoller.getDistance() == 0){
detectionMessage = "Object Detected";
return detectionMessage;
}
else{
// colorSensor.fetchSample(sample, 0);
// System.out.println(sample[0]);
//if()
detectionMessage ="No Object";
return detectionMessage;
}
//TODO block or styro
}
/**
* gives the message of whether or not an object is currently detected
* @return the detection message according to if there in an object or not
*/
public String getDetection() {
synchronized (this) {
return detectionMessage;
}
}
}