Implement new RobotContainer.java and Constants.java Classes

- OI.java has been deprecated and replaced with RobotContainer.java
- RobotMap.java has been deprecated and replaced with Constants.java
- Changes have been made to use the new classes without errors; some of these changes will be changed in the future
This commit is contained in:
Keenan D. Buckley
2020-01-05 17:35:52 -07:00
parent ec2412a31e
commit 6fb373969d
13 changed files with 134 additions and 112 deletions
@@ -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.
*
* <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 {
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;
}
}
+2
View File
@@ -17,6 +17,8 @@ import frc4388.utility.controller.XboxController;
/** /**
* This class is the glue that binds the controls on the physical operator * 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. * interface to the commands and command groups that allow control of the robot.
*
* @deprecated
*/ */
public class OI { public class OI {
//// CREATING BUTTONS //// CREATING BUTTONS
+5 -17
View File
@@ -10,12 +10,6 @@ package frc4388.robot;
import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler; 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 * The VM is configured to automatically run this class, and to call the
@@ -25,13 +19,8 @@ import frc4388.robot.subsystems.LED;
* project. * project.
*/ */
public class Robot extends TimedRobot { 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; Command m_autonomousCommand;
SendableChooser<Command> m_chooser = new SendableChooser<>(); public static RobotContainer m_robotContainer;
/** /**
* This function is run when the robot is first started up and should be * This function is run when the robot is first started up and should be
@@ -39,10 +28,9 @@ public class Robot extends TimedRobot {
*/ */
@Override @Override
public void robotInit() { public void robotInit() {
m_oi = new OI(); // Instantiate our RobotContainer. This will perform all our button bindings, and put our
m_chooser.setDefaultOption("Default Auto", new ExampleCommand()); // autonomous chooser on the dashboard.
// chooser.addOption("My Auto", new MyAutoCommand()); m_robotContainer = new RobotContainer();
SmartDashboard.putData("Auto mode", m_chooser);
} }
/** /**
@@ -84,7 +72,7 @@ public class Robot extends TimedRobot {
*/ */
@Override @Override
public void autonomousInit() { public void autonomousInit() {
m_autonomousCommand = m_chooser.getSelected(); m_autonomousCommand = m_robotContainer.getAutonomousCommand();
/* /*
* String autoSelected = SmartDashboard.getString("Auto Selector", * String autoSelected = SmartDashboard.getString("Auto Selector",
@@ -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();
}
}
@@ -12,6 +12,8 @@ package frc4388.robot;
* to a variable name. This provides flexibility changing wiring, makes checking * to a variable name. This provides flexibility changing wiring, makes checking
* the wiring easier and significantly reduces the number of magic numbers * the wiring easier and significantly reduces the number of magic numbers
* floating around. * floating around.
*
* @deprecated
*/ */
public class RobotMap { public class RobotMap {
// For example to map the left and right motors, you could define the // For example to map the left and right motors, you could define the
@@ -8,8 +8,8 @@
package frc4388.robot.commands.Drive; package frc4388.robot.commands.Drive;
import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.OI;
import frc4388.robot.Robot; import frc4388.robot.Robot;
import frc4388.robot.RobotContainer;
public class DriveWithJoystick extends Command { public class DriveWithJoystick extends Command {
@@ -18,7 +18,6 @@ public class DriveWithJoystick extends Command {
public DriveWithJoystick() { public DriveWithJoystick() {
// Use requires() here to declare subsystem dependencies // Use requires() here to declare subsystem dependencies
// eg. requires(chassis); // eg. requires(chassis);
requires(Robot.m_Drive);
} }
// Called just before this Command runs the first time // 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 // Called repeatedly when this Command is scheduled to run
@Override @Override
protected void execute() { protected void execute() {
m_inputMove = OI.getInstance().getDriverController().getLeftYAxis(); m_inputMove = Robot.m_robotContainer.getDriverController().getLeftYAxis();
m_inputSteer = -(OI.getInstance().getDriverController().getRightXAxis()); m_inputSteer = -(Robot.m_robotContainer.getDriverController().getRightXAxis());
Robot.m_Drive.driveWithInput(m_inputMove, m_inputSteer); RobotContainer.m_robotDrive.driveWithInput(m_inputMove, m_inputSteer);
} }
// Make this return true when this Command no longer needs to run execute() // Make this return true when this Command no longer needs to run execute()
@@ -8,13 +8,12 @@
package frc4388.robot.commands.Drive; package frc4388.robot.commands.Drive;
import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.Robot; import frc4388.robot.RobotContainer;
public class GamerMove extends Command { public class GamerMove extends Command {
public GamerMove() { public GamerMove() {
// Use requires() here to declare subsystem dependencies // Use requires() here to declare subsystem dependencies
// eg. requires(chassis); // eg. requires(chassis);
requires(Robot.m_Drive);
} }
// Called just before this Command runs the first time // 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 // Called repeatedly when this Command is scheduled to run
@Override @Override
protected void execute() { 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() // Make this return true when this Command no longer needs to run execute()
@@ -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() {
}
}
@@ -7,7 +7,7 @@
package frc4388.robot.commands.LED; package frc4388.robot.commands.LED;
import frc4388.robot.Robot; import frc4388.robot.RobotContainer;
import frc4388.robot.constants.LEDPatterns; import frc4388.robot.constants.LEDPatterns;
import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Command;
@@ -17,7 +17,6 @@ public class SetLEDPattern extends Command {
public static LEDPatterns m_pattern; public static LEDPatterns m_pattern;
public SetLEDPattern(LEDPatterns pattern) { public SetLEDPattern(LEDPatterns pattern) {
requires(Robot.m_led);
m_pattern = pattern; m_pattern = pattern;
} }
@@ -29,7 +28,7 @@ public class SetLEDPattern extends Command {
// Called repeatedly when this Command is scheduled to run // Called repeatedly when this Command is scheduled to run
@Override @Override
protected void execute() { 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() // Make this return true when this Command no longer needs to run execute()
@@ -8,12 +8,11 @@
package frc4388.robot.commands.LED; package frc4388.robot.commands.LED;
import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.Robot; import frc4388.robot.RobotContainer;
public class UpdateLED extends Command { public class UpdateLED extends Command {
public UpdateLED() { public UpdateLED() {
// Use requires() here to declare subsystem dependencies // Use requires() here to declare subsystem dependencies
requires(Robot.m_led);
} }
// Called just before this Command runs the first time // 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 // Called repeatedly when this Command is scheduled to run
@Override @Override
protected void execute() { protected void execute() {
Robot.m_led.updateLED(); RobotContainer.m_robotLED.updateLED();
} }
// Make this return true when this Command no longer needs to run execute() // Make this return true when this Command no longer needs to run execute()
@@ -12,7 +12,8 @@ import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import frc4388.robot.RobotMap;
import frc4388.robot.Constants.DriveConstants;
import frc4388.robot.commands.Drive.DriveWithJoystick; import frc4388.robot.commands.Drive.DriveWithJoystick;
/** /**
@@ -22,10 +23,10 @@ public class Drive extends Subsystem {
// Put methods for controlling this subsystem // Put methods for controlling this subsystem
// here. Call these from Commands. // 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_leftFrontMotor = new WPI_TalonSRX(DriveConstants.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_rightFrontMotor = new WPI_TalonSRX(DriveConstants.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_leftBackMotor = new WPI_TalonSRX(DriveConstants.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_rightBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_BACK_CAN_ID);
public static DifferentialDrive m_driveTrain = new DifferentialDrive(m_leftFrontMotor, m_rightFrontMotor); public static DifferentialDrive m_driveTrain = new DifferentialDrive(m_leftFrontMotor, m_rightFrontMotor);
@@ -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());
}
}
@@ -7,13 +7,14 @@
package frc4388.robot.subsystems; 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.Spark;
import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; 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 * 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 static Spark LEDController;
public LED(){ public LED(){
LEDController = new Spark(RobotMap.LED_SPARK_ID); LEDController = new Spark(LEDConstants.LED_SPARK_ID);
setPattern(LEDPatterns.FOREST_WAVES); setPattern(LEDPatterns.FOREST_WAVES);
LEDController.set(currentLED); LEDController.set(currentLED);
} }