What is the problem of my code? thanks

it works to drive the chassis, but it does not make sence.
if i push the joystick to most left, x=-1,
double fl = y - x - rx=1
double bl = y + x - rx=-1
double fr = y - x + rx=1
double br = y + x + rx=-1
but the chassis is still strafe to left.

thanks

package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;

@TeleOp
public class MecanumDrivetelemetry extends OpMode {
    DcMotor RFMotor;
    DcMotor LFMotor;
    DcMotor RBMotor;
    DcMotor LBMotor;

    public float speedMultiplier = 0.5f;

    @Override
    public void init() {
        RFMotor = hardwareMap.get(DcMotor.class, "RFMotor");
        LFMotor = hardwareMap.get(DcMotor.class, "LFMotor");
        RBMotor = hardwareMap.get(DcMotor.class, "RBMotor");
        LBMotor = hardwareMap.get(DcMotor.class, "LBMotor");

        RFMotor.setDirection(DcMotorSimple.Direction.REVERSE);
        RBMotor.setDirection(DcMotorSimple.Direction.REVERSE);
    }

    @Override
    public void loop() {
        moveDriveTrain();
    }

    public void moveDriveTrain() {
        double y = gamepad1.left_stick_y;
        double x = gamepad1.left_stick_x;
        double rx = gamepad1.right_stick_x;

//        double fl = y + x + rx;
//        double bl = y - x + rx;
//        double fr = y + x - rx;
//        double br = y - x - rx;

        double fl = y - x - rx;
        double bl = y + x - rx;
        double fr = y - x + rx;
        double br = y + x + rx;

        LFMotor.setPower(fl*speedMultiplier);
        LBMotor.setPower(bl*speedMultiplier);
        RFMotor.setPower(fr*speedMultiplier);
        RBMotor.setPower(br*speedMultiplier);

        telemetry.addData("y",y);
        telemetry.addData("x",x);
        telemetry.addData("fl",fl);
        telemetry.addData("bl",bl);
        telemetry.addData("fr",fr);
        telemetry.addData("br",br);
        telemetry.update();
    }
}

You push the joystick to the left and the and the chassis strafes left. Seems sensible to me?

Please describe what you expect, or want, the chassis to do when you push the joystick to the left.

@epdu I agree with @cmacfarlane that it’s not clear what problems you’re actually having - perhaps @cmacfarlane’s suggestion of what you want to happen and what it does differently might help clear up some of the confusion.

In general, there’s one code issue that you might want to consider and there are 2 possible mechanical issues that you may also want to look at. I assume you have looked at your wheels to ensure they’re spinning the correct direction when you command the robot to drive, so I won’t spend any time discussing that.

Software

I learned from @phil.malone the importance of normalizing your wheel power before setting the power in hardware to ensure the robot maintains the desired motion. I believe I see your attempt to do this with your speedMultiplier value, but you really should be using true normalization and not use a constant value. In the FTC SDK there’s the BasicOmniOpMode_Linear.java sample that shows the correct way to write a Mecanum-based drivetrain calculation that includes normalization - you can easily incorporate this into your code as well. The comments in the sample code are priceless, please pay special attention to them. This may likely solve your problem, depending on what the problem is.

Hardware

When I guide my students to using Mecanum wheels, there are two big areas we talk about: Mecanum wheel configuration, and weight distribution. Mecanum wheel configuration has everything to do with the way the wheels are mounted on the robot, and weight distribution deals with how the weight is distributed on the robot. Both are important to the proper performance of your Mecanum drivetrain.

Mecanum Wheel Configuration

You probably knew this, but there are two different kinds of Mecanum wheel - a “left” and a “right” wheel. Instead of putting the “left” wheel on the left side of the bot, and the “right” on the right side of the bot, you actually put them diagonal of each other. This video from AndyMark on Mecanum wheels is a FANTASTIC guide to making sure you mounted the wheels correctly.

Weight Distribution

Since Mecanum wheels are heavily reliant on the traction of the wheels on the floor, proper weight distribution is of critical importance. Even if you do everything else right, your Mecanum wheels may not perform the way you want simply because of how much weight each wheel is bearing. When strafing specifically, your robot might not strafe straight even when you’re absolutely providing the proper power to each wheel, but may instead strafe in a curved line. Ensuring that each wheel has an equal (or as equal as possible) amount of weight may significantly improve your robot’s strafing performance.

I hope this helps.
-Danny

1 Like