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

lejos.hardware.sensor.HiTechnicGyro 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 NXT Gyro Sensor
* The NXT Gyro Sensor contains a single axis gyroscopic sensor that detects rotation. * *

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

* *

*

* * * * * * * * * * * * * * * *
Supported modes
Mode nameDescriptionunit(s)Getter
RateThe Rate mode measures the angular speed of the sensor over a single axisDegrees/second {@link #getRateMode() }
* * *

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

* * * @author Lawrie Griffiths * */ public class HiTechnicGyro extends AnalogSensor implements SensorConstants { private static final float TO_SI=-1; private float zero = 600f; /** * Supports the SampleProvider interface.
* The sensor measures the angular velocity in degrees per second. * A positive rate indicates a counterclockwise rotation. A negative rate indicates a clockwise rotation. * * @param port the Analog port */ public HiTechnicGyro(AnalogPort port) { super(port); init(); } /** * Supports the SampleProvider interface.
* The sensor measures the angular velocity in degrees per second. * A positive rate indicates a counterclockwise rotation. A negative rate indicates a clockwise rotation. * * @param port the Sensor port */ public HiTechnicGyro(Port port) { super(port); init(); } protected void init() { setModes(new SensorMode[]{ new RateMode() }); port.setTypeAndMode(TYPE_CUSTOM, MODE_RAW); } /** * HiTechnic Gyro sensor, Rate mode
* The Rate mode measures the angular speed of the sensor over three axes * *

* Size and content of the sample
* The sample contains one element giving the angular speed (in degrees/second) of the sensor over its vertical axis (Z-axis). * *

* */ public SensorMode getRateMode() { return getMode(0); } private class RateMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { sample[offset] = ((float) NXTRawValue(port.getPin1()) - zero) * TO_SI; } @Override public String getName() { return "Rate"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy