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

lejos.hardware.sensor.HiTechnicMagneticSensor 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;
import lejos.robotics.SampleProvider;


/**
 * 
* The sensor detects magnetic fields that are present around the front of the sensor in a vertical orientation. * *

* The code for this sensor has not been tested. Please report test results to * the leJOS forum. *

* *

*

* * * * * * * * * * * * * * * *
Supported modes
Mode nameDescriptionunit(s)Getter
MagneticMeasures the strength of a vertical magnetic fieldN/A, normalized {@link #getMagneticMode() }
* * *

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

* * * @author Lawrie Griffiths * */public class HiTechnicMagneticSensor extends AnalogSensor implements SensorConstants {; /** * Create a magnetic sensor on an analog port * * @param port the analog port */ public HiTechnicMagneticSensor(AnalogPort port) { super(port); init(); } /** * Create a magnetic sensor on a sensor port * * @param port the analog port */ public HiTechnicMagneticSensor(Port port) { super(port); init(); } protected void init() { setModes(new SensorMode[]{ new MagneticMode() }); port.setTypeAndMode(TYPE_CUSTOM, MODE_RAW); } /** * HiTechnic Magnetic sensor, Magnetic mode
* Measures the strength og the vertical magnetic field * *

* Size and content of the sample
* The sample contains one element containing the strength of the magnetic field around the sensor. * The value is normalized (0-1) where 1 corresponds with the maximum field strength. */ public SampleProvider getMagneticMode() { return getMode(0); } private class MagneticMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { sample[offset] = normalize(port.getPin1()); } @Override public String getName() { return "Magnetic"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy