4 motor tank/arcade drive java CANbus Java

We began programming out bot this year and everything was going great until we realized (I know we forgot it was going away) MotorControlGroup was going away. So we set up each motor. We create a group for left and right side using DifferentialDrive. Now we need to create the final drive combining those two DifferentialDrives. Is there a new command library that will combine these two drives or is there a different way we need to do this? If we need to return to the PWM wiring we can, we just like the ease of the CANBus for configuration. Our code is on our mentors GitHub. screen shot of the drivetrain subsystem below. GitHub - michaelallen1994/Crescendo1994: Team 1994's code for the Crescendo game 2024

The intermediary DifferentialDrives won’t do what you want. CANSparkMax has a follow method. CANSparkBase (FRC-REVLib API)

1 Like

I did not know that the MotorControllerGroup was going away. We are using it in our code currently.

One solution is to recreate a MotorControllerGroup manually. This should not be too hard if you have a basic understanding of objects and use other WPI libraries.

Code Ex:

public class MotorControllerGroup{
     public static void MotorControllerGroup(CANSparkMax motor1, CANSparkMax motor 2){
          motor1.set(0);
          motor2.set(0);
          //continue your code
     }
}

You could also return something from this array or you could have the input be an array of motor controllers.

If you are picky you could use threading in addition or instead of MotorControllerGroup to eliminate the very small delay between motors starting.

The correct follower setup for this is:

private final CANSparkMax leftMotor1 = new CANSparkMax(...);
private final CANSparkMax leftMotor2 = new CANSparkMax(...);
private final CANSparkMax rightMotor1 = new CANSparkMax(...);
private final CANSparkMax rightMotor2 = new CANSparkMax(...);
private final DifferentialDrive drive = new DifferentialDrive(leftMotor1, leftMotor2);

public Drivetrain() {
  leftMotor2.follow(leftMotor1);
  rightMotor2.follow(rightMotor1);
}

There is no need to make your own version of MotorControllerGroup, the follow() calls have the same effect, potentially with less CAN bus traffic.

1 Like

Thank you, everyone, for your feedback. The “follow” method is working great so far. Good luck to you all for the season.

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