Hey, all of these problems are not connected to any code that I wrote:
Error at com.ctre.phoenix.motorcontrol.WPI_AutoFeedEnable.lambda$new$0(WPI_AutoFeedEnable.java:20): Unhandled exception: java.lang.NoSuchMethodError: 'edu.wpi.first.wpilibj.DriverStation edu.wpi.first.wpilibj.DriverStation.getInstance()'
at com.ctre.phoenix.motorcontrol.WPI_AutoFeedEnable.lambda$new$0(WPI_AutoFeedEnable.java:20)
at edu.wpi.first.hal.HAL.simPeriodicBefore(HAL.java:66)
at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:367)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:130)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:343)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:413)
at java.base/java.lang.Thread.run(Thread.java:829)
Though, this is the autonomous code - sorry that I can’t provide a link to the repo, the repo is currently private and I don’t have the access rights to change it:
// 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.subsystems;
import com.ctre.phoenix.motorcontrol.TalonFXSimCollection;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
import edu.wpi.first.math.system.plant.DCMotor;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;
public class DriveTrain extends SubsystemBase {
/** Creates a new DriveTrain. */
private WPI_TalonFX backLeftMotor;
private WPI_TalonFX backRightMotor;
private WPI_TalonFX frontLeftMotor;
private WPI_TalonFX frontRightMotor;
private DifferentialDrive differentialDrive;
protected TalonFXSimCollection backLeftMotorSim;
protected TalonFXSimCollection backRightMotorSim;
protected TalonFXSimCollection frontLeftMotorSim;
protected TalonFXSimCollection frontRightMotorSim;
protected DifferentialDrivetrainSim differentialDriveSim;
public DriveTrain() {
this.backLeftMotor = new WPI_TalonFX(Constants.kBackFrontMotor);
this.backRightMotor = new WPI_TalonFX(Constants.kBackLeftMotor);
this.frontLeftMotor = new WPI_TalonFX(Constants.kFrontLeftMotor);
this.frontRightMotor = new WPI_TalonFX(Constants.kFrontRightMotor);
this.frontLeftMotorSim = frontLeftMotor.getSimCollection();
this.frontRightMotorSim = frontRightMotor.getSimCollection();
this.backLeftMotor.follow(this.frontLeftMotor);
this.backRightMotor.follow(this.frontRightMotor);
this.differentialDrive = new DifferentialDrive(this.frontLeftMotor, this.frontRightMotor);
// I currently dont know to real parameters of our robot's driveTrain, these are temp variables
this.differentialDriveSim = new DifferentialDrivetrainSim(DCMotor.getCIM(2), Constants.kGearRatio, 2.1, 26.5, Units.inchesToMeters(Constants.kWheelRadiusInches), 0.546, null);
}
public WPI_TalonFX getBackLeftMotor(){return this.backLeftMotor;}
public TalonFXSimCollection getbackLeftMotorSim(){return this.backLeftMotor.getSimCollection();}
public TalonFXSimCollection getbackRightMotor(){return this.backRightMotor.getSimCollection();}
public TalonFXSimCollection getfrontLeftMotor(){return this.frontLeftMotor.getSimCollection();}
public TalonFXSimCollection getfrontRightMotor(){return this.frontRightMotor.getSimCollection();}
public DifferentialDrivetrainSim getdifferentialDriveSim(){return this.differentialDriveSim;}
public void robotArcadeDrive(double move, double rot){
if (move < 0.05) {move = 0;}
if (rot < 0.05) {rot = 0;}
differentialDrive.arcadeDrive(move, rot);
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
}
// 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.math.util.Units;
/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
* constants. This class should not be used for any other purpose. All constants should be declared
* globally (i.e. public static). Do not put anything functional in this class.
*
* <p>It is advised to statically import this class (or one of its inner classes) wherever the
* constants are needed, to reduce verbosity.
*/
public final class Constants {
// Speed controller ports
public static final int kBackLeftMotor = 1;
public static final int kBackFrontMotor = 2;
public static final int kFrontLeftMotor = 3;
public static final int kFrontRightMotor = 4;
// Joystick
public static final int kJoystickPort = 0;
public static final int kJoystickBButton = 2;
// Wpi encoder
public static final int kResetEncoder = 0;
// Autonomous command
public static final double kAutoSpeed = .5;
// Simulataion values
public static final double kUpdateTime = 0.02;
public static final int kCountsPerRev = 4096;
public static final double kWheelRadiusInches = 3;
public static final double kSensorGearRatio = 1.0;
public static final double kGearRatio = 10.71;
// Const methods
public static int distanceToNativeUnits(double positionMeters){
double wheelRotations = positionMeters/(2 * Math.PI * Units.inchesToMeters(kWheelRadiusInches));
double motorRotations = wheelRotations * kSensorGearRatio;
int sensorCounts = (int)(motorRotations * kCountsPerRev);
return sensorCounts;
}
}
// 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.RobotController;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
@SuppressWarnings("unused")
private RobotContainer robotContainer;
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
robotContainer = new RobotContainer();
}
/**
* This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
* that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();
}
/** This function is called once each time the robot enters Disabled mode. */
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
public void autonomousInit() {
}
/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}
@Override
public void testInit() {
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
}
/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {}
/** This function is called once when the robot is first started up. */
@Override
public void simulationInit() {}
/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {
RobotContainer.driveArcade.getfrontLeftMotor().setBusVoltage(RobotController.getBatteryVoltage());
RobotContainer.driveArcade.getfrontRightMotor().setBusVoltage(RobotController.getBatteryVoltage());
RobotContainer.driveArcade.getdifferentialDriveSim().setInputs(RobotContainer.driveArcade.getfrontLeftMotor().getMotorOutputLeadVoltage(), RobotContainer.driveArcade.getfrontRightMotor().getMotorOutputLeadVoltage() * -1);
RobotContainer.driveArcade.getdifferentialDriveSim().update(Constants.kUpdateTime);
// RobotContainer.driveArcade.getfrontLeftMotor().setQuadratureRawPosition(Constants.distanceToNativeUnits(
// RobotContainer.driveArcade.getdifferentialDriveSim().getLeftPositionMeters()
// ));
}
}