Change Drive to operate on a command based model

This commit is contained in:
Keenan D. Buckley
2019-12-20 12:53:02 -07:00
parent 9cb8e6d6d6
commit cb904002ad
5 changed files with 122 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
plugins { plugins {
id "java" id "java"
id "edu.wpi.first.GradleRIO" version "2020.1.1-beta-2" id "edu.wpi.first.GradleRIO" version "2020.1.1-beta-4"
} }
def ROBOT_MAIN_CLASS = "frc4388.robot.Main" def ROBOT_MAIN_CLASS = "frc4388.robot.Main"
+13 -1
View File
@@ -8,6 +8,9 @@
package frc4388.robot; package frc4388.robot;
import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import frc4388.robot.commands.Drive.DriveWithJoystick;
import frc4388.robot.commands.Drive.GamerMove;
import frc4388.utility.controller.IHandController; import frc4388.utility.controller.IHandController;
import frc4388.utility.controller.XboxController; import frc4388.utility.controller.XboxController;
@@ -46,12 +49,16 @@ public class OI {
private static OI instance; private static OI instance;
private static XboxController m_driverXbox; public static XboxController m_driverXbox;
private static XboxController m_operatorXbox; private static XboxController m_operatorXbox;
public OI() { public OI() {
m_driverXbox = new XboxController(RobotMap.XBOX_DRIVER_ID); m_driverXbox = new XboxController(RobotMap.XBOX_DRIVER_ID);
m_operatorXbox = new XboxController(RobotMap.XBOX_OPERATOR_ID); m_operatorXbox = new XboxController(RobotMap.XBOX_OPERATOR_ID);
JoystickButton GamerMove = new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON);
GamerMove.whenPressed(new GamerMove());
GamerMove.whenReleased(new DriveWithJoystick());
} }
public static OI getInstance() { public static OI getInstance() {
@@ -74,4 +81,9 @@ public class OI {
{ {
return m_operatorXbox.getJoyStick(); return m_operatorXbox.getJoyStick();
} }
public Joystick getDriverJoystick()
{
return m_driverXbox.getJoyStick();
}
} }
@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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.Drive;
import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.OI;
import frc4388.robot.Robot;
public class DriveWithJoystick extends Command {
public double m_inputMove, m_inputSteer;
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
@Override
protected void initialize() {
}
// 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);
}
// 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() {
}
}
@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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.Drive;
import edu.wpi.first.wpilibj.command.Command;
import frc4388.robot.Robot;
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
@Override
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.m_Drive.gamerMove();
}
// 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() {
}
}
@@ -17,6 +17,8 @@ import edu.wpi.first.wpilibj.Talon;
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.RobotMap;
import frc4388.robot.commands.Drive.DriveWithJoystick;
import frc4388.robot.commands.Drive.GamerMove;
import frc4388.robot.OI; import frc4388.robot.OI;
import frc4388.robot.Robot; import frc4388.robot.Robot;
import frc4388.utility.controller.XboxController; import frc4388.utility.controller.XboxController;
@@ -61,17 +63,18 @@ public class Drive extends Subsystem {
m_rightBackMotor.setInverted(InvertType.FollowMaster); m_rightBackMotor.setInverted(InvertType.FollowMaster);
} }
@Override public void driveWithInput(double move, double steer){
public void periodic() { m_driveTrain.arcadeDrive(move, steer);
m_inputMove = OI.getInstance().getDriverController().getLeftYAxis(); }
m_inputSteer = -(OI.getInstance().getDriverController().getRightXAxis());
m_driveTrain.arcadeDrive(m_inputMove, m_inputSteer); public void gamerMove(){
m_driveTrain.arcadeDrive(0, 1);
} }
@Override @Override
public void initDefaultCommand() { public void initDefaultCommand() {
// Set the default command for a subsystem here. // Set the default command for a subsystem here.
// setDefaultCommand(new MySpecialCommand()); // setDefaultCommand(new MySpecialCommand());
setDefaultCommand(new DriveWithJoystick());
} }
} }