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

lejos.hardware.sensor.HiTechnicEOPD 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.hardware.sensor;

import lejos.hardware.port.AnalogPort;
import lejos.hardware.port.Port;

/**
 * HiTechnic EOPD Sensor
* The EOPD or Electro Optical Proximity Detector uses an internal light source to detect the presence of a target or determine changes in distance to a target. * *

*

* * * * * * * * * * * * * * * * * * * * * *
Supported modes
Mode nameDescriptionunit(s)Getter
Long DistanceMeasures the relative distance to an objectN/A, a normalized value that represents the relative distance to an object. 0 = minimum range, 1 = maximum range. {@link #getLongDistanceMode() }
Short DistanceMeasures the relative distance to an objectN/A, a normalized value that represents the relative distance to an object. 0 = minimum range, 1 = maximum range. {@link #getShortDistanceMode() }
* * * * See Sensor Product page * See The * leJOS sensor framework * See {@link lejos.robotics.SampleProvider leJOS conventions for * SampleProviders} * *

* * * @author Michael Smith * */ public class HiTechnicEOPD extends AnalogSensor implements SensorConstants { protected static final long SWITCH_DELAY = 10; /** * @param port NXT sensor port 1-4 */ public HiTechnicEOPD (AnalogPort port){ super(port); init(); } /** * @param port NXT sensor port 1-4 */ public HiTechnicEOPD (Port port){ super(port); init(); } protected void init() { setModes(new SensorMode[]{ new LongDistanceMode(), new ShortDistanceMode() }); } /** * HiTechnic EOPD sensor, Long distance mode
* Measures the relative distance to a surface. * *

* Size and content of the sample
* The sample contains one element containing the relative distance to a surface in the range of 0 to 1. * Where 0 corresponds to the minimum of the measurement range and 1 corresponds to the maximum of the measyurement range. * The measurement range depends on the color and reflectivity of the measured surface. The measurement is more or less linear to the distance for a given surface. */ public SensorMode getLongDistanceMode() { return getMode(0); } private class LongDistanceMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { switchType(TYPE_LIGHT_INACTIVE, SWITCH_DELAY); sample[offset] = (float) Math.sqrt((normalize(port.getPin1()))); } @Override public String getName() { return "Long distance"; } } /** * HiTechnic EOPD sensor, Short distance mode
* Measures the relative distance to a surface. This mode is suited for white objects at short distance. * *

* Size and content of the sample
* The sample contains one element containing the relative distance to a surface in the range of 0 to 1. * Where 0 corresponds to the minimum of the measurement range and 1 corresponds to the maximum of the measyurement range. * The measurement range depends on the color and reflectivity of the measured surface. The measurement is more or less linear to the distance for a given surface. */ public SensorMode getShortDistanceMode() { return getMode(1); } public class ShortDistanceMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { switchType(TYPE_LIGHT_ACTIVE, SWITCH_DELAY); sample[offset] = (float) Math.sqrt((normalize(port.getPin1()))); } @Override public String getName() { return "Short distance"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy