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

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

/**
 * Support for Dexter Industries DPressure250
 * Not tested.
 * 
 * See http://www.dexterindustries.com/Products-dPressure.html.
 * 
 * @author Lawrie Griffiths
 *
 */


/**
 * Dexter Industries DPressure250
* Pressure sensor for LEGO® MINDSTORMS® EV3 and NXT. * *

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

* *

*

* * * * * * * * * * * * * * * *
Supported modes
Mode nameDescriptionunit(s)Getter
PressureMeasures the pressure Pascal {@link #getPressureMode() }
* * *

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

* * * @author Lawrie Griffiths * */ public class DexterPressureSensor250 extends AnalogSensor implements SensorConstants { /* * * Formula from DPRESS-driver.h: * vRef = 4.85 * vOut = rawValue * vRef / 1023 * result = (vOut / vRef - CAL1) / CAL2 */ private static final double CAL1 = 0.04; private static final double CAL2 = 0.00369; /* * Optimized: * result = rawValue * DPRESS_MULT - DPRESS_OFFSET; */ private static final float DPRESS_MULT = (float)(1.0 / (CAL2 )); private static final float DPRESS_OFFSET = (float)(CAL1 / CAL2); public DexterPressureSensor250(AnalogPort port) { super(port); init(); } public DexterPressureSensor250(Port port) { super(port); init(); } protected void init() { setModes(new SensorMode[]{ new PressureMode() }); port.setTypeAndMode(TYPE_CUSTOM, MODE_RAW); } /** * Dexter Industries DPressure250, Pressure mode
* Measures the pressure * *

* Size and content of the sample
* The sample contains one element containing the pressure (in PA) measured by the sensor. * *

* * @return A sampleProvider * See {@link lejos.robotics.SampleProvider leJOS conventions for * SampleProviders} * See Sensor datasheet */ public SampleProvider getPressureMode() { return getMode(0); } private class PressureMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { sample[offset] = (NXTRawValue(normalize(port.getPin1())) * DPRESS_MULT - DPRESS_OFFSET)* 1000f; // in pascals } @Override public String getName() { return "Pressure"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy