New drivetrain problems

so this code that used to work to make our tank drive move now only makes it turn. I have been working on this for days and I’m not sure if I’m missing something obvious or if something changed recently with the differentialdrive class or something. Thanks for the help!


// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.commands.Drive;
import frc.robot.subsystems.DriveTrain;

 * This class is where the bulk of the robot should be declared. Since Command-based is a
 * "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
 * periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
 * subsystems, commands, and button mappings) should be declared here.
public class RobotContainer {
  // The robot's subsystems and commands are defined here...
  DriveTrain driveTrain = new DriveTrain();

  Drive drive;

  /** The container for the robot. Contains subsystems, OI devices, and commands. */
  public RobotContainer() {
    // Configure the button bindings

   * Use this method to define your button->command mappings. Buttons can be created by
   * instantiating a {@link GenericHID} or one of its subclasses ({@link
   * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
   * edu.wpi.first.wpilibj2.command.button.JoystickButton}.
  private void configureButtonBindings() {
    XboxController controller = new XboxController(0);
    drive = new Drive(driveTrain, () -> controller.getLeftY(), () -> controller.getRightX());


   * Use this to pass the autonomous command to the main {@link Robot} class.
   * @return the command to run in autonomous
  public Command getAutonomousCommand() {
    // An ExampleCommand will run in autonomous
    return null;

drivetrain subsystem:

package frc.robot.subsystems;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;

import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class DriveTrain extends SubsystemBase {
    public CANSparkMax leftLeader;
    public CANSparkMax leftFollower;
    public CANSparkMax rightLeader;
    public CANSparkMax rightFollower;

    MotorControllerGroup left;
    MotorControllerGroup right;

    public DifferentialDrive drive;

    public DriveTrain() {
        leftLeader = new CANSparkMax(1, MotorType.kBrushless);
        leftFollower = new CANSparkMax(3, MotorType.kBrushless);

        rightLeader = new CANSparkMax(2, MotorType.kBrushless);
        rightFollower = new CANSparkMax(4, MotorType.kBrushless);

        left = new MotorControllerGroup(leftLeader, leftFollower);
        right = new MotorControllerGroup(rightLeader, rightFollower);


        drive = new DifferentialDrive(left, right);

    public void drive(double f, double t) {
        drive.arcadeDrive(f, t);

drive command:

package frc.robot.commands;

import java.util.function.DoubleSupplier;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DriveTrain;

public class Drive extends CommandBase {
    public DriveTrain driveTrain;
    public DoubleSupplier forward;
    public DoubleSupplier turn;
    public boolean finished;

    public Drive(DriveTrain d, DoubleSupplier f, DoubleSupplier t) {
        driveTrain = d;
        forward = f;
        turn = t;


    public void execute() {, turn.getAsDouble());

    public boolean isFinished(){
        return finished;

Can you elaborate on this? Are you saying that it NEVER drives forward? Or does it seem like the inputs are reversed (forward on the left stick rotates right, right on the right stick goes forward)?

No so both inputs of the controller make it turn

1 Like

I hope you have the robot up on blocks while testing this.
It’s a lot easier to see what each wheel is actually doing.

On the ground the wheels will be dragged kicking and screaming by the other wheels, and it’s harder to tell what is really occurring.

For instance, pushing one joystick:

  • Are the motors on one side only being driven?
  • Do the opposing motors remain in neutral?
  • Do the motor controller status lights show the same color and flashing pattern?

All of the spark maxes show the green indicator light for positive controller values and red for negative controller values. Both joysticks make the robot behave the same

You might have to invert some of the motor depending on how they are oriented. Unless you burn these settings to flash, they will not remain on the SparkMax until set again in code.

1 Like

Code mostly looks good but you might want to try something like leftLeader.restoreFactoryDefault() for all the motors just to get rid of any stuff that might be burned to flash and messing something up. I lean more towards a hardware issue if it is never going straight which would not happen if it were an inversion issue.

1 Like

that fixed it. thanks!!!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.