lejos.robotics.DirectionFinderAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lejos-ev3-api Show documentation
Show all versions of lejos-ev3-api Show documentation
leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.
The newest version!
package lejos.robotics;
import lejos.robotics.filter.ModulusFilter;
public class DirectionFinderAdapter implements DirectionFinder {
private Calibrate calibrator;
private SampleProvider provider, initialProvider;
private float[] sample = new float[1];
public DirectionFinderAdapter(SampleProvider provider) {
this.provider = provider;
initialProvider = provider;
if (provider instanceof Calibrate) this.calibrator = (Calibrate) provider;
}
@Override
public float getDegreesCartesian() {
provider.fetchSample(sample, 0);
return sample[0];
}
@Override
public void startCalibration() {
if (calibrator != null) calibrator.startCalibration();
}
@Override
public void stopCalibration() {
if (calibrator != null) calibrator.stopCalibration();
}
@Override
public void resetCartesianZero() {
float[] sample = new float[1];
initialProvider.fetchSample(sample,0);
provider = new ModulusFilter(initialProvider, sample, 360);
}
}