lejos.hardware.sensor.HiTechnicIRSeeker Maven / Gradle / Ivy
Show all versions of lejos-ev3-api Show documentation
package lejos.hardware.sensor;
import lejos.hardware.port.I2CPort;
import lejos.hardware.port.Port;
/**
* HiTechnic NXT IRSeeker
* The NXT IRSeeker is a multi-element infrared detector that
* detects infrared signals from sources such as the HiTechnic IRBall soccer
* ball, infrared remote controls and sunlight.
*
*
* The code for this sensor has not been tested. Please report test results to
* the leJOS forum.
*
*
*
*
*
* Supported modes
*
*
* Mode name
* Description
* unit(s)
* Getter
*
*
* Unmodulated
* Measures the angle to a source of unmodulated infrared light
* Degrees
* {@link #getUnmodulatedMode() }
*
*
*
*
*
*
* See
* Sensor Product page
* See The
* leJOS sensor framework
* See {@link lejos.robotics.SampleProvider leJOS conventions for
* SampleProviders}
*
*
*
*
* @author ?
*
*/
public class HiTechnicIRSeeker extends I2CSensor {
byte[] buf = new byte[1];
public HiTechnicIRSeeker(I2CPort port) {
super(port);
init();
}
public HiTechnicIRSeeker(Port port) {
super(port);
init();
}
protected void init() {
setModes(new SensorMode[] { new UnmodulatedMode() });
}
/**
* HiTechnic IR seeker, Unmodulated mode
* Measures the angle to a source of unmodulated infrared light
*
*
* Size and content of the sample
* The sample contains one element containing the angle to the infrared source. The angle is expressed in degrees following the right hand rule.
*/
public SensorMode getUnmodulatedMode() {
return getMode(0);
}
/**
* Measures angle with zero forward, anti-clockwise positive
*/
private class UnmodulatedMode implements SensorMode {
@Override
public int sampleSize() {
return 1;
}
@Override
public void fetchSample(float[] sample, int offset) {
getData(0x42, buf, 1);
float angle = Float.NaN;
if (buf[0] > 0) {
angle = -(buf[0] * 30 - 150);
}
sample[offset] = angle;
}
@Override
public String getName() {
return "Unmodulated";
}
}
}