X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=dsl%2Fruntime%2Fsrc%2Fnl%2Fru%2Fdes%2Fsensors%2FSensorCollector.java;h=db10870145250774d61c89401acc35476f978677;hb=8880a95aedaf51c028818910b64f85472d96c14e;hp=a9c20488704538d15d1b48094745dc3a76aeb5ed;hpb=16aef029cf49685c60c422d36b54d459355e832c;p=des2015.git diff --git a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java index a9c2048..db10870 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java +++ b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java @@ -1,17 +1,22 @@ package nl.ru.des.sensors; -import lejos.hardware.lcd.LCD; +import java.util.HashSet; +import java.util.Set; + +import lejos.hardware.sensor.EV3GyroSensor; import lejos.robotics.SampleProvider; -import lejos.utility.Delay; public class SensorCollector implements MessageHandler{ - public static final int DELAY = 100; + public static final int DELAY = 200; - private static final float DANGER_DISTANCE_FRONT = 0.15f; + private static final float DANGER_DISTANCE_FRONT = 0.175f; private static final float DANGER_DISTANCE_BACK = 0.035f; - private static final float DANGER_LIGHT = 0.45f; + private static final float DANGER_LIGHT = 0.40f; + + private Set variables; //Local sensors + private EV3GyroSensor gyroSensor; private SampleProvider ultra, leftLight, rightLight, gyro; private float[] ultraSamples, leftLightSamples, rightLightSamples, gyroSamples; private long ultraTime, leftLightTime, rightLightTime, gyroTime; @@ -24,11 +29,12 @@ public class SensorCollector implements MessageHandler{ public SensorCollector(SampleProvider ultra, SampleProvider leftLight, SampleProvider rightLight, - SampleProvider gyro){ + EV3GyroSensor gyro){ this.ultra = ultra; this.leftLight = leftLight; this.rightLight = rightLight; - this.gyro = gyro; + this.gyroSensor = gyro; + this.gyro = gyro.getAngleMode(); ultraSamples = new float[ultra.sampleSize()]; gyroSamples = new float[gyro.sampleSize()]; leftLightSamples = new float[leftLight.sampleSize()]; @@ -37,6 +43,12 @@ public class SensorCollector implements MessageHandler{ leftLightTime = System.currentTimeMillis(); rightLightTime = System.currentTimeMillis(); gyroTime = System.currentTimeMillis(); + + color = -1; + leftTouch = false; + rightTouch = false; + frontUltra = Float.MAX_VALUE; + variables = new HashSet(); } //Local sensors @@ -72,9 +84,21 @@ public class SensorCollector implements MessageHandler{ return gyroSamples[0]; } + public void resetGyro(){ + gyroSensor.reset(); + } + //Remote sensors - public boolean collected(int[] colors){ - return false; + public void reset(){ + variables.clear(); + } + + public boolean collected(String var){ + return variables.contains(var); + } + + public void saveVar(String var) { + variables.add(var); } public int color(){