// getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made.
@Override
    public void runOpMode() {
        telemetry.addData("Status", "Initialized");
        telemetry.update();
        left_mtr = hardwareMap.dcMotor.get("left_mtr");
        right_mtr = hardwareMap.dcMotor.get("right_mtr");
        front_left_mtr = hardwareMap.dcMotor.get("front_left_mtr");
        front_right_mtr = hardwareMap.dcMotor.get("front_right_mtr");
        Shooter = hardwareMap.dcMotor.get("Shooter");
        Conveyor = hardwareMap.dcMotor.get("Conveyor");
        clow_moter = hardwareMap.dcMotor.get("clow moter");
        Claw = hardwareMap.servo.get("Claw");
        touchfront = hardwareMap.touchSensor.get("touchfront");
        touch2 = hardwareMap.touchSensor.get("touch2");
        // values is a reference to the hsvValues array.
        float[] hsvValues = new float[3];
        final float values[] = hsvValues;
        // bPrevState and bCurrState keep track of the previous and current state of the button
        boolean bPrevState = false;
        boolean bCurrState = false;
        String mode="";
        Claw.setPosition(0);
        right_mtr.setDirection(DcMotorSimple.Direction.REVERSE);
        right_mtr.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
        left_mtr.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
        front_right_mtr.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
        front_left_mtr.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
        clow_moter.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
        right_mtr.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
        left_mtr.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
        front_right_mtr.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
        front_left_mtr.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
        initVuforia();
        initTfod();
        /**
         * Activate TensorFlow Object Detection before we wait for the start command.
         * Do it here so that the Camera Stream window will have the TensorFlow annotations visible.
         **/
        if (tfod != null) {
            tfod.activate();
            // The TensorFlow software will scale the input images from the camera to a lower resolution.
            // This can result in lower detection accuracy at longer distances (> 55cm or 22").
            // If your target is at distance greater than 50 cm (20") you can adjust the magnification value
            // to artificially zoom in to the center of image.  For best results, the "aspectRatio" argument
            // should be set to the value of the images used to create the TensorFlow Object Detection model
            // (typically 1.78 or 16/9).
            // Uncomment the following line if you want to adjust the magnification and/or the aspect ratio of the input images.
            //tfod.setZoom(2.5, 1.78);
        }
        /** Wait for the game to begin */
        telemetry.addData(">", "Press Play to start op mode");
        telemetry.update();
        waitForStart();
        if (opModeIsActive()) {
            halt();
            sleep(1000);
            turnRight(0.5);
            haltSequence(450);
            goForward(.5);
            haltSequence(150);
            turnLeft(.5);
            haltSequence(450);
            goForward(0.4);
            sleep(450);
            halt();
            sleep(1000);
            telemetry.addData("Status", "Started");
            telemetry.update();
            if (tfod != null) {
                // getUpdatedRecognitions() will return null if no new information is available since
                // the last time that call was made.
                List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
                if (updatedRecognitions != null) {
                    telemetry.addData("# Object Detected", updatedRecognitions.size());
                    if (updatedRecognitions.size() == 0) {
                        mode = "A";
                    }
                    // step through the list of recognitions and display boundary info.
                    int i = 0;
                    for (Recognition recognition : updatedRecognitions) {
                        telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
                        if (recognition.getLabel() =="Quad"){
                            mode = "C";
                        } else {
                            mode = "B";
                        }
                        telemetry.addData(String.format("  left,top (%d)", i), "%.03f , %.03f",
                                recognition.getLeft(), recognition.getTop());
                        telemetry.addData(String.format("  right,bottom (%d)", i), "%.03f , %.03f",
                                recognition.getRight(), recognition.getBottom());
                    }
                    //telemetry.addData(String.format("Mode (%s)", mode), "");
                    telemetry.update();
                    sleep(2000);
                }
            }
        }
        // go somewhere based on mode
            if (mode == "A") {
                doModeA();
            } else if (mode == "B") {
                doModeB();
            } else if (mode == "C") {
                doModeC();
            } else {
                // not sure what to do here
            }
        if (tfod != null) {
             tfod.shutdown();
        }
    }
telemetry.update();
if (tfod != null) {
// getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made.
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
if (updatedRecognitions != null) {
haltSequence(150);
turnLeft(.5);
haltSequence(450);
goForward(0.4);
sleep(450);
halt();
sleep(1000);
telemetry.addData("Status", "Started");
telemetry.update();
if (tfod != null) {
// getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made.
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
if (updatedRecognitions != null) {
telemetry.addData("# Object Detected", updatedRecognitions.size());
if (updatedRecognitions.size() == 0) {
mode = "A";
}
// step through the list of recognitions and display boundary info.
int i = 0;
for (Recognition recognition : updatedRecognitions) {
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
/** Wait for the game to begin */
telemetry.addData(">", "Press Play to start op mode");
telemetry.update();
waitForStart();
if (opModeIsActive()) {
halt();
sleep(1000);
turnRight(0.5);
haltSequence(450);
goForward(.5);
haltSequence(150);
turnLeft(.5);
haltSequence(450);
goForward(0.4);
sleep(450);
halt();
sleep(1000);
telemetry.addData("Status", "Started");
telemetry.update();
if (tfod != null) {
// getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made.
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
if (updatedRecognitions != null) {
telemetry.addData("# Object Detected", updatedRecognitions.size());
if (updatedRecognitions.size() == 0) {
mode = "A";
}
// step through the list of recognitions and display boundary info.
int i = 0;
for (Recognition recognition : updatedRecognitions) {
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
if (recognition.getLabel() =="Quad"){
mode = "C";
} else {
mode = "B";
}
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
recognition.getLeft(), recognition.getTop());
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
recognition.getRight(), recognition.getBottom());
}