diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java new file mode 100644 index 0000000..d5ab37e --- /dev/null +++ b/src/main/java/frc4388/robot/Constants.java @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018-2019 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 frc4388.robot; + +/** + * 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. + * + *

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 { + public static final class DriveConstants { + public static final int DRIVE_LEFT_FRONT_CAN_ID = 2; + public static final int DRIVE_RIGHT_FRONT_CAN_ID = 4; + public static final int DRIVE_LEFT_BACK_CAN_ID = 3; + public static final int DRIVE_RIGHT_BACK_CAN_ID = 5; + } + + public static final class LEDConstants { + public static final int LED_SPARK_ID = 0; + } + + public static final class OIConstants { + public static final int XBOX_DRIVER_ID = 0; + public static final int XBOX_OPERATOR_ID = 1; + } +} diff --git a/src/main/java/frc4388/robot/OI.java b/src/main/java/frc4388/robot/OI.java index e97b4bb..2232d03 100644 --- a/src/main/java/frc4388/robot/OI.java +++ b/src/main/java/frc4388/robot/OI.java @@ -17,6 +17,8 @@ import frc4388.utility.controller.XboxController; /** * This class is the glue that binds the controls on the physical operator * interface to the commands and command groups that allow control of the robot. + * + * @deprecated */ public class OI { //// CREATING BUTTONS diff --git a/src/main/java/frc4388/robot/Robot.java b/src/main/java/frc4388/robot/Robot.java index 6cd6668..b2988cb 100644 --- a/src/main/java/frc4388/robot/Robot.java +++ b/src/main/java/frc4388/robot/Robot.java @@ -10,12 +10,6 @@ package frc4388.robot; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Scheduler; -import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import frc4388.robot.commands.ExampleCommand; -import frc4388.robot.subsystems.Drive; -import frc4388.robot.subsystems.ExampleSubsystem; -import frc4388.robot.subsystems.LED; /** * The VM is configured to automatically run this class, and to call the @@ -25,13 +19,8 @@ import frc4388.robot.subsystems.LED; * project. */ public class Robot extends TimedRobot { - public static ExampleSubsystem m_subsystem = new ExampleSubsystem(); - public static LED m_led = new LED(); - public static Drive m_Drive = new Drive(); - public static OI m_oi; - Command m_autonomousCommand; - SendableChooser m_chooser = new SendableChooser<>(); + public static RobotContainer m_robotContainer; /** * This function is run when the robot is first started up and should be @@ -39,10 +28,9 @@ public class Robot extends TimedRobot { */ @Override public void robotInit() { - m_oi = new OI(); - m_chooser.setDefaultOption("Default Auto", new ExampleCommand()); - // chooser.addOption("My Auto", new MyAutoCommand()); - SmartDashboard.putData("Auto mode", m_chooser); + // Instantiate our RobotContainer. This will perform all our button bindings, and put our + // autonomous chooser on the dashboard. + m_robotContainer = new RobotContainer(); } /** @@ -84,7 +72,7 @@ public class Robot extends TimedRobot { */ @Override public void autonomousInit() { - m_autonomousCommand = m_chooser.getSelected(); + m_autonomousCommand = m_robotContainer.getAutonomousCommand(); /* * String autoSelected = SmartDashboard.getString("Auto Selector", diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java new file mode 100644 index 0000000..7f4d50a --- /dev/null +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -0,0 +1,70 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018-2019 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 frc4388.robot; + +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.command.Command; +import edu.wpi.first.wpilibj.command.InstantCommand; +import frc4388.robot.Constants.*; +import frc4388.robot.subsystems.Drive; +import frc4388.robot.subsystems.LED; +import frc4388.utility.controller.IHandController; +import frc4388.utility.controller.XboxController; + +/** + * This class is where the bulk of the robot should be declared. Since + * Command-based is a "declarative" paradigm, very little robot logic should + * actually be handled in the {@link Robot} periodic methods (other than the + * scheduler calls). Instead, the structure of the robot (including subsystems, + * commands, and button mappings) should be declared here. + */ +public class RobotContainer { + /* Subsystems */ + public static final Drive m_robotDrive = new Drive(); + public static final LED m_robotLED = new LED(); + + /* Controllers */ + XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID); + XboxController m_operatorXbox = new XboxController(OIConstants.XBOX_OPERATOR_ID); + + /** + * The container for the robot. Contains subsystems, OI devices, and commands. + */ + public RobotContainer() { + + } + + /** + * Use this to pass the autonomous command to the main {@link Robot} class. + * + * @return the command to run in autonomous + */ + public Command getAutonomousCommand() { + // no auto + return new InstantCommand(); + } + + public IHandController getDriverController() { + return m_driverXbox; + } + + public IHandController getOperatorController() + { + return m_operatorXbox; + } + + public Joystick getOperatorJoystick() + { + return m_operatorXbox.getJoyStick(); + } + + public Joystick getDriverJoystick() + { + return m_driverXbox.getJoyStick(); + } +} diff --git a/src/main/java/frc4388/robot/RobotMap.java b/src/main/java/frc4388/robot/RobotMap.java index 67aff89..2fce0f5 100644 --- a/src/main/java/frc4388/robot/RobotMap.java +++ b/src/main/java/frc4388/robot/RobotMap.java @@ -12,6 +12,8 @@ package frc4388.robot; * to a variable name. This provides flexibility changing wiring, makes checking * the wiring easier and significantly reduces the number of magic numbers * floating around. + * + * @deprecated */ public class RobotMap { // For example to map the left and right motors, you could define the diff --git a/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java b/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java index 572b875..14bcf21 100644 --- a/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java +++ b/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java @@ -8,8 +8,8 @@ package frc4388.robot.commands.Drive; import edu.wpi.first.wpilibj.command.Command; -import frc4388.robot.OI; import frc4388.robot.Robot; +import frc4388.robot.RobotContainer; public class DriveWithJoystick extends Command { @@ -18,7 +18,6 @@ public class DriveWithJoystick extends Command { public DriveWithJoystick() { // Use requires() here to declare subsystem dependencies // eg. requires(chassis); - requires(Robot.m_Drive); } // Called just before this Command runs the first time @@ -29,9 +28,9 @@ public class DriveWithJoystick extends Command { // Called repeatedly when this Command is scheduled to run @Override protected void execute() { - m_inputMove = OI.getInstance().getDriverController().getLeftYAxis(); - m_inputSteer = -(OI.getInstance().getDriverController().getRightXAxis()); - Robot.m_Drive.driveWithInput(m_inputMove, m_inputSteer); + m_inputMove = Robot.m_robotContainer.getDriverController().getLeftYAxis(); + m_inputSteer = -(Robot.m_robotContainer.getDriverController().getRightXAxis()); + RobotContainer.m_robotDrive.driveWithInput(m_inputMove, m_inputSteer); } // Make this return true when this Command no longer needs to run execute() diff --git a/src/main/java/frc4388/robot/commands/Drive/GamerMove.java b/src/main/java/frc4388/robot/commands/Drive/GamerMove.java index b890aa5..6169453 100644 --- a/src/main/java/frc4388/robot/commands/Drive/GamerMove.java +++ b/src/main/java/frc4388/robot/commands/Drive/GamerMove.java @@ -8,13 +8,12 @@ package frc4388.robot.commands.Drive; import edu.wpi.first.wpilibj.command.Command; -import frc4388.robot.Robot; +import frc4388.robot.RobotContainer; public class GamerMove extends Command { public GamerMove() { // Use requires() here to declare subsystem dependencies // eg. requires(chassis); - requires(Robot.m_Drive); } // Called just before this Command runs the first time @@ -25,7 +24,7 @@ public class GamerMove extends Command { // Called repeatedly when this Command is scheduled to run @Override protected void execute() { - Robot.m_Drive.driveWithInput(0, 1); + RobotContainer.m_robotDrive.driveWithInput(0, 1); } // Make this return true when this Command no longer needs to run execute() diff --git a/src/main/java/frc4388/robot/commands/ExampleCommand.java b/src/main/java/frc4388/robot/commands/ExampleCommand.java deleted file mode 100644 index cb8a9f6..0000000 --- a/src/main/java/frc4388/robot/commands/ExampleCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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 frc4388.robot.commands; - -import edu.wpi.first.wpilibj.command.Command; -import frc4388.robot.Robot; - -/** - * An example command. You can replace me with your own command. - */ -public class ExampleCommand extends Command { - public ExampleCommand() { - // Use requires() here to declare subsystem dependencies - requires(Robot.m_subsystem); - } - - // Called just before this Command runs the first time - @Override - protected void initialize() { - } - - // Called repeatedly when this Command is scheduled to run - @Override - protected void execute() { - } - - // Make this return true when this Command no longer needs to run execute() - @Override - protected boolean isFinished() { - return false; - } - - // Called once after isFinished returns true - @Override - protected void end() { - } - - // Called when another command which requires one or more of the same - // subsystems is scheduled to run - @Override - protected void interrupted() { - } -} diff --git a/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java b/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java index 11c4447..152f81a 100644 --- a/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java +++ b/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java @@ -7,7 +7,7 @@ package frc4388.robot.commands.LED; -import frc4388.robot.Robot; +import frc4388.robot.RobotContainer; import frc4388.robot.constants.LEDPatterns; import edu.wpi.first.wpilibj.command.Command; @@ -17,7 +17,6 @@ public class SetLEDPattern extends Command { public static LEDPatterns m_pattern; public SetLEDPattern(LEDPatterns pattern) { - requires(Robot.m_led); m_pattern = pattern; } @@ -29,7 +28,7 @@ public class SetLEDPattern extends Command { // Called repeatedly when this Command is scheduled to run @Override protected void execute() { - Robot.m_led.setPattern(m_pattern); + RobotContainer.m_robotLED.setPattern(m_pattern); } // Make this return true when this Command no longer needs to run execute() diff --git a/src/main/java/frc4388/robot/commands/LED/UpdateLED.java b/src/main/java/frc4388/robot/commands/LED/UpdateLED.java index 3d6c374..44f195c 100644 --- a/src/main/java/frc4388/robot/commands/LED/UpdateLED.java +++ b/src/main/java/frc4388/robot/commands/LED/UpdateLED.java @@ -8,12 +8,11 @@ package frc4388.robot.commands.LED; import edu.wpi.first.wpilibj.command.Command; -import frc4388.robot.Robot; +import frc4388.robot.RobotContainer; public class UpdateLED extends Command { public UpdateLED() { // Use requires() here to declare subsystem dependencies - requires(Robot.m_led); } // Called just before this Command runs the first time @@ -24,7 +23,7 @@ public class UpdateLED extends Command { // Called repeatedly when this Command is scheduled to run @Override protected void execute() { - Robot.m_led.updateLED(); + RobotContainer.m_robotLED.updateLED(); } // Make this return true when this Command no longer needs to run execute() diff --git a/src/main/java/frc4388/robot/subsystems/Drive.java b/src/main/java/frc4388/robot/subsystems/Drive.java index 8d9b3b2..135afd0 100644 --- a/src/main/java/frc4388/robot/subsystems/Drive.java +++ b/src/main/java/frc4388/robot/subsystems/Drive.java @@ -12,7 +12,8 @@ import com.ctre.phoenix.motorcontrol.NeutralMode; import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import frc4388.robot.RobotMap; + +import frc4388.robot.Constants.DriveConstants; import frc4388.robot.commands.Drive.DriveWithJoystick; /** @@ -22,10 +23,10 @@ public class Drive extends Subsystem { // Put methods for controlling this subsystem // here. Call these from Commands. - public static WPI_TalonSRX m_leftFrontMotor = new WPI_TalonSRX(RobotMap.DRIVE_LEFT_FRONT_CAN_ID); - public static WPI_TalonSRX m_rightFrontMotor = new WPI_TalonSRX(RobotMap.DRIVE_RIGHT_FRONT_CAN_ID); - public static WPI_TalonSRX m_leftBackMotor = new WPI_TalonSRX(RobotMap.DRIVE_LEFT_BACK_CAN_ID); - public static WPI_TalonSRX m_rightBackMotor = new WPI_TalonSRX(RobotMap.DRIVE_RIGHT_BACK_CAN_ID); + public static WPI_TalonSRX m_leftFrontMotor = new WPI_TalonSRX(DriveConstants.DRIVE_LEFT_FRONT_CAN_ID); + public static WPI_TalonSRX m_rightFrontMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_FRONT_CAN_ID); + public static WPI_TalonSRX m_leftBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_LEFT_BACK_CAN_ID); + public static WPI_TalonSRX m_rightBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_BACK_CAN_ID); public static DifferentialDrive m_driveTrain = new DifferentialDrive(m_leftFrontMotor, m_rightFrontMotor); diff --git a/src/main/java/frc4388/robot/subsystems/ExampleSubsystem.java b/src/main/java/frc4388/robot/subsystems/ExampleSubsystem.java deleted file mode 100644 index 50ace89..0000000 --- a/src/main/java/frc4388/robot/subsystems/ExampleSubsystem.java +++ /dev/null @@ -1,24 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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 frc4388.robot.subsystems; - -import edu.wpi.first.wpilibj.command.Subsystem; - -/** - * An example subsystem. You can replace me with your own Subsystem. - */ -public class ExampleSubsystem extends Subsystem { - // Put methods for controlling this subsystem - // here. Call these from Commands. - - @Override - public void initDefaultCommand() { - // Set the default command for a subsystem here. - // setDefaultCommand(new MySpecialCommand()); - } -} diff --git a/src/main/java/frc4388/robot/subsystems/LED.java b/src/main/java/frc4388/robot/subsystems/LED.java index 3c66878..7dc940c 100644 --- a/src/main/java/frc4388/robot/subsystems/LED.java +++ b/src/main/java/frc4388/robot/subsystems/LED.java @@ -7,13 +7,14 @@ package frc4388.robot.subsystems; -import frc4388.robot.RobotMap; -import frc4388.robot.commands.LED.UpdateLED; -import frc4388.robot.constants.LEDPatterns; import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import frc4388.robot.Constants.LEDConstants; +import frc4388.robot.commands.LED.UpdateLED; +import frc4388.robot.constants.LEDPatterns; + /** * Allows for the control of a 5v LED Strip using a Rev Robotics Blinkin LED Driver */ @@ -23,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; public static Spark LEDController; public LED(){ - LEDController = new Spark(RobotMap.LED_SPARK_ID); + LEDController = new Spark(LEDConstants.LED_SPARK_ID); setPattern(LEDPatterns.FOREST_WAVES); LEDController.set(currentLED); }