Announcement

Collapse
No announcement yet.

Mecanum Drive

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

  • Mecanum Drive

    We are having a problem with mecanum Drive. We use the X button and y button to drive the robot sideways. We use the joy sticks to drive forwards and backwards tank style. The problem is that it drives great but when we use the buttons for going sideways the motors start jumping, no consistent power. We had it working great but it started doing this when we added a second rev hub. I'll post our code later.

  • #2
    My bet is that you are sending different powers to the motors. Once from your joystick and once from x and y. You need code that if you are pressing x and/or y that it doesn't even look at the joysticks.

    Comment


    • #3
      Here is our code.

      @Override
      public void loop()
      {
      double left;
      double right;


      // Drive Wheels (Motors) in Tank Mode With Joysticks on Gamepad1
      /*(Note: The joystick goes negative when pushed forwards, so negate it for robot to drive forwards.)*/
      //Left Joystick Manipulates Left Motors
      left = gamepad1.left_stick_y;
      robot.left1Motor.setPower(left);
      robot.left2Motor.setPower(left);


      //Right Joystick Manipulates Right Motors
      right = gamepad1.right_stick_y;
      robot.right1Motor.setPower(right);
      robot.right2Motor.setPower(right);

      // Strafe Robot with Mecanum Wheels
      // Right Strafe
      // Robot strafes to the right when button 'b' is pressed.
      // 'left1Motor'and 'right2Motor' Drive FORWARD and 'left2Motor' and 'right1Motor' Drive REVERSE
      // Motors on Robot are Reversed, so driving forwards will be negative and reverse will be positive
      if (gamepad1.b)
      {
      robot.left1Motor.setPower(-1);
      robot.left2Motor.setPower(1);
      robot.right1Motor.setPower(1);
      robot.right2Motor.setPower(-1);
      }

      // Left Strafe
      // Robot strafes to the left when button 'x' is pressed.
      // 'left1Motor' and 'right2Motor' Drive in RREVERSE and 'left2Motor' and 'right1Motor' Drive FORWARD
      if (gamepad1.x)
      {
      robot.left1Motor.setPower(1);
      robot.left2Motor.setPower(-1);
      robot.right1Motor.setPower(-1);
      robot.right2Motor.setPower(1);
      }

      }

      // Code to Run When Coach Hits STOP
      @Override
      public void stop()
      {
      telemetry.addData("Robot", "Stopped");
      }
      }

      Comment


      • #4
        Yes, it is exactly as I said above. What you want to do is:

        if (gamepad1.x){
        // your code here
        }else if (gamepad1.b){
        // your code here
        }else{
        // your code that uses the two joysticks
        }

        However, I would probably not use full power to strafe. You might want to use the left and right bumpers (they are analog) so pressing them in farther can make your robot strafe faster. (and a lighter touch makes it slower)

        Make sense?

        --Alan

        Comment


        • #5
          Yes, thank you!

          Comment


          • #6
            we were going to try the bumpers but couldn't figure out the code. We shall continue to try and post that code later for your inputs!

            Comment


            • #7
              We made a separate class for Mecanum here: https://github.com/ftc16072/Skystone...anumDrive.java

              If you do something like that, then it becomes easy for your opMode to do various things with it.

              Best of luck!!!

              --Alan

              Comment


              • #8
                OK, we tried that and now we get the following errors on line 70 and 78
                "Else without if statement" even though there is an if!
                // Code to Run When Coach Hits INITIALIZATION
                /*Initializes All Hardware Variables*/
                @Override
                public void init() {
                robot.init(hardwareMap);
                telemetry.addData("Robot", "Initialized");
                }
                @Override
                public void init_loop() {
                }

                // Code to Run ONCE When the Coach Hits PLAY
                @Override
                public void start() {
                telemetry.addData("Robot", "Driver_Controlled");
                }

                // Code to Run REPEATEDLY After the Coach Hits PLAY
                // Teleop Objects
                @Override
                public void loop()
                {
                double left;
                double right;





                // Strafe Robot with Mecanum Wheels
                // Right Strafe
                // Robot strafes to the right when button 'b' is pressed.
                // 'left1Motor'and 'right2Motor' Drive FORWARD and 'left2Motor' and 'right1Motor' Drive REVERSE
                // Motors on Robot are Reversed, so driving forwards will be negative and reverse will be positive
                if (gamepad1.b) ;
                {
                robot.left1Motor.setPower(-1);
                robot.left2Motor.setPower(1);
                robot.right1Motor.setPower(1);
                robot.right2Motor.setPower(-1);
                }

                // Left Strafe
                // Robot strafes to the left when button 'x' is pressed.
                // 'left1Motor' and 'right2Motor' Drive in RREVERSE and 'left2Motor' and 'right1Motor' Drive FORWARD
                else if (gamepad1.x);
                {
                robot.left1Motor.setPower(1);
                robot.left2Motor.setPower(-1);
                robot.right1Motor.setPower(-1);
                robot.right2Motor.setPower(1);
                }
                // Drive Wheels (Motors) in Tank Mode With Joysticks on Gamepad1
                /*(Note: The joystick goes negative when pushed forwards, so negate it for robot to drive forwards.)*/
                //Left Joystick Manipulates Left Motors
                else

                {left = gamepad1.left_stick_y;
                robot.left1Motor.setPower(left);
                robot.left2Motor.setPower(left);

                //Right Joystick Manipulates Right Motors
                right = gamepad1.right_stick_y;
                robot.right1Motor.setPower(right);
                robot.right2Motor.setPower(right); } }

                // Code to Run When Coach Hits STOP
                @Override
                public void stop()
                {
                telemetry.addData("Robot", "Stopped");
                }
                }


                I made it red where the problem is.

                Comment


                • #9
                  TLDR: The problems are that you have a semicolon after your if statements.

                  You can either have an if statement with a single "execution" followed by a semicolon OR it can be followed by a block of code (one or more statements inside of curly braces). so the compiler thinks you have an if statement followed by a block of code (the block of code is NOT conditional) then it sees an else statement and it is very confused.....

                  Comment

                  Working...
                  X