MotorControllerGroup Error

I am trying to code an FRC robot that my robotics team used last year. There is one error left, and I have no idea what is happening. Here is my code for my drivetrain.java file:

package frc.robot.subsystems;

import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.can.VictorSPX;

import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;

public class drivetrain {
private VictorSPX leftMotor1;
private VictorSPX leftMotor2;
private final MotorControllerGroup leftMotors;
private VictorSPX rightMotor1;
private VictorSPX rightMotor2;
private final MotorControllerGroup rightMotors;

public drivetrain() {
    leftMotor1 = new VictorSPX(1);
    leftMotor2 = new VictorSPX(2);
    rightMotor1 = new VictorSPX(3);
    rightMotor2 = new VictorSPX(4);

    MotorControllerGroup leftMotors = new MotorControllerGroup(leftMotor1, leftMotor2);
    MotorControllerGroup rightMotors = new MotorControllerGroup(rightMotor1, rightMotor2);
}

public void tankDrive(double leftMotor, double rightMotor) {
    leftMotors.set(leftMotor);
    rightMotors.set(rightMotor);
}

public MotorController getLeftMotorController() {
    return null;
}

public MotorController getRightMotorController() {
    return null;
}

}

The error is this:
The constructor MotorControllerGroup(VictorSPX, VictorSPX) is undefined

The normal VictorSPX class doesn’t implement the MotorController interface from WPILib, and so can’t be used in a MotorControllerGroup. Use the WPI_VictorSPX class instead. You should be able to simply replace “VictorSPX” with “WPI_VictorSPX” at every point where it’s used in your code.

This assumes that the VictorSPX is connected via CAN, and that the CAN IDs are assigned correctly.

That worked, but now I have some more errors.

The blank final field leftMotors may not have been initialized
The blank final field rightMotors may not have been initialized

Also, in build.gradle, I have this error:

The supplied phased action failed with an exception.
A problem occurred configuring root project ‘Newarcadedirve’.
A problem occurred evaluating root project ‘Newarcadedirve’.
Could not get unknown property ‘deps’ for extension ‘wpi’ of type edu.wpi.first.gradlerio.wpi.WPIExtension.

Exactly as the error says, you have class member variables marked final that haven’t been initialized (i.e. assigned a value). If you believe you have assigned a value, then you should look at where youre doing so. 99% of the time (including this time), it’s just a silly mistake.

If you need a hint… variable scope matters

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