Help with java drivetrain code

My team and I are having issues with our drivetrain code (first image below). In initDefaultCommand, TankDrive cannot be resolved to a type. We’re very confused because there’s nothing wrong that we can see. We have it configured how we’ve always had it in previous years, so there’s nothing that we can tell that is wrong. The second picture is our tankdrive command and the third is our file hierarchy.
Any and all ideas are appreciated!



TankDrive.Java needs a lowercase ‘j’ in the extension

1 Like

Also, after lower casing the j in java, double check that you are importing the TankDrive class in the DriveTrain class

1 Like

So I did catch the J in .java right after I uploaded, but even after importing TankDrive into DriveTrain it throws an error that it is an unsed import. Our software mentor is completely stumped, he said it feels like the program is completely unaware that commands exists.

Well, if it’s an unused import it’s not a problem. Check your command and make sure it is correctly done.

Can you upload or copy the entire DriveTrain class so we can see if it is importing the TankDrive class correctly?

In your TankDrive class, are you importing Command from wpilibj or wpilibj2?

wpilibj, what’s the difference between j & j2?

This year they released a new version that has new libraries and new structures for commands, subsystems, etc. You can still use the old structure but I would recommend learning the new structure in case the old is removed in the future.

Can you paste the top of your DriveTrain file?

package frc.subsystems;

import com.ctre.phoenix.motorcontrol.InvertType;

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

import edu.wpi.first.wpilibj.SpeedControllerGroup;

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

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

import frc.commands.TankDrive;

public class DriveTrain extends Subsystem{

//create talons

WPI_TalonSRX LeftMasterT, RightMasterT, LeftFollowerOneT, RightFollowerOneT, LeftFollowerTwoT, RightFollowerTwoT;

//create speedcontroller groups

SpeedControllerGroup LeftMotors, RightMotors;

//create robotdrive

DifferentialDrive robotDrive;

//create drivetrain

public DriveTrain(int LeftMaster, int RightMaster, int LeftFollowerOne, int RightFollowerOne,

              int LeftFollowerTwo, int RightFollowerTwo){

//initialize motors

LeftMasterT = new WPI_TalonSRX(LeftMaster);

LeftFollowerOneT = new WPI_TalonSRX(LeftFollowerOne);

LeftFollowerTwoT = new WPI_TalonSRX(LeftFollowerTwo);

RightMasterT = new WPI_TalonSRX(RightMaster);

RightFollowerOneT = new WPI_TalonSRX(RightFollowerOne);

RightFollowerTwoT = new WPI_TalonSRX(RightFollowerTwo);

    LeftFollowerOneT.follow(LeftMasterT);

    LeftFollowerTwoT.follow(LeftMasterT);

    RightFollowerOneT.follow(RightMasterT);

    RightFollowerTwoT.follow(RightMasterT);

    LeftFollowerOneT.setInverted(InvertType.FollowMaster);

    LeftFollowerTwoT.setInverted(InvertType.FollowMaster);

    RightFollowerOneT.setInverted(InvertType.FollowMaster);

    RightFollowerTwoT.setInverted(InvertType.FollowMaster);

    robotDrive = new DifferentialDrive(LeftMasterT, RightMasterT);

// Stop "output not updated often enough" error from printing

robotDrive.setSafetyEnabled(false);

}

public void JoystickDrive(double speed, double rotate){

robotDrive.arcadeDrive(speed * 0.85, rotate * 0.85);

}

@Override

protected void initDefaultCommand() {

    setDefaultCommand(new TankDrive());

}

}

It sort of formatted weird but it hopefully that helps you understand my issues

Looking over the TankDrive command I see that you called Robot.DriveTrain.joyStickDrive(…)

The method in DriveTrain is JoystickDrive(…) with a capital J not a lower case j

Also, is the static public variable in Robot for DriveTrain really DriveTrain or driveTrain?

What happens if you change it to setDefaultCommand(frc.commands.TankDrive()); ?

Try changing
package frc.subsystems;

for
package frc.robot.subsystems;

And also change the tank drive import like this:
import frc.robot.command.TankDrive;
You should add “robot” after “frc”, I think that is what caused the problem since it didn’t recognize that the whole frc subsystem libraries because “robot” wasn’t there. I tried it on my VS code and there was no error anymore.

Just checking in to see if you figured it out or need help with anything

1 Like

Yeah thanks. Eventually we figured it out. For some reason (and this we have not figured this out yet but we learned the workaround for it so it’s fine) VS code will not accept the certain files that we made ourselves. For whatever reason, we need to write a line of code, then use the “Quick Fix” button that pops up and let VS auto-generate the file or even field inside a file. For this, it could not find TankDrive. We’ve had other issues where it can’t find the OI with our controller & button stuff and RobotMap with our port definitions, but letting it create fields itself seems to work. It’s strange because like even when I let it create things and it shows no errors, when I push to Github and someone downloads it, they end up with the same “cannot find X” or “X cannot be resolved”. Once we figured that out and the workaround for it, development has gone smoothly. Thanks for all your help, and thanks to the rest of the people in this thread

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