Announcement

Collapse
No announcement yet.

Robot doesn't move with encoders.

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

  • Robot doesn't move with encoders.

    I made this program so I could go exactly one rotation but none of the motors move. So I was wondering if anyone knew a way to fix it.

    Attached Files

  • #2
    After sending power to your motors, you are sending some telemetry & then immediately stopping the motors - then your program ends with no movement.

    You need to add some type of waiting logic after setting the power & before setting them back to 0 power. The best way to do that is to either wait for 1 of the motors to reach target, or wait for all of the motors to reach. The sample program PushbotAutoDriveByEncoder_Linear is an excellent way to learn encoders - go through it top to bottom & make sure you understand every single line (research or ask questions where you are unsure), then pick out the pieces you need for your application.

    Also - Depending on your hardware setup you probably need to reverse 2 of the motors & I'm not sure of the default mode, but it is safest to to perform setMode(DcMotor.RunMode.RUN_USING_ENCODER).

    Comment


    • #3
      changed code as below after waitForStart() -
      while (opModeIsActive()){


      frontLeft.setTargetPosition(1120); //Sets motor to move 1120 ticks (1 rotation)
      backLeft.setTargetPosition(1120); //89.1 = 1"
      frontRight.setTargetPosition(1120); // 1120 = 12.57"
      backRight.setTargetPosition(1120); // 1069.2 = 12"


      frontLeft.setPower(.5); // Sets motors to half power
      backLeft.setPower(.5);
      frontRight.setPower(.5);
      backRight.setPower(.5);
      while(!frontLeft.isBusy()){ frontLeft.setPower(0); //Sets motors to no power
      backLeft.setPower(0);
      frontRight.setPower(0);
      backRight.setPower(0);}

      telemetry.addData("Path", "Finished"); //Phone displays that the path is finished
      telemetry.update();
      }

      Comment


      • #4
        look at sample code - drive by encoder

        Comment


        • #5
          Originally posted by FLARE View Post
          After sending power to your motors, you are sending some telemetry & then immediately stopping the motors - then your program ends with no movement.

          You need to add some type of waiting logic after setting the power & before setting them back to 0 power. The best way to do that is to either wait for 1 of the motors to reach target, or wait for all of the motors to reach. The sample program PushbotAutoDriveByEncoder_Linear is an excellent way to learn encoders - go through it top to bottom & make sure you understand every single line (research or ask questions where you are unsure), then pick out the pieces you need for your application.

          Also - Depending on your hardware setup you probably need to reverse 2 of the motors & I'm not sure of the default mode, but it is safest to to perform setMode(DcMotor.RunMode.RUN_USING_ENCODER).
          I did try the sample code but I have 4 individual motors and it only controlled 2 of them even though I changed it a bit for 4 motors.

          Comment


          • #6
            Originally posted by FTC12676 View Post
            changed code as below after waitForStart() -
            while (opModeIsActive()){


            frontLeft.setTargetPosition(1120); //Sets motor to move 1120 ticks (1 rotation)
            backLeft.setTargetPosition(1120); //89.1 = 1"
            frontRight.setTargetPosition(1120); // 1120 = 12.57"
            backRight.setTargetPosition(1120); // 1069.2 = 12"


            frontLeft.setPower(.5); // Sets motors to half power
            backLeft.setPower(.5);
            frontRight.setPower(.5);
            backRight.setPower(.5);
            while(!frontLeft.isBusy()){ frontLeft.setPower(0); //Sets motors to no power
            backLeft.setPower(0);
            frontRight.setPower(0);
            backRight.setPower(0);}

            telemetry.addData("Path", "Finished"); //Phone displays that the path is finished
            telemetry.update();
            }
            I believe in the above code isBusy will be true when the program gets to the while statement, negate makes it false, so it jumps past, and still ends the program before the motors get a chance to run.

            Try replacing the above while loop with below. With one rotation you probably won't have enough time to see the telemetry, you will with a longer move. You don't absolutely need the setPower(0) statements as when the encoder count is reached the motors will stop. They will have power applied to actively maintain that position so will consume more battery power.
            (should add && opModeActive to while test condition to not get an SDK complaint about the robot being stuck if you hit stop while in the while loop)
            I agree with the others saying that you should go and understand the example code.



            while (frontLeft.isBusy()) {
            telemetry.addData("Encoder cnt ", frontLeft.getCurrentPosition());
            telemetry.update();
            |

            Comment


            • #7
              The last line above the "|" is supposed to be "}"

              Comment

              Working...
              X