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

lejos.hardware.sensor.HiTechnicIRSeekerV2 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.I2CPort;
import lejos.hardware.port.Port;


/**
 * HiTechnic NXT IRSeeker V2
* The NXT IRSeeker V2 (Version 2) 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 nameDescriptionunit(s)Getter
modulatedMeasures the angle to a source of modulated (1200 Hz square wave) infrared lightDegrees {@link #getModulatedMode() }
UnmodulatedMeasures the angle to a source of unmodulated infrared lightDegrees {@link #getUnmodulatedMode() }
* * *

* * See * Sensor Product page * See The * leJOS sensor framework * See {@link lejos.robotics.SampleProvider leJOS conventions for * SampleProviders} * *

* * * @author Lawrie Griffiths * */ public class HiTechnicIRSeekerV2 extends I2CSensor { private static final byte address = 0x10; private byte[] buf = new byte[1]; public HiTechnicIRSeekerV2(I2CPort port) { super(port, address); init(); } public HiTechnicIRSeekerV2(Port port) { super(port, address); init(); } protected void init() { setModes(new SensorMode[]{ new ModulatedMode(), new UnmodulatedMode() }); } /** * HiTechnic IR seeker V2, modulated mode
* Measures the angle to a source of a modulated 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 getModulatedMode() { return getMode(0); } private class ModulatedMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { getData(0x49, buf, 1); float angle = Float.NaN; if (buf[0] > 0) { // Convert to angle with zero forward, anti-clockwise positive angle = -(buf[0] * 30 - 150); } sample[offset] = angle; } @Override public String getName() { return "Modulated"; } } /** * HiTechnic IR seeker V2, 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(1); } 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) { // Convert to angle with zero forward, anti-clockwise positive angle = -(buf[0] * 30 - 150); } sample[offset] = angle; } @Override public String getName() { return "Unmodulated"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy