Search in sources :

Example 1 with ModernRoboticsI2cGyro

use of com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro 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)

Example 2 with ModernRoboticsI2cGyro

use of com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro in project robotcode by OutoftheBoxFTC.

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)

Example 3 with ModernRoboticsI2cGyro

use of com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro in project FTC-2017 by FIRST-4030.

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

ModernRoboticsI2cGyro (com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro)3 AngularVelocity (org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity)3