Announcement

Collapse
No announcement yet.

Weird problem with autonomous...

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

  • Weird problem with autonomous...

    I was having a problem with our autonomous program and I was wondering if you might be able to help. The program is below. What it does is the robot drives the first encoder set and then stops. When it stops, it sets a flag variable to 1. Then, it starts the next if loop. However, it does the thread.sleep(1000); command but not the resetting encoders or moving. In fact, after the thread.sleep, it jumps all the way down to the bottom of the program, ignoring all the code including the second thread.sleep command but still writes the flag variable to 3... Can you see what I'm doing wrong? ;-) Thanks
    ================================================== ================================================== =====
    package com.qualcomm.ftcrobotcontroller.opmodes;

    import com.qualcomm.robotcore.eventloop.opmode.OpMode;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.hardware.DcMotorController. RunMode;
    import com.qualcomm.robotcore.hardware.Servo;
    import com.qualcomm.robotcore.util.Range;

    public class Autonomous1_4_16multistep extends OpMode
    {
    final static double ARM_MIN_RANGE = 0.0;
    final static double ARM_MAX_RANGE = 1.0;
    final static double LEFT_FLIPPER_MAX_RANGE = 1.0;
    final static double LEFT_FLIPPER_MIN_RANGE = 0.0;
    final static double RIGHT_FLIPPER_MAX_RANGE = 1.0;
    final static double RIGHT_FLIPPER_MIN_RANGE = 0.0;
    final static double SHOULDER_MAX_RANGE = 1.0;
    final static double SHOULDER_MIN_RANGE = 0.0;
    final static double ELBOW_MAX_RANGE = 1.0;
    final static double ELBOW_MIN_RANGE = 0.0;
    final static double SPIN_MIN_RANGE = 0.20;
    final static double SPIN_MAX_RANGE = 0.55;
    final static double GRABBER_MIN_RANGE = 0.0;
    final static double GRABBER_MAX_RANGE = 1.0;
    double armPosition; // arm = climber bucket
    double leftFlipperposition;
    double rightFlipperposition;

    // amount to change the arm servo+ position. 1 = 180deg rotation.
    double armDelta = 1.0;
    double shoulderPosition=0.54;
    double elbowPosition=0.99;
    double spinPosition=0.23;
    double grabberPosition=1.00;
    int flag=0;

    // Initialize motors. (DcMotor is an FTC class.)

    DcMotor backRight;
    DcMotor backLeft;
    DcMotor frontLeft;
    DcMotor frontRight;
    //servo for climber bucket dumper
    Servo leftFlipper; //debris pushers
    Servo rightFlipper;
    Servo shoulder;
    Servo elbow;
    Servo spin;
    Servo grabber;

    int counts=10121;
    /* * Construct the class.
    * <p>
    * The system calls this member when the class is instantiated.
    */
    public Autonomous1_4_16multistep()

    {
    // This would be an autonomous method. Not used for now.
    }

    @Override
    public void init()
    /**
    * Perform any actions that are necessary when the OpMode is enabled.
    * The system calls this member once when the OpMode is enabled.
    */

    {
    backRight = hardwareMap.dcMotor.get("backRight");
    backLeft = hardwareMap.dcMotor.get("backLeft");
    frontRight = hardwareMap.dcMotor.get("frontRight");
    frontLeft = hardwareMap.dcMotor.get("frontLeft");

    backLeft.setDirection(DcMotor.Direction.FORWARD); //setting the motors on the left to be reversed so positive power makes them turn backward.
    frontLeft.setDirection(DcMotor.Direction.FORWARD);
    backRight.setDirection(DcMotor.Direction.REVERSE);
    frontRight.setDirection(DcMotor.Direction.REVERSE) ;

    rightFlipper=hardwareMap.servo.get("rightFlipper") ;
    leftFlipper=hardwareMap.servo.get("leftFlipper");
    shoulder = hardwareMap.servo.get("shoulder");
    elbow = hardwareMap.servo.get("elbow");
    spin = hardwareMap.servo.get("spin");
    grabber = hardwareMap.servo.get("grabber");
    rightFlipperposition = 0.0; //setting the debri pusher servos to hold their current position
    leftFlipperposition=0.6;

    backRight.setChannelMode(RunMode.RUN_USING_ENCODER S);
    frontRight.setChannelMode(RunMode.RUN_USING_ENCODE RS);
    backLeft.setChannelMode(RunMode.RUN_USING_ENCODERS );
    frontLeft.setChannelMode(RunMode.RUN_USING_ENCODER S);

    backRight.setChannelMode(RunMode.RESET_ENCODERS);
    frontRight.setChannelMode(RunMode.RESET_ENCODERS);
    backLeft.setChannelMode(RunMode.RESET_ENCODERS);
    frontLeft.setChannelMode(RunMode.RESET_ENCODERS);

    }

    @Override
    public void start() // The system calls this member once while the OpMode is running.
    {
    frontRight.setChannelMode(RunMode.RUN_TO_POSITION) ;
    backRight.setChannelMode(RunMode.RUN_TO_POSITION);
    frontLeft.setChannelMode(RunMode.RUN_TO_POSITION);
    backLeft.setChannelMode(RunMode.RUN_TO_POSITION);
    }
    @Override
    public void loop() // The system calls this member repeatedly while the OpMode is running.
    {
    if (flag==0) {
    backLeft.setTargetPosition(counts);
    backRight.setTargetPosition(counts);
    frontLeft.setTargetPosition(counts);
    frontRight.setTargetPosition(counts);

    backRight.setPower(.25);
    frontRight.setPower(.25);
    backLeft.setPower(.25);
    frontLeft.setPower(.25);

    if (backRight.getCurrentPosition() > 10115) {

    backRight.setPower(0);
    frontRight.setPower(0);
    backLeft.setPower(0);
    frontLeft.setPower(0);
    flag=1;
    }
    }
    if (flag==1){
    try {
    Thread.sleep(1000); //1000 milliseconds is one second.
    } catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
    }
    backRight.setChannelMode(RunMode.RESET_ENCODERS);
    frontRight.setChannelMode(RunMode.RESET_ENCODERS);
    backLeft.setChannelMode(RunMode.RESET_ENCODERS);
    frontLeft.setChannelMode(RunMode.RESET_ENCODERS);

    frontRight.setChannelMode(RunMode.RUN_TO_POSITION) ;
    backRight.setChannelMode(RunMode.RUN_TO_POSITION);
    frontLeft.setChannelMode(RunMode.RUN_TO_POSITION);
    backLeft.setChannelMode(RunMode.RUN_TO_POSITION);

    backLeft.setTargetPosition(4000);
    backRight.setTargetPosition(-4000);
    frontLeft.setTargetPosition(4000);
    frontRight.setTargetPosition(-4000);

    backRight.setPower(.25);
    frontRight.setPower(.25);
    backLeft.setPower(.25);
    frontLeft.setPower(.25);

    if (backRight.getCurrentPosition() > 3995) {
    backRight.setPower(0);
    frontRight.setPower(0);
    backLeft.setPower(0);
    frontLeft.setPower(0);
    flag=2;
    }
    }

    if (flag==2){

    try {
    Thread.sleep(1000); //1000 milliseconds is one second.
    } catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
    }

    backRight.setChannelMode(RunMode.RESET_ENCODERS);
    frontRight.setChannelMode(RunMode.RESET_ENCODERS);
    backLeft.setChannelMode(RunMode.RESET_ENCODERS);
    frontLeft.setChannelMode(RunMode.RESET_ENCODERS);

    frontRight.setChannelMode(RunMode.RUN_TO_POSITION) ;
    backRight.setChannelMode(RunMode.RUN_TO_POSITION);
    frontLeft.setChannelMode(RunMode.RUN_TO_POSITION);
    backLeft.setChannelMode(RunMode.RUN_TO_POSITION);

    backLeft.setTargetPosition(4000);
    backRight.setTargetPosition(4000);
    frontLeft.setTargetPosition(4000);
    frontRight.setTargetPosition(4000);

    backRight.setPower(.25);
    frontRight.setPower(.25);
    backLeft.setPower(.25);
    frontLeft.setPower(.25);

    if (backRight.getCurrentPosition() > 3995)
    {
    backRight.setPower(0);
    frontRight.setPower(0);
    backLeft.setPower(0);
    frontLeft.setPower(0);
    flag=3;
    }
    }

    armPosition = Range.clip(armPosition, ARM_MIN_RANGE, ARM_MAX_RANGE);
    rightFlipperposition=Range.clip(rightFlipperpositi on, RIGHT_FLIPPER_MIN_RANGE, RIGHT_FLIPPER_MAX_RANGE);
    leftFlipperposition=Range.clip(leftFlipperposition , LEFT_FLIPPER_MIN_RANGE, LEFT_FLIPPER_MAX_RANGE);
    spinPosition = Range.clip(spinPosition, SPIN_MIN_RANGE, SPIN_MAX_RANGE);
    shoulderPosition = Range.clip(shoulderPosition, SHOULDER_MIN_RANGE, SHOULDER_MAX_RANGE);
    elbowPosition=Range.clip(elbowPosition, ELBOW_MIN_RANGE, ELBOW_MAX_RANGE);
    grabberPosition=Range.clip(grabberPosition, GRABBER_MIN_RANGE, GRABBER_MAX_RANGE);


    rightFlipper.setPosition(rightFlipperposition);
    leftFlipper.setPosition(leftFlipperposition);
    shoulder.setPosition(shoulderPosition);
    spin.setPosition(spinPosition);
    elbow.setPosition(elbowPosition);
    grabber.setPosition(grabberPosition);

    telemetry.addData("Back Right ", String.format("number: " + backRight.getCurrentPosition()));
    telemetry.addData("Back Left ", String.format("number: " + backLeft.getCurrentPosition()));
    telemetry.addData("Front Right ", String.format("number: " + frontRight.getCurrentPosition()));
    telemetry.addData("Front Left ", String.format("number: " + frontLeft.getCurrentPosition()));
    telemetry.addData("Flag variable ", String.format("is: " + flag));
    }
    }

  • #2
    Please put this in the Android Studio Thread
    Captain and Lead Programmer of team 10083 Something Weird, AKA Mars Robotics

    Comment


    • #3
      Hi FTC8668,

      I moved your thread to the Android Studio forum.

      Tom

      Comment

      Working...
      X