Implement new Command Based Framework

This commit is contained in:
Keenan D. Buckley
2020-01-05 18:59:50 -07:00
parent 6fb373969d
commit c52bbdd2ee
13 changed files with 185 additions and 314 deletions
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 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. */
@@ -7,46 +7,46 @@
package frc4388.robot.commands.Drive;
import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.Robot;
import frc4388.robot.RobotContainer;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.subsystems.Drive;
import frc4388.utility.controller.IHandController;
public class DriveWithJoystick extends Command {
public class DriveWithJoystick extends CommandBase {
private final Drive m_drive;
private final IHandController m_driverXbox;
public double m_inputMove, m_inputSteer;
public DriveWithJoystick() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
/**
* Creates a new DriveWithJoystick, driving the robot with the given controller
*/
public DriveWithJoystick(Drive subsystem, IHandController controller) {
m_drive = subsystem;
m_driverXbox = controller;
addRequirements(m_drive);
}
// Called just before this Command runs the first time
// Called when the command is initially scheduled.
@Override
protected void initialize() {
public void initialize() {
}
// Called repeatedly when this Command is scheduled to run
// Called every time the scheduler runs while the command is scheduled.
@Override
protected void execute() {
m_inputMove = Robot.m_robotContainer.getDriverController().getLeftYAxis();
m_inputSteer = -(Robot.m_robotContainer.getDriverController().getRightXAxis());
RobotContainer.m_robotDrive.driveWithInput(m_inputMove, m_inputSteer);
public void execute() {
m_inputMove = m_driverXbox.getLeftYAxis();
m_inputSteer = m_driverXbox.getRightXAxis();
m_drive.driveWithInput(m_inputMove, m_inputSteer);
}
// Make this return true when this Command no longer needs to run execute()
// Called once the command ends or is interrupted.
@Override
protected boolean isFinished() {
public void end(boolean interrupted) {
}
// Returns true when the command should end.
@Override
public 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() {
}
}
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 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. */
@@ -7,40 +7,41 @@
package frc4388.robot.commands.Drive;
import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.RobotContainer;
import edu.wpi.first.wpilibj2.command.CommandBase;
public class GamerMove extends Command {
public GamerMove() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
import frc4388.robot.subsystems.Drive;
public class GamerMove extends CommandBase {
private final Drive m_drive;
/**
* Creates a new GamerMove.
*/
public GamerMove(Drive subsystem) {
m_drive = subsystem;
addRequirements(m_drive);
}
// Called just before this Command runs the first time
// Called when the command is initially scheduled.
@Override
protected void initialize() {
public void initialize() {
}
// Called repeatedly when this Command is scheduled to run
// Called every time the scheduler runs while the command is scheduled.
@Override
protected void execute() {
RobotContainer.m_robotDrive.driveWithInput(0, 1);
public void execute() {
m_drive.driveWithInput(0, 1);
}
// Make this return true when this Command no longer needs to run execute()
// Called once the command ends or is interrupted.
@Override
protected boolean isFinished() {
public void end(boolean interrupted) {
}
// Returns true when the command should end.
@Override
public 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() {
}
}
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 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. */
@@ -7,44 +7,28 @@
package frc4388.robot.commands.LED;
import frc4388.robot.RobotContainer;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import frc4388.robot.constants.LEDPatterns;
import frc4388.robot.subsystems.LED;
import edu.wpi.first.wpilibj.command.Command;
public class SetLEDPattern extends Command {
// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
public class SetLEDPattern extends InstantCommand {
private final LED m_led;
public static LEDPatterns m_pattern;
public SetLEDPattern(LEDPatterns pattern) {
public SetLEDPattern(LED subsystem, LEDPatterns pattern) {
m_led = subsystem;
m_pattern = pattern;
addRequirements(m_led);
}
// Called just before this Command runs the first time
// Called when the command is initially scheduled.
@Override
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
RobotContainer.m_robotLED.setPattern(m_pattern);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return true;
}
// 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() {
public void initialize() {
m_led.setPattern(m_pattern);
}
}
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 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. */
@@ -7,39 +7,41 @@
package frc4388.robot.commands.LED;
import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.RobotContainer;
import edu.wpi.first.wpilibj2.command.CommandBase;
public class UpdateLED extends Command {
public UpdateLED() {
// Use requires() here to declare subsystem dependencies
import frc4388.robot.subsystems.LED;
public class UpdateLED extends CommandBase {
private final LED m_LED;
/**
* Creates a new UpdateLED that continually runs updateLED in the LED subsystem.
*/
public UpdateLED(LED subsystem) {
m_LED = subsystem;
addRequirements(m_LED);
}
// Called just before this Command runs the first time
// Called when the command is initially scheduled.
@Override
protected void initialize() {
public void initialize() {
}
// Called repeatedly when this Command is scheduled to run
// Called every time the scheduler runs while the command is scheduled.
@Override
protected void execute() {
RobotContainer.m_robotLED.updateLED();
public void execute() {
m_LED.updateLED();
}
// Make this return true when this Command no longer needs to run execute()
// Called once the command ends or is interrupted.
@Override
protected boolean isFinished() {
public void end(boolean interrupted) {
}
// Returns true when the command should end.
@Override
public 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() {
}
}