Announcement

Collapse
No announcement yet.

Touch Gyro sensor HELP NEEDED

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Touch Gyro sensor HELP NEEDED

    beginner with coding not sure what is wrong with this code getting lots of red everywhere pls help and guide to make this code work for a
    gyro sensor

    package com.qualcomm.ftcrobotcontroller.opmodes.Op;
    import com.qualcomm.hardware.modernrobotics.ModernRobotic sI2cGyro;
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
    import com.qualcomm.robotcore.eventloop.opmode.OpMode;
    import com.qualcomm.robotcore.hardware.GyroSensor;

    /**
    *
    public class gyroTest extends LinearOpMode {

    @Override
    public void runOpMode() throws InterruptedException; {

    int zAccumulated; //Total rotation left/right
    int heading; //Heading left/right. Integer between 0 and 359
    int xVal, yVal, zVal; //Momentary rate of rotation

    GyroSensor sensorGyro; //General Gyro Sensor allows us to point to the sensor in the configuration file.
    ModernRoboticsI2cGyro mrGyro;

    sensorGyro = hardwareMap.gyroSensor.get("gyro"); //Point to the gyro in the configuration file
    mrGyro = (ModernRoboticsI2cGyro) sensorGyro; //ModernRoboticsI2cGyro allows us to .getIntegratedZValue()

    mrGyro.calibrate(); //Calibrate the sensor so it knows where 0 is and what still is. DO NOT MOVE SENSOR WHILE BLUE LIGHT IS SOLID

    waitForStart(); //Wait for play button to be pressed

    while (mrGyro.isCalibrating()) { //Ensure calibration is complete (usually 2 seconds)
    }

    while (opModeIsActive()) {

    zAccumulated = mrGyro.getIntegratedZValue(); //Set variables to gyro readings

    heading = 360 - mrGyro.getHeading(); //Reverse direction of headding to match the integrated value
    if (heading == 360) {
    heading = 0;
    }

    xVal = mrGyro.rawX() / 128;
    yVal = mrGyro.rawY() / 128;
    zVal = mrGyro.rawZ() / 128;

    telemetry.addData("1. headding", String.format("%03d", heading)); //Display variables to Driver Station Screen
    telemetry.addData("2. accu", String.format("%03d", zAccumulated));
    telemetry.addData("3. X", String.format("%03d", xVal));
    telemetry.addData("4. Y", String.format("%03d", yVal));
    telemetry.addData("5. Z", String.format("%03d", zVal));

    waitOneFullHardwareCycle();
    }

    }
    }

  • #2
    You have spaces in your import statements...

    Comment


    • #3
      Didn't look through the entire program but the first thing caught my eyes is:
      Code:
      @Override
         public void runOpMode() throws InterruptedException; {
      You have a semi-colon after InterruptedException. That's an error, please remove it.

      Comment


      • #4
        Originally posted by KinaK View Post
        beginner with coding not sure what is wrong with this code getting lots of red everywhere pls help and guide to make this code work for a
        gyro sensor
        If you are a beginner, you should try using one of the code samples that are part of the SDK.

        In particular, there is an almost identical MR Gyro sample to the one you are using, except the one that is in the SDK is up-to-date based on the latest DSK changes (eg: waitOneFullHardwareCycle() is not needed.

        Check out the following tutorial on how to use the samples in the SDK.

        https://www.youtube.com/playlist?lis...1FeqeqW1_pnzE2

        (In all cases you just copy the sample from the external/samples folder to your TeamCode folder.) and comment out the @Disabled line.

        Comment

        Working...
        X