Announcement

Collapse
No announcement yet.

OpMode Stuck in Stop() error when attempting stop

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

  • OpMode Stuck in Stop() error when attempting stop

    Hello Teams,
    We have recently been attempting to create the parking portion of the autonomous. For this task, we are using 2 color sensors (One in front, one in back. The one in front is a REV Color Distance Sensor, and the one in back is a REV Color Sensor V2) and we are checking the hue value. The code appears to be working perfectly fine, but as soon as we try to press the stop button, we get the error, OpMode Stuck in Stop(). It was previously not doing this, but as soon as we added the color sensor logic, we get the error when stopping. We have read other posts on the forum, but to no avail. We do not get the error when the Autonomous runs out the time limit. Thank you very much for your help! Here is our code:

    Code:
     
    // Defines where the code is in the project
    package org.firstinspires.ftc.teamcode.Test.Auto_Tests;
    // Imports for the code
    import android.graphics.Color;
    import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
    import com.qualcomm.robotcore.hardware.ColorSensor;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
    import com.qualcomm.robotcore.hardware.DistanceSensor;
    // Defines the codes name
    @Autonomous(name = "Parking_Test", group= "Auto_Tests")
    public class Parking_Test extends LinearOpMode{
    // Robot definitions
    public DcMotor motorFrontRight;
    public DcMotor motorFrontLeft;
    public DcMotor motorBackRight;
    public DcMotor motorBackLeft;
    ColorSensor sensorColor;
    ColorSensor color2;
    DistanceSensor sensorDistance;
    double step = 0;
    @Override
    public void runOpMode(){
    // Drive train initialization
    motorFrontRight = hardwareMap.dcMotor.get("FR");
    motorFrontLeft = hardwareMap.dcMotor.get("FL");
    motorBackLeft = hardwareMap.dcMotor.get("BL");
    motorBackRight = hardwareMap.dcMotor.get("BR");
    motorFrontLeft.setDirection(DcMotor.Direction.FORWARD);
    motorFrontRight.setDirection(DcMotor.Direction.REVERSE);
    motorBackLeft.setDirection(DcMotor.Direction.FORWARD);
    motorBackRight.setDirection(DcMotor.Direction.REVERSE);
    // Color sensor initialization
    sensorColor = hardwareMap.get(ColorSensor.class, "color_sensor");
    color2 = hardwareMap.get(ColorSensor.class, "color2");
    sensorDistance = hardwareMap.get(DistanceSensor.class, "color_sensor");
    // Color Sensor Values
    // "hsvValues" is an array that will hold the hue, saturation, and value information
    float hsvValues[] = {0F, 0F, 0F};
    // "values" is a reference to the hsvValues array
    final float values[] = hsvValues;
    // Sometimes it helps to multiply the raw RGB values with a scale factor
    // to amplify/attenuate the measured values.
    final double SCALE_FACTOR = 255;
    telemetry.addData("Status: ", "Initialized");
    telemetry.addData(">", "Press Play to start op mode");
    telemetry.update();
    waitForStart();
    while (opModeIsActive()){
    // Color Sensor Code
    // Convert the RGB values to HSV values.
    // Multiply by the SCALE_FACTOR.
    // Cast it back to int (SCALE_FACTOR is a double)
    Color.RGBToHSV((int) (color2.red() * SCALE_FACTOR),
    (int) (color2.green() * SCALE_FACTOR),
    (int) (color2.blue() * SCALE_FACTOR),
    hsvValues);
    Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR),
    (int) (sensorColor.green() * SCALE_FACTOR),
    (int) (sensorColor.blue() * SCALE_FACTOR),
    hsvValues);
    // Send the info back to driver station using telemetry function.
    telemetry.addData("Step: ", step);
    telemetry.addData("Hue", hsvValues[0]);
    telemetry.update();
    // Move forward
    if (step == 0){
    motorFrontRight.setPower(.2);
    motorFrontLeft.setPower(.2);
    motorBackLeft.setPower(.2);
    motorBackRight.setPower(.2);
    }
    // Does it see the line?
    while (step == 0){
    if (opModeIsActive()){
    Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR),
    (int) (sensorColor.green() * SCALE_FACTOR),
    (int) (sensorColor.blue() * SCALE_FACTOR),
    hsvValues);
    Color.RGBToHSV((int) (color2.red() * SCALE_FACTOR),
    (int) (color2.green() * SCALE_FACTOR),
    (int) (color2.blue() * SCALE_FACTOR),
    hsvValues);
    // Send the info back to driver station using telemetry function.
    telemetry.addData("Step: ", step);
    telemetry.addData("Hue", hsvValues[0]);
    telemetry.update();
    }
    //
    if (hsvValues[0] > 150 ){ // Checks if it is red or blue
    step++;
    }
    }
    if (step == 1){
    motorFrontRight.setPower(0);
    motorFrontLeft.setPower(0);
    motorBackLeft.setPower(0);
    motorBackRight.setPower(0);
    step++;
    }
    if (step == 2){
    motorFrontRight.setPower(-.5);
    motorFrontLeft.setPower(-.5);
    motorBackLeft.setPower(-.5);
    motorBackRight.setPower(-.5);
    sleep(200);
    step++;
    }
    if (step == 3){
    motorFrontRight.setPower(0);
    motorFrontLeft.setPower(0);
    motorBackLeft.setPower(0);
    motorBackRight.setPower(0);
    }
    }
    }
    }

  • #2
    while (step == 0) {
    if (opModeIsActive)

    opModeIsActive does not stop your program, it is just a boolean. Your code stays in the step zero while loop even if opMode is not active.

    while (step == 0 && opModeIsActive) jumps out of loop and lets your program terminate.


    Javadoc -

    If the opMode is not active, the OpMode should terminate at its earliest convenience.

    Comment


    • #3
      More on what 3805Mentor said -- ALL loops (while, for, etc) in linearOpModes need to have an opModeIsActive int their conditional check (or in each possible branch within). That will allow the flow to break out of the loop when opModeIsActive is false.

      Comment


      • #4
        For code like this, why use linearOpMode? It seems like this code would work better if it was derived from OpMode.

        Comment

        Working...
        X