No announcement yet.

Mecanum wont go straight during strafe

  • Filter
  • Time
  • Show
Clear All
new posts

  • Mecanum wont go straight during strafe

    We have built a basic bot with mecanum wheels that strafes, kind of. It is not completely straight. any ideas what we are missing? We have seen competition bots strafe perfectly sideways and can't figure out how to do it.
    Here is our code:

    package org.firstinspires.ftc.teamcode;

    import com.qualcomm.robotcore.eventloop.opmode.OpMode;
    import com.qualcomm.robotcore.hardware.Gamepad;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import com.qualcomm.robotcore.util.Range;

    @TeleOp(name="mecanum", group="Pushbot")
    public class Mecanum extends OpMode {

    /* Declare OpMode members. */
    org.firstinspires.ftc.teamcode.HardwarePushbot robot = new HardwarePushbot(); // use the class created to define a Pushbot's hardware

    * Code to run ONCE when the driver hits INIT
    public void init() {
    /* Initialize the hardware variables.
    * The init() method of the hardware class does all the work here

    // Send telemetry message to signify robot waiting;
    telemetry.addData("Say", "Hello Driver"); //

    * Code to run REPEATEDLY after the driver hits INIT, but before they hit PLAY
    public void init_loop() {

    * Code to run ONCE when the driver hits PLAY
    public void start() {

    * Code to run REPEATEDLY after the driver hits PLAY but before they hit STOP
    public void loop() {
    double left;
    double right;

    // Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
    left = -gamepad1.left_stick_y;
    right = -gamepad1.right_stick_y;


    // Use gamepad left & right Bumpers to open and close the claw
    if (gamepad1.b) {

    else if (gamepad1.x){



    public void stop() {


  • #2
    The problem may be your robot's weight distribution. If you can move components around so you have roughly the same weight to each wheel, that should help.

    If you are not already running with encoders, that may help as well since it will try to regulate speed rather than power.

    The most reliable way is probably to use a gyro, but the programming is rather complicated so that may not be an option depending on your team's java ability.
    Last edited by FLARE; 03-14-2018, 02:00 PM.


    • #3
      We are having this same issue and redistributing the robot's weight is not an option. We have thought of using the gyro, but we can't figure out how to do it.


      • #4
        Your problem is that in strafe, the wheels on each side rotate together or apart. This is dependent on the direction you want to move. Your program always rotates the right motors together and the left motors together. Our team uses the Left stick to drive and strafe and the right stick to turn. This is a code that we found last year on the web somewhere and our programmer can not remember exactly where. It finds the angle that your joystick is currently at and calculates the power required for each of the 4 wheels.

        Click image for larger version

Name:	Screenshot from 2019-02-01 18-42-18.png
Views:	97
Size:	13.5 KB
ID:	73110


        • #5
          thensley There's a problem with the logic in your loop() method:

          1. Suppose you are trying to strafe by pressing X or B (and you aren't touching the joysticks): each time through the loop method, all of your motors will get set to zero power (via joystick control), then they will get set to the powers for strafing.
          2. Suppose you are trying to use the joysticks for tank drive (and aren't touching X or B): each time through the loop method, all of your motors will get set via the joysticks, but then they will get set to zero power in the "else" clause.

          I'd expect to see very jerky motion.

          You need to incorporate the joystick control into the if-else logic:

          if (gamepad1.b) {your existing code to strafe in one direction}
          else if (gamepad1.x) {your existing code to strafe in the opposite direction}
          else {joystick control goes here}

          Also, I second the advice from FLARE about using encoders (in RUN_USING_ENCODER mode). Mechanum bot control will be very difficult without them.