All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.robotics.DirectionFinderAdapter Maven / Gradle / Ivy

Go to download

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);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy