Differential Drive SpeedControllerGroup Error

Hi, I’m getting an error, in my Differential Drive Subsystem, on the lines …
SpeedControllerGroup m_Right = new SpeedControllerGroup( RightFrontMotor,
RightBackMotor);
&
SpeedControllerGroup m_Right = new SpeedControllerGroup( LeftFrontMotor,
LeftBackMotor);
It says “The constructor SpeedControllerGroup(VictorSPX, VictorSPX) is undefined” and I can not for the life of me figure out why. Below I have Copy and Pasted the majority of my Differential Drive Subsystem. I would really appreciate any help thank you.

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

import edu.wpi.first.wpilibj.SpeedController;

import edu.wpi.first.wpilibj.SpeedControllerGroup;

import edu.wpi.first.wpilibj.command.Subsystem;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;

import frc.robot.commands.DriveTrainCom;

/**

  • Add your docs here.

*/

public class DriveTrainSub extends Subsystem {

// Put methods for controlling this subsystem

// here. Call these from Commands.

VictorSPX RightFrontMotor,RightBackMotor, LeftFrontMotor,LeftBackMotor;

DifferentialDrive m_drive;

public DriveTrainSub() {

RightFrontMotor = new VictorSPX(4);

RightBackMotor = new VictorSPX(1);

LeftFrontMotor = new VictorSPX(2);

LeftBackMotor = new VictorSPX(3);

SpeedControllerGroup m_Right = new SpeedControllerGroup(RightFrontMotor, RightBackMotor);

** SpeedControllerGroup m_Left = new SpeedControllerGroup(LeftFrontMotor, LeftBackMotor);**

DifferentialDrive m_drive = new DifferentialDrive(m_Right, m_Left);

}

Change to WPI_VictorSPX

1 Like

I am having the exact same issue. What do you mean change to WPI_VictorSPX? Where should we change it?
I am trying to program the kit bot with two motors on each side, using VictorSPX motor Controllers connected by CAN and two joysticks for Tank Drive
Here is my Code:

package frc.robot;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import com.ctre.phoenix.motorcontrol.can.VictorSPX;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.SpeedController;

public class Robot extends TimedRobot {
private DifferentialDrive m_myRobot;
private Joystick m_leftStick;
private Joystick m_rightStick;
private VictorSPX m_BL;
private VictorSPX m_FL;
private VictorSPX m_BR;
private VictorSPX m_FR;
public SpeedControllerGroup m_leftMotors;
public SpeedControllerGroup m_rightMotors;

@Override
public void robotInit() {
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
m_BL = new VictorSPX(0);
m_FL = new VictorSPX(1);
m_BR = new VictorSPX(2);
m_FR = new VictorSPX(3);
m_myRobot = new DifferentialDrive(m_leftMotors, m_rightMotors);
m_leftMotors = new SpeedControllerGroup(m_BL, m_FL);
m_rightMotors = new SpeedControllerGroup(m_BR, m_FR);
}

@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
}
}

Would become:
private WPI_VictorSPX m_BL;
private WPI_VictorSPX m_FL;
private WPI_VictorSPX m_BR;
private WPI_VictorSPX m_FR;

Would become:
m_BL = new WPI_VictorSPX(0);
m_FL = new WPI_VictorSPX(1);
m_BR = new WPI_VictorSPX(2);
m_FR = new WPI_VictorSPX(3);

Thanks, the code now reports now errors and I can deploy the code. However, in the driver station it says there is no code, communications are good and joysticks are good but no code. I think it has something to do with the speed controller groups. Does any of that code look out of place.

I’ve restart from scratch and when I don’t have those speed control groups I am able to run the program.

I don’t see an issue but it would be easier to help if you had a GitHub link or something of all your code.

If robot code crashed there will likely be an error that printed to the driver station log. Can you copy that here?

1 Like

m_leftMotors and m_rightMotors are null when you pass them to DifferentialDrive.

2 Likes

I just created a github account, but I’m not sure how to link my code. I copied and pasted my whole code below:
package frc.robot;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.SpeedController;
import com.ctre.phoenix.motorcontrol.can.VictorSPX;
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.SpeedControllerGroup;

public class Robot extends TimedRobot {

private DifferentialDrive m_myRobot;
private Joystick m_leftStick;
private Joystick m_rightStick;
private WPI_VictorSPX m_BackLeft;
private WPI_VictorSPX m_Frontleft;
private WPI_VictorSPX m_BackRight;
private WPI_VictorSPX m_FrontRight;
public SpeedControllerGroup m_left;
public SpeedControllerGroup m_right;

@Override
public void robotInit() {
m_myRobot = new DifferentialDrive(new SpeedControllerGroup(m_left), new SpeedControllerGroup(m_right));

m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);

WPI_VictorSPX m_BackLeft = new WPI_VictorSPX(0);
WPI_VictorSPX m_Frontleft = new WPI_VictorSPX(1);
SpeedControllerGroup m_left = new SpeedControllerGroup(m_BackLeft, m_Frontleft);

WPI_VictorSPX m_BackRight = new WPI_VictorSPX(2);
WPI_VictorSPX m_FrontRight =new WPI_VictorSPX(3);
SpeedControllerGroup m_right = new SpeedControllerGroup(m_BackRight, m_FrontRight);

m_left.setInverted(false); // if you want to invert the entire side you can do so here
m_right.setInverted(false); // if you want to invert the entire side you can do so here 

}

@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
}
}

These are my error messages from Visual Studio:
The import edu.wpi.first.wpilibj.SpeedController is never used
The import com.ctre.phoenix.motorcontrol.can.VictorSPX is never used
The value of the field Robot.m_BackLeft is not used
The value of the field Robot.m_Frontleft is not used
The value of the field Robot.m_FrontRight is not used
The value of the field Robot.m_BackRight is not used
Resource leak: ‘m_left’ is never closed
Resource leak: ‘m_right’ is never closed

Do I not have the right things imported? Things not listed as public/private Correctly? Do I have parts of the code in the wrong areas? I really have no clue what parts go where ie, public class or public void.

The line below is before you actually set m_left and m_right. Move it down till after the setInverted lines. I would also remove the new SpeedControllerGroup as you are already setting that!
m_myRobot = new DifferentialDrive(m_left, m_right);

You can remove the unused imports for the top 2 warnings:
import com.ctre.phoenix.motorcontrol.can.VictorSPX;
import edu.wpi.first.wpilibj.SpeedController;

Did you create a new repository?

After creating the repoitory you should be able to use “Add File”->“Upload files” to get started. You can read more about Github here.
image

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