Skip to content

Commit

Permalink
Better codriver controls (#28)
Browse files Browse the repository at this point in the history
* Rename stopAll to stopAllDriveMotors

* remove import

* Start more OOP approach to codriver controls

* implement OOP based codriver controls
  • Loading branch information
team6101 authored Mar 2, 2024
1 parent 2fa899e commit a6d7c63
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 66 deletions.
5 changes: 4 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public class Constants {

/*SHOOTER CONFIG*/
/**the amount of time we let the wheels rev up when shooting in seconds */
public static final double REV_TIME = 1.0;
public static final double SHOOTER_FLYWHEEL_STARTUP_TIME = 1.0;
/*The amount of seconds that the feeder should wait before turning off after shooting */
public static final double FEEDER_MOTOR_SHUTOFF_TIME = 0;

/*CLIMB CONFIG */
public static final double CLIMB_EXTENDED_ENCODER_POSITION = 5;
Expand Down Expand Up @@ -60,4 +62,5 @@ public class Constants {
/* ROTATION PID CONSTANTS */

public static final double ROTATION_ERROR_DEGREES = 5.;
public static final double SHOOTING_VELOCITY = 4000;
}
73 changes: 19 additions & 54 deletions src/main/java/frc/robot/InputtedCoDriverControls.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package frc.robot;

import edu.wpi.first.wpilibj.XboxController;
import frc.robot.auton.AutonShoot;
import frc.robot.auton.ExtendArms;
import frc.robot.auton.RetractArms;
import frc.robot.RobotComponents.Climber;
import frc.robot.RobotComponents.Intake;
import frc.robot.RobotComponents.Shooter;

public class InputtedCoDriverControls {

Expand All @@ -14,62 +14,27 @@ public static void setCoDriverController(XboxController xboxController) {
}

public static void onEveryFrame() {
Robot.motors.getFeeder().stopMotor();
if (controller.getAButton()) {
Robot.motors.getFeeder().set(30);
if (controller.getAButtonPressed()) {
Shooter.startFeedMotors();
}
if (controller.getXButtonPressed()) {
shootIntoSpeaker();
if (controller.getXButton()) {
Shooter.startShooterMotors();
} else {
Shooter.stopShooterMotors();
}
doShooterIntake();
Robot.motors.getIntake().stopMotor();

if (controller.getYButton()) {
doFloorIntake();
}
Robot.motors.getLeftClimb().stopMotor();
Robot.motors.getRightClimb().stopMotor();
if (controller.getStartButton()) {
//extendArms();
Robot.motors.getLeftClimb().set(Constants.CLIMB_EXTENSION_SPEED);
Robot.motors.getRightClimb().set(Constants.CLIMB_EXTENSION_SPEED);
}
if (controller.getBackButton()) {
//retractArms();
Robot.motors.getLeftClimb().set(Constants.CLIMB_RETRACTION_SPEED);
Robot.motors.getRightClimb().set(Constants.CLIMB_RETRACTION_SPEED);
Intake.startFloorIntake();
} else {
Intake.stopFloorIntake();
}
}

private static void doFloorIntake() {
Robot.motors.getIntake().set(.5);
//Robot.motors.getFeeder().set(.5);
}

private static void extendArms() {
Robot.getTeleopActionRunner().addActionToRun(new ExtendArms());
Robot.getTeleopActionRunner().removeActionsOfType(RetractArms.class);
}

private static void retractArms() {
Robot.getTeleopActionRunner().addActionToRun(new RetractArms());
Robot.getTeleopActionRunner().removeActionsOfType(ExtendArms.class);
}

private static void doShooterIntake() {
if (controller.getPOV() == 0) {
Robot.motors.getRightFlywheel().set(0.3);
Robot.motors.getLeftFlywheel().set(-0.3);
} else if (controller.getPOV() == 180) {
Robot.motors.getRightFlywheel().set(0);
Robot.motors.getLeftFlywheel().set(0);
if (controller.getStartButton()) {
Climber.manualExtendArms();
} else if (controller.getBackButton()) {
Climber.manualRetractArms();
} else {
Climber.stopClimbMotors();
}
}

private static void shootIntoSpeaker() {
Robot.getTeleopActionRunner().addActionToRun(new AutonShoot());
}

private static void dropIntoAmp() {
throw new UnsupportedOperationException("Unimplemented method 'dropIntoAmp'");
}
}
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/QuickActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class QuickActions {

public static void setAll(double percent) {
public static void setDriveMotors(double percent) {
Robot.motors.getDriveLeftParent().set(percent);
Robot.motors.getDriveRightParent().set(percent);
}

public static void stopAll() {
public static void stopDriveMotors() {
Robot.motors.getDriveLeftParent().set(0.0);
Robot.motors.getDriveRightParent().set(0.0);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package frc.robot;

import com.kauailabs.navx.frc.AHRS;
import com.revrobotics.CANSparkLowLevel.MotorType;
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj.SPI;
import edu.wpi.first.wpilibj.TimedRobot;
Expand Down Expand Up @@ -211,7 +210,7 @@ public void teleopPeriodic() {
// TODO: make slow mode
double leftY = driverController.getLeftY();
double rightY = driverController.getRightY();
QuickActions.stopAll();
QuickActions.stopDriveMotors();
if (Math.abs(leftY) > Constants.CONTROLLER_DEADZONE) {
driveLeftParent.set(leftY);
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/RobotComponents/Climber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot.RobotComponents;

import frc.robot.Constants;
import frc.robot.Robot;
import frc.robot.auton.ExtendArms;
import frc.robot.auton.RetractArms;

public class Climber {

private static void extendArms() {
Robot.getTeleopActionRunner().addActionToRun(new ExtendArms());
Robot.getTeleopActionRunner().removeActionsOfType(RetractArms.class);
}

private static void retractArms() {
Robot.getTeleopActionRunner().addActionToRun(new RetractArms());
Robot.getTeleopActionRunner().removeActionsOfType(ExtendArms.class);
}

public static void manualExtendArms() {
Robot.motors.getLeftClimb().set(Constants.CLIMB_EXTENSION_SPEED);
Robot.motors.getRightClimb().set(Constants.CLIMB_EXTENSION_SPEED);
}

public static void manualRetractArms() {
Robot.motors.getLeftClimb().set(Constants.CLIMB_RETRACTION_SPEED);
Robot.motors.getRightClimb().set(Constants.CLIMB_RETRACTION_SPEED);
}

public static void stopClimbMotors() {
Robot.motors.getLeftClimb().stopMotor();
Robot.motors.getRightClimb().stopMotor();
}
}
14 changes: 14 additions & 0 deletions src/main/java/frc/robot/RobotComponents/Intake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package frc.robot.RobotComponents;

import frc.robot.Robot;

public class Intake {

public static void startFloorIntake() {
Robot.motors.getIntake().set(.5);
}

public static void stopFloorIntake() {
Robot.motors.getIntake().stopMotor();
}
}
28 changes: 28 additions & 0 deletions src/main/java/frc/robot/RobotComponents/Shooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package frc.robot.RobotComponents;

import frc.robot.Constants;
import frc.robot.Robot;
import frc.robot.auton.AutonShoot;
import frc.robot.auton.AutonShooterFeed;

public class Shooter {

public static void startShooterMotors() {
Robot.motors.getLeftFlywheel().setVelocity(Constants.SHOOTING_VELOCITY);
Robot.motors.getRightFlywheel().setVelocity(Constants.SHOOTING_VELOCITY);
}

public static void stopShooterMotors() {
Robot.motors.getLeftFlywheel().stopMotor();
Robot.motors.getRightFlywheel().stopMotor();
}

public static void startFeedMotors() {
Robot.getTeleopActionRunner().removeActionsOfType(AutonShooterFeed.class);
Robot.getTeleopActionRunner().addActionToRun(new AutonShooterFeed());
}

public static void autoShootIntoSpeaker() {
Robot.getTeleopActionRunner().addActionToRun(new AutonShoot());
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/auton/AutonMoveInches.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public AutonMoveInches(double distance) {

@Override
public void shutdown() {
QuickActions.stopAll();
QuickActions.stopDriveMotors();
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/auton/AutonRotate.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public void initiate() {

@Override
public void shutdown() {
QuickActions.stopAll();
QuickActions.stopDriveMotors();
}
}
8 changes: 3 additions & 5 deletions src/main/java/frc/robot/auton/AutonShoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ public boolean isDone() {
Robot.motors.getFeeder().set(0.2);
Robot.motors.getIntake().set(.2);
}
if (Timer.getFPGATimestamp() >= revFinishedTime + 1.0) {
return true;
}
return false;

return Timer.getFPGATimestamp() >= revFinishedTime + 1.0;
}

@Override
public void initiate() {
Robot.motors.getLeftFlywheel().set(1.0);
Robot.motors.getRightFlywheel().set(-1.0);
revFinishedTime = Timer.getFPGATimestamp() + Constants.REV_TIME;
revFinishedTime = Timer.getFPGATimestamp() + Constants.SHOOTER_FLYWHEEL_STARTUP_TIME;
}

@Override
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/auton/AutonShooterFeed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package frc.robot.auton;

import edu.wpi.first.wpilibj.Timer;
import frc.robot.Constants;
import frc.robot.Robot;

public class AutonShooterFeed extends AutonAction {

private double revFinishedTime;

@Override
public boolean isDone() {
return Timer.getFPGATimestamp() > revFinishedTime;
}

@Override
public void initiate() {
Robot.motors.getFeeder().set(0.75);
revFinishedTime = Timer.getFPGATimestamp() + Constants.FEEDER_MOTOR_SHUTOFF_TIME;
}

@Override
public void shutdown() {
Robot.motors.getFeeder().stopMotor();
}
}

0 comments on commit a6d7c63

Please sign in to comment.