Search in sources :

Example 1 with AngularVelocity

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

the class ModernRoboticsI2cGyro method getAngularVelocity.

@Override
public AngularVelocity getAngularVelocity(AngleUnit unit) {
    TimestampedData data = this.deviceClient.readTimeStamped(Register.RAW_X_VAL.bVal, 3 * 2);
    int rawX = TypeConversion.byteArrayToShort(data.data, 0, ByteOrder.LITTLE_ENDIAN);
    int rawY = TypeConversion.byteArrayToShort(data.data, 2, ByteOrder.LITTLE_ENDIAN);
    int rawZ = TypeConversion.byteArrayToShort(data.data, 4, ByteOrder.LITTLE_ENDIAN);
    float degPerSecondX = rawX * degreesPerSecondPerDigit;
    float degPerSecondY = rawY * degreesPerSecondPerDigit;
    float degPerSecondZ = rawZ * degreesPerSecondPerDigit;
    return new AngularVelocity(AngleUnit.DEGREES, degPerSecondX, degPerSecondY, degPerSecondZ, data.nanoTime).toAngleUnit(unit);
}
Also used : TimestampedData(com.qualcomm.robotcore.hardware.TimestampedData) AngularVelocity(org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity)

Example 2 with AngularVelocity

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

the class SensorKLNavxMicro method runOpMode.

@Override
public void runOpMode() throws InterruptedException {
    // Get a reference to a Modern Robotics GyroSensor object. We use several interfaces
    // on this object to illustrate which interfaces support which functionality.
    navxMicro = hardwareMap.get(NavxMicroNavigationSensor.class, "navx");
    gyro = (IntegratingGyroscope) navxMicro;
    // If you're only interested int the IntegratingGyroscope interface, the following will suffice.
    // gyro = hardwareMap.get(IntegratingGyroscope.class, "navx");
    // The gyro automatically starts calibrating. This takes a few seconds.
    telemetry.log().add("Gyro Calibrating. Do Not Move!");
    // Wait until the gyro calibration is complete
    timer.reset();
    while (navxMicro.isCalibrating()) {
        telemetry.addData("calibrating", "%s", Math.round(timer.seconds()) % 2 == 0 ? "|.." : "..|");
        telemetry.update();
        Thread.sleep(50);
    }
    telemetry.log().clear();
    telemetry.log().add("Gyro Calibrated. Press Start.");
    telemetry.clear();
    telemetry.update();
    // Wait for the start button to be pressed
    waitForStart();
    telemetry.log().clear();
    while (opModeIsActive()) {
        // Read dimensionalized data from the gyro. This gyro can report angular velocities
        // about all three axes. Additionally, it internally integrates the Z axis to
        // be able to report an absolute angular Z orientation.
        AngularVelocity rates = gyro.getAngularVelocity(AngleUnit.DEGREES);
        Orientation angles = gyro.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
        telemetry.addLine().addData("dx", formatRate(rates.xRotationRate)).addData("dy", formatRate(rates.yRotationRate)).addData("dz", "%s deg/s", formatRate(rates.zRotationRate));
        telemetry.addLine().addData("heading", formatAngle(angles.angleUnit, angles.firstAngle)).addData("roll", formatAngle(angles.angleUnit, angles.secondAngle)).addData("pitch", "%s deg", formatAngle(angles.angleUnit, angles.thirdAngle));
        telemetry.update();
        // Always call idle() at the bottom of your while(opModeIsActive()) loop
        idle();
    }
}
Also used : NavxMicroNavigationSensor(com.qualcomm.hardware.kauailabs.NavxMicroNavigationSensor) AngularVelocity(org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity) Orientation(org.firstinspires.ftc.robotcore.external.navigation.Orientation)

Example 3 with AngularVelocity

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

the class NavxMicroNavigationSensor method getAngularVelocity.

@Override
public AngularVelocity getAngularVelocity(AngleUnit unit) {
    TimestampedData data = this.deviceClient.readTimeStamped(Register.GYRO_X_L.bVal, 3 * 2);
    float xDegPerSec = TypeConversion.byteArrayToShort(data.data, 0, ByteOrder.LITTLE_ENDIAN) * gyroScaleFactor;
    float yDegPerSec = TypeConversion.byteArrayToShort(data.data, 2, ByteOrder.LITTLE_ENDIAN) * gyroScaleFactor;
    float zDegPerSec = TypeConversion.byteArrayToShort(data.data, 4, ByteOrder.LITTLE_ENDIAN) * gyroScaleFactor;
    return new AngularVelocity(AngleUnit.DEGREES, xDegPerSec, yDegPerSec, zDegPerSec, data.nanoTime).toAngleUnit(unit);
}
Also used : TimestampedData(com.qualcomm.robotcore.hardware.TimestampedData) AngularVelocity(org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity)

Example 4 with AngularVelocity

use of org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity in project FTC-2017 by FIRST-4030.

the class SensorKLNavxMicro method runOpMode.

@Override
public void runOpMode() throws InterruptedException {
    // Get a reference to a Modern Robotics GyroSensor object. We use several interfaces
    // on this object to illustrate which interfaces support which functionality.
    navxMicro = hardwareMap.get(NavxMicroNavigationSensor.class, "navx");
    gyro = (IntegratingGyroscope) navxMicro;
    // If you're only interested int the IntegratingGyroscope interface, the following will suffice.
    // gyro = hardwareMap.get(IntegratingGyroscope.class, "navx");
    // The gyro automatically starts calibrating. This takes a few seconds.
    telemetry.log().add("Gyro Calibrating. Do Not Move!");
    // Wait until the gyro calibration is complete
    timer.reset();
    while (navxMicro.isCalibrating()) {
        telemetry.addData("calibrating", "%s", Math.round(timer.seconds()) % 2 == 0 ? "|.." : "..|");
        telemetry.update();
        Thread.sleep(50);
    }
    telemetry.log().clear();
    telemetry.log().add("Gyro Calibrated. Press Start.");
    telemetry.clear();
    telemetry.update();
    // Wait for the start button to be pressed
    waitForStart();
    telemetry.log().clear();
    while (opModeIsActive()) {
        // Read dimensionalized data from the gyro. This gyro can report angular velocities
        // about all three axes. Additionally, it internally integrates the Z axis to
        // be able to report an absolute angular Z orientation.
        AngularVelocity rates = gyro.getAngularVelocity(AngleUnit.DEGREES);
        Orientation angles = gyro.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
        telemetry.addLine().addData("dx", formatRate(rates.xRotationRate)).addData("dy", formatRate(rates.yRotationRate)).addData("dz", "%s deg/s", formatRate(rates.zRotationRate));
        telemetry.addLine().addData("heading", formatAngle(angles.angleUnit, angles.firstAngle)).addData("roll", formatAngle(angles.angleUnit, angles.secondAngle)).addData("pitch", "%s deg", formatAngle(angles.angleUnit, angles.thirdAngle));
        telemetry.update();
        // Always call idle() at the bottom of your while(opModeIsActive()) loop
        idle();
    }
}
Also used : NavxMicroNavigationSensor(com.qualcomm.hardware.kauailabs.NavxMicroNavigationSensor) AngularVelocity(org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity) Orientation(org.firstinspires.ftc.robotcore.external.navigation.Orientation)

Example 5 with AngularVelocity

use of org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity in project Relic_Main by TeamOverdrive.

the class SensorMRGyro method runOpMode.

@Override
public void runOpMode() {
    boolean lastResetState = false;
    boolean curResetState = false;
    // Get a reference to a Modern Robotics gyro object. We use several interfaces
    // on this object to illustrate which interfaces support which functionality.
    modernRoboticsI2cGyro = hardwareMap.get(ModernRoboticsI2cGyro.class, "gyro");
    gyro = (IntegratingGyroscope) modernRoboticsI2cGyro;
    // If you're only interested int the IntegratingGyroscope interface, the following will suffice.
    // gyro = hardwareMap.get(IntegratingGyroscope.class, "gyro");
    // A similar approach will work for the Gyroscope interface, if that's all you need.
    // Start calibrating the gyro. This takes a few seconds and is worth performing
    // during the initialization phase at the start of each opMode.
    telemetry.log().add("Gyro Calibrating. Do Not Move!");
    modernRoboticsI2cGyro.calibrate();
    // Wait until the gyro calibration is complete
    timer.reset();
    while (!isStopRequested() && modernRoboticsI2cGyro.isCalibrating()) {
        telemetry.addData("calibrating", "%s", Math.round(timer.seconds()) % 2 == 0 ? "|.." : "..|");
        telemetry.update();
        sleep(50);
    }
    telemetry.log().clear();
    telemetry.log().add("Gyro Calibrated. Press Start.");
    telemetry.clear();
    telemetry.update();
    // Wait for the start button to be pressed
    waitForStart();
    telemetry.log().clear();
    telemetry.log().add("Press A & B to reset heading");
    // Loop until we're asked to stop
    while (opModeIsActive()) {
        // If the A and B buttons are pressed just now, reset Z heading.
        curResetState = (gamepad1.a && gamepad1.b);
        if (curResetState && !lastResetState) {
            modernRoboticsI2cGyro.resetZAxisIntegrator();
        }
        lastResetState = curResetState;
        // The raw() methods report the angular rate of change about each of the
        // three axes directly as reported by the underlying sensor IC.
        int rawX = modernRoboticsI2cGyro.rawX();
        int rawY = modernRoboticsI2cGyro.rawY();
        int rawZ = modernRoboticsI2cGyro.rawZ();
        int heading = modernRoboticsI2cGyro.getHeading();
        int integratedZ = modernRoboticsI2cGyro.getIntegratedZValue();
        // Read dimensionalized data from the gyro. This gyro can report angular velocities
        // about all three axes. Additionally, it internally integrates the Z axis to
        // be able to report an absolute angular Z orientation.
        AngularVelocity rates = gyro.getAngularVelocity(AngleUnit.DEGREES);
        float zAngle = gyro.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES).firstAngle;
        // Read administrative information from the gyro
        int zAxisOffset = modernRoboticsI2cGyro.getZAxisOffset();
        int zAxisScalingCoefficient = modernRoboticsI2cGyro.getZAxisScalingCoefficient();
        telemetry.addLine().addData("dx", formatRate(rates.xRotationRate)).addData("dy", formatRate(rates.yRotationRate)).addData("dz", "%s deg/s", formatRate(rates.zRotationRate));
        telemetry.addData("angle", "%s deg", formatFloat(zAngle));
        telemetry.addData("heading", "%3d deg", heading);
        telemetry.addData("integrated Z", "%3d", integratedZ);
        telemetry.addLine().addData("rawX", formatRaw(rawX)).addData("rawY", formatRaw(rawY)).addData("rawZ", formatRaw(rawZ));
        telemetry.addLine().addData("z offset", zAxisOffset).addData("z coeff", zAxisScalingCoefficient);
        telemetry.update();
    }
}
Also used : ModernRoboticsI2cGyro(com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro) AngularVelocity(org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity)

Aggregations

AngularVelocity (org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity)9 NavxMicroNavigationSensor (com.qualcomm.hardware.kauailabs.NavxMicroNavigationSensor)3 ModernRoboticsI2cGyro (com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro)3 Orientation (org.firstinspires.ftc.robotcore.external.navigation.Orientation)3 TimestampedData (com.qualcomm.robotcore.hardware.TimestampedData)2