'"kBrushless cannot be resolved or is not a field" error in FRC Java [closed]
Importer "kBrushless" states that is is not resolved of not a field. Any help?
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.RobotDriveBase.MotorType;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
// import edu.wpi.first.hal.FRCNetComm.tResourceType;
// import edu.wpi.first.hal.HAL;
import frc.robot.autos.*;
import frc.robot.commands.*;
import frc.robot.subsystems.*;
public class Robot2 extends TimedRobot {
private static final int leadDeviceID = 1;
private static final int followDeviceID = 2;
private static final int kJoystickPort = 0;
private CANSparkMax m_leadMotor;
private CANSparkMax m_followMotor;
private Joystick m_joystick;
@Override
public void robotInit() {
m_leadMotor = new CANSparkMax(leadDeviceID, MotorType.kBrushless);
m_followMotor = new CANSparkMax(followDeviceID, MotorType.kBrushless);
m_leadMotor.restoreFactoryDefaults();
m_followMotor.restoreFactoryDefaults();
}
}
This is also using the WPI libraries and FRC. This is also using all of the imported libraries, as it is shown below.
Solution 1:[1]
You are importing the wrong MotorType enum:
- the
edu.wpi.first.wpilibj.drive.RobotDriveBase.MotorTypedoesn't contain akBrushlessconstant. - it seems that you are using
CANSparkMax(because you writem_leadMotor = new CANSparkMax(leadDeviceID, MotorType.kBrushless);) - the [
CANSparkMaxconstructor](https://codedocs.revrobotics.com/java/com/revrobotics/cansparkmax#%3Cinit%3E(int,com.revrobotics.CANSparkMaxLowLevel.MotorType) takes as second parameter an instance ofCANSparkMaxLowLevel.MotorType, which has a constantkBrushless
Therefore it seems that you should replace
import edu.wpi.first.wpilibj.drive.RobotDriveBase.MotorType;
with
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
and probably also add
import com.revrobotics.CANSparkMax;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thomas Kläger |
