Announcement

Collapse
No announcement yet.

Motor switching directions at end of auto run

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

  • Motor switching directions at end of auto run

    I have a team with an unusual problem. At the end of their autonomous run, one of their motors will just switch directions. We have tried switching motors and power cables and encoder wires but it always happens. Could it be something in the REV board? The coding is the same for all four motors. we are really stumped at this point.

  • #2
    What programming method are you using? (ie. blocks, onbot jave, AS)

    Is your autonomous structured as linear or iterative opmode?

    Post the end of your code.

    FYI, if you are using linear opmode, you must set all motors to zero power and use the Stop and Reset encoder command for each motor at the end of the program. There appears to be a bug in the SDK that does random things at the end of a linear opmode if you don't do this.

    Comment


    • #3
      I will check with my programmer and get that info posted tomorrow.

      Comment


      • #4
        This is the linear program that is being used on onbotjava. It is supposed to make the robot strafe right. The two right motors are reporting spinning 600 ticks more than they are supposed to and the robot rotates slightly at the end. are there any errors in the code or is it the hardware.

        package org.firstinspires.ftc.teamcode;

        import com.qualcomm.robotcore.hardware.DcMotor;
        import java.lang.annotation.Target;
        import com.qualcomm.robotcore.hardware.DcMotorSimple;
        import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
        import com.qualcomm.robotcore.eventloop.opmode.Disabled;
        import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
        import com.qualcomm.robotcore.util.ElapsedTime;


        @Autonomous

        public class Strafe extends LinearOpMode {


        private ElapsedTime runtime = new ElapsedTime();

        DcMotor mLeft_1;//front left
        DcMotor mRight_1;//frint right
        DcMotor mLeft_2;//back left
        DcMotor mRight_2;//Back right

        static final double COUNTS_PER_MOTOR_REV = 1120;
        static final double DRIVE_GEAR_REDUCTION = 1.0;
        static final double WHEEL_DIAMETER_INCHES = 3;
        static final double COUNTS_PER_INCH =(COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION)/ (WHEEL_DIAMETER_INCHES * 3.1415);
        @Override

        public void runOpMode() {

        //init(hardwareMap);

        mLeft_1 = hardwareMap.dcMotor.get("mLeft_1");
        mLeft_1.setDirection(DcMotor.Direction.REVERSE);

        mRight_1 = hardwareMap.dcMotor.get("mRight_1");
        mRight_1.setDirection(DcMotor.Direction.FORWARD);

        mLeft_2 = hardwareMap.dcMotor.get("mLeft_2");
        mLeft_2.setDirection(DcMotor.Direction.REVERSE);

        mRight_2 = hardwareMap.dcMotor.get("mRight_2");
        mRight_2.setDirection(DcMotorSimple.Direction.FORW ARD);

        mLeft_1.setMode(DcMotor.RunMode.STOP_AND_RESET_ENC ODER);
        mLeft_2.setMode(DcMotor.RunMode.STOP_AND_RESET_ENC ODER);
        mRight_1.setMode(DcMotor.RunMode.STOP_AND_RESET_EN CODER);
        mRight_2.setMode(DcMotor.RunMode.STOP_AND_RESET_EN CODER);

        mLeft_1.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
        mLeft_2.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
        mRight_1.setMode(DcMotor.RunMode.RUN_USING_ENCODER );
        mRight_2.setMode(DcMotor.RunMode.RUN_USING_ENCODER );


        waitForStart();

        runtime.reset();

        while (opModeIsActive()){
        encoderDrive(1,-12, 12, 12, -12);
        sleep(2000000000);
        }
        }
        public void encoderDrive(double speed, double leftfrontInches,
        double leftbackInches, double rightfrontInches,
        double rightbackInches){

        int frontLeftTarget;
        int frontRightTarget;
        int backLeftTarget;
        int backRightTarget;

        if (opModeIsActive()) {

        frontLeftTarget = mLeft_1.getCurrentPosition() + (int)(leftfrontInches * COUNTS_PER_INCH);
        backLeftTarget = mLeft_2.getCurrentPosition() + (int)(leftbackInches * COUNTS_PER_INCH);
        frontRightTarget = mRight_1.getCurrentPosition() + (int)(rightfrontInches * COUNTS_PER_INCH);
        backRightTarget = mRight_2.getCurrentPosition() + (int)(rightbackInches * COUNTS_PER_INCH);

        mLeft_1.setTargetPosition(frontLeftTarget);
        mLeft_2.setTargetPosition(backLeftTarget);
        mRight_1.setTargetPosition(frontRightTarget);
        mRight_2.setTargetPosition(backRightTarget);

        mLeft_1.setMode(DcMotor.RunMode.RUN_TO_POSITION);
        mLeft_2.setMode(DcMotor.RunMode.RUN_TO_POSITION);
        mRight_1.setMode(DcMotor.RunMode.RUN_TO_POSITION);
        mRight_2.setMode(DcMotor.RunMode.RUN_TO_POSITION);

        runtime.reset();

        mLeft_1.setPower(speed);
        mLeft_2.setPower(speed);
        mRight_1.setPower(speed);
        mRight_2.setPower(speed);

        while (opModeIsActive() &&
        (mLeft_1.isBusy() && mRight_1.isBusy() && mLeft_2.isBusy() && mRight_2.isBusy())) {
        telemetry.addData("mLeft_1", "Running to %7d : %7d", mLeft_1.getCurrentPosition(), frontLeftTarget);
        telemetry.addData("mLeft_2", "Running to %7d : %7d", mLeft_2.getCurrentPosition(), backLeftTarget);
        telemetry.addData("mRight_1", "Running to %7d : %7d", mRight_1.getCurrentPosition(), frontRightTarget);
        telemetry.addData("mRight_2", "Running to %7d : %7d", mRight_2.getCurrentPosition(), backRightTarget);
        telemetry.update();
        }

        // Stop all motion;
        mLeft_1.setPower(0);
        mRight_1.setPower(0);
        mLeft_2.setPower(0);
        mRight_2.setPower(0);

        mLeft_1.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
        mLeft_2.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
        mRight_1.setMode(DcMotor.RunMode.RUN_USING_ENCODER );
        mRight_2.setMode(DcMotor.RunMode.RUN_USING_ENCODER );


        }

        }
        }

        Comment


        • #5
          So, a few comments:

          - What version SDK are you currently running? If you are running 5.3, before doing anything else update to 5.4. Version 5.3 broke Run to Position and it doesn't work.
          - I STRONGLY suggest abandoning Run To Position for drive wheels. It is fine for singular motors doing a specific task, like a lift motor or extension arm, but is terrible for driving, especially mecanum wheels
          - Instead, use Run Using Encoder. Pick one wheel, preferably the wheel that has the most weight on it and is less likely to slip. Use the encoder in this one motor to control your robot position.
          - You will have to use your own PID for controlling motion, this is quite easy and there are many people on here that can assist your programmers. For the most part, you can use a simple proportional factor times the remaining ticks for your movement, plus adding a small amount of feed forward power to ensure the robot reaches the target.
          - For reference, we use three different PID formulas based upon function. Straight runs uses a simple proportional + FF, turns use a P+D+FF formula (a dy/dt velocity factor to rapidly slow at the end), and our strafing routines use an exponential decay function due to the fact that strafing has a high friction load and little inertia. Our decay curve is to the 5th power for a sharp decline close to end point.
          - As mentioned previously, when your movement is finally done, invoke Stop and Reset Encoder for all motors. For some reason, Linear Op Modes don't like active motor modes at the end of program, we never figured out why, even though your motors are supposedly set at zero power.
          - Another suggestion is to also abandon Linear Opmode. The concept of sequential, one time through main loop, doesn't play well with Java. Your program effectively dies within the long sleep command, and squirrely things can happen there. I suggest your programmers look into using iterative opmode. This means you need to have each step of the program defined with state machine flags for each task, and many teams set up each task as an object to make things a little easier to follow.

          Comment

          Working...
          X