Search in sources :

Example 1 with MagneticFlux

use of org.firstinspires.ftc.robotcore.external.navigation.MagneticFlux in project robotcode by OutoftheBoxFTC.

the class ModernRoboticsI2cCompassSensor method getMagneticFlux.

public MagneticFlux getMagneticFlux() {
    // Capture all the data at once so as to get them all from one read
    TimestampedData ts = this.deviceClient.readTimeStamped(Register.MAGX.bVal, 3 * 2);
    ByteBuffer buffer = ByteBuffer.wrap(ts.data).order(ByteOrder.LITTLE_ENDIAN);
    // units are in Gauss. One Tesla is 10,000 Gauss.
    int magX = (buffer.getShort());
    int magY = (buffer.getShort());
    int magZ = (buffer.getShort());
    double scale = 0.0001;
    return new MagneticFlux(magX * scale, magY * scale, magZ * scale, ts.nanoTime);
}
Also used : TimestampedData(com.qualcomm.robotcore.hardware.TimestampedData) MagneticFlux(org.firstinspires.ftc.robotcore.external.navigation.MagneticFlux) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TimestampedData (com.qualcomm.robotcore.hardware.TimestampedData)1 ByteBuffer (java.nio.ByteBuffer)1 MagneticFlux (org.firstinspires.ftc.robotcore.external.navigation.MagneticFlux)1