Search in sources :

Example 6 with TimestampedData

use of com.qualcomm.robotcore.hardware.TimestampedData in project robotcode by OutoftheBoxFTC.

the class NavxMicroNavigationSensor method getAngularOrientation.

@Override
public Orientation getAngularOrientation(AxesReference reference, AxesOrder order, org.firstinspires.ftc.robotcore.external.navigation.AngleUnit angleUnit) {
    TimestampedData data = this.deviceClient.readTimeStamped(Register.YAW_L.bVal, 3 * 2);
    // 
    float zDegrees = -shortToSignedHundredths(TypeConversion.byteArrayToShort(data.data, 0, ByteOrder.LITTLE_ENDIAN));
    float yDegrees = shortToSignedHundredths(TypeConversion.byteArrayToShort(data.data, 2, ByteOrder.LITTLE_ENDIAN));
    float xDegrees = shortToSignedHundredths(TypeConversion.byteArrayToShort(data.data, 4, ByteOrder.LITTLE_ENDIAN));
    // 
    return new Orientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES, zDegrees, yDegrees, xDegrees, data.nanoTime).toAxesReference(reference).toAxesOrder(order).toAngleUnit(angleUnit);
}
Also used : TimestampedData(com.qualcomm.robotcore.hardware.TimestampedData) Orientation(org.firstinspires.ftc.robotcore.external.navigation.Orientation)

Example 7 with TimestampedData

use of com.qualcomm.robotcore.hardware.TimestampedData 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)

Example 8 with TimestampedData

use of com.qualcomm.robotcore.hardware.TimestampedData in project robotcode by OutoftheBoxFTC.

the class ModernRoboticsI2cCompassSensor method getAcceleration.

// ----------------------------------------------------------------------------------------------
// CompassSensor
// ----------------------------------------------------------------------------------------------
public Acceleration getAcceleration() {
    // Capture all the data at once so as to get them all from one read
    TimestampedData ts = this.deviceClient.readTimeStamped(Register.ACCELX.bVal, 3 * 2);
    ByteBuffer buffer = ByteBuffer.wrap(ts.data).order(ByteOrder.LITTLE_ENDIAN);
    // units are milli-earth's-gravity
    int mgX = (buffer.getShort());
    int mgY = (buffer.getShort());
    int mgZ = (buffer.getShort());
    double scale = 0.001;
    return Acceleration.fromGravity(mgX * scale, mgY * scale, mgZ * scale, ts.nanoTime);
}
Also used : TimestampedData(com.qualcomm.robotcore.hardware.TimestampedData) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TimestampedData (com.qualcomm.robotcore.hardware.TimestampedData)8 ByteBuffer (java.nio.ByteBuffer)2 AngularVelocity (org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity)2 Orientation (org.firstinspires.ftc.robotcore.external.navigation.Orientation)2 LynxCommand (com.qualcomm.hardware.lynx.commands.LynxCommand)1 LynxI2cWriteReadMultipleBytesCommand (com.qualcomm.hardware.lynx.commands.core.LynxI2cWriteReadMultipleBytesCommand)1 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1 I2cDeviceSynch (com.qualcomm.robotcore.hardware.I2cDeviceSynch)1 MagneticFlux (org.firstinspires.ftc.robotcore.external.navigation.MagneticFlux)1 Quaternion (org.firstinspires.ftc.robotcore.external.navigation.Quaternion)1