Skip to content

Commit

Permalink
Better driver controls (#30)
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

* implent OOP to inputted driver controls
  • Loading branch information
team6101 authored Mar 2, 2024
1 parent 749df0f commit a3d8781
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/main/java/frc/robot/InputtedDriverControls.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frc.robot;

import edu.wpi.first.wpilibj.XboxController;
import frc.robot.RobotComponents.DriveTrain;

public class InputtedDriverControls {

Expand All @@ -11,6 +12,7 @@ public static void setDriverController(XboxController xboxController) {
}

public static void onEveryFrame() {
DriveTrain.driveTank(controller.getLeftY(), controller.getRightY());
if (controller.getBButtonPressed()) {
stopAtFeedingDistance();
}
Expand All @@ -20,11 +22,6 @@ public static void onEveryFrame() {
if (controller.getXButtonPressed()) {
stopAtShootingDistance();
}
driveTank(controller.getLeftY(), controller.getRightY());
}

private static void driveTank(double leftY, double rightY) {
throw new UnsupportedOperationException("Unimplemented method 'driveTank'");
}

private static void stopAtShootingDistance() {
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.RobotComponents.DriveTrain;
import frc.robot.Vision.AprilTagHighlighter;
import frc.robot.auton.AutonAction;
import frc.robot.auton.AutonRoutes;
Expand Down Expand Up @@ -114,6 +115,7 @@ public void robotInit() {
System.out.println("Is drive right parent inverted at end?? " + driveRightParent.getInverted());

InputtedCoDriverControls.setCoDriverController(coDriverController);
InputtedDriverControls.setDriverController(driverController);
}

/**
Expand Down Expand Up @@ -207,17 +209,7 @@ public void teleopInit() {}
@Override
public void teleopPeriodic() {
teleopActionRunner.onEveryFrame();
// TODO: make slow mode
double leftY = driverController.getLeftY();
double rightY = driverController.getRightY();
QuickActions.stopDriveMotors();
if (Math.abs(leftY) > Constants.CONTROLLER_DEADZONE) {
driveLeftParent.set(leftY);
}
if (Math.abs(rightY) > Constants.CONTROLLER_DEADZONE) {
driveRightParent.set(rightY);
}
// aprilTagHighlighter.doEveryTeleopFrame(driverController);
InputtedDriverControls.onEveryFrame();
InputtedCoDriverControls.onEveryFrame();
}

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

import frc.robot.Constants;
import frc.robot.QuickActions;
import frc.robot.Robot;

public class DriveTrain {

public static void driveTank(double leftY, double rightY) {
QuickActions.stopDriveMotors();
if (Math.abs(leftY) > Constants.CONTROLLER_DEADZONE) {
Robot.motors.getDriveLeftChild().set(leftY);
}
if (Math.abs(rightY) > Constants.CONTROLLER_DEADZONE) {
Robot.motors.getDriveRightParent().set(rightY);
}
}
}

0 comments on commit a3d8781

Please sign in to comment.