EasyStack Docs

DifferentialDrive

Esta página ainda não foi traduzida. Mostrando a versão em inglês.

Differential Drive

A differential drivetrain controls a left side and a right side. It moves forward or backward by driving both sides and turns by giving the sides different commands. This class does not support sideways movement.

Creating a differential drive

Provide the left actuator first and the right actuator second. Both parameters implement EasyControllable. They may represent individual actuators or compatible side controllers; this class itself does not build motor groups.

Java
import dev.easyfamily.easystack.drivebase.DifferentialDrive;
DifferentialDrive drive new DifferentialDrive(left, right);
drive.;

left and right above are already initialized EasyControllable objects. The default constructor enables right side inversion, which multiplies right side commands by −1 before sending them to the actuator.

Configuring right side inversion

The optional boolean comes before the two hardware parameters. Pass false when your hardware configuration already provides the required direction.

Java
DifferentialDrive drive
        new DifferentialDrive(false, left, right);

drive.setRightSideInverted (true);
boolean inverted drive.isRightSideInverted ();

Check how inversion interacts with the motor directions configured elsewhere. Inverting the same side both in the hardware wrapper and in the drivebase can cancel the intended change.

getLeft() and getRight() return the same actuator references supplied to the constructor. They are useful for accessing existing hardware configuration; they do not return measured drivetrain velocity or position.

Differential driving modes

Arcade drive

Arcade drive uses one forward input and one turn input. Before right side inversion and output scaling, the mixer calculates left = forward + turn and right = forward − turn. If either magnitude exceeds 1, both commands are reduced proportionally.

Java
drive.arcadeDrive(
        -gamepad1.left_stick_y,
        gamepad1.right_stick_x
);

Negating the FTC stick Y value makes an upward stick request positive forward input. Confirm the physical turning direction during setup because hardware direction settings also affect the result.

Tank drive

Tank drive provides separate left and right power requests. The following mapping uses one vertical joystick per side.

Java
drive.tankDrive(
        -gamepad1.left_stick_y,
        -gamepad1.right_stick_y
);

Squared inputs

Both modes have a final squareInputs argument. Enable it to reduce small commands while retaining their sign and the full input range. The versions without the boolean do not square inputs.

Java
drive.arcadeDrive(0.5, -0.2, true);
drive.tankDrive(0.5, 0.5, true);

drive(DrivePowers) calls the two argument arcadeDrive() method, using forward and turn. Strafe is ignored, and this path does not enable input squaring automatically.

Direct power and stopping

setMotorPowers(leftPower, rightPower) bypasses the arcade and tank input clipping and normalization. It still applies maxOutput and the right side multiplier. Keep direct inputs within the intended range; the drivebase does not constrain them on this path.

Java
drive.setMotorPowers(0.2, 0.2);
drive.stop();

stop() sends zero directly to both sides, regardless of inversion or output scaling. Call it when the control session ends.

Differential drive in a control loop

The helper below accepts an existing drivebase. Construct it once, then call update() from the active control loop. The boolean selects tank mode; otherwise the helper uses arcade mode. All inputs are squared in this example.

Java
import com.qualcomm.robotcore.hardware.Gamepad;
import dev.easyfamily.easystack.drivebase.DifferentialDrive;

public class DifferentialControls {
    private final DifferentialDrive drive;

    public DifferentialControls(DifferentialDrive drive) {
        this.drive = drive;
        drive.setMaxOutput(0.6);
    }

    public void update(Gamepad pad, boolean tankMode) {
        if (tankMode) {
            drive.tankDrive(-pad.left_stick_y,
                    -pad.right_stick_y, true);
        } else {
            drive.arcadeDrive(-pad.left_stick_y,
                    pad.right_stick_x, true);
        }
Java
    }

    public void stop() {
        drive.stop();
    }
}

Differential setup checks

If forward input produces rotation, check the left and right actuator order and the right side inversion setting. Verify motor directions with a small equal command before combining forward and turn.

For an unexpected joystick response, confirm whether tank or arcade mode is selected and whether squared inputs are enabled. Call stop() when control ends.

Última atualização 2026-11-16

EasyStack - FTC Java library

This site records page views of visitors to understand how the documentation is used. Nothing is sold or shared with third parties.