Skip to content

Commit

Permalink
Basic Drive Interface/Stub
Browse files Browse the repository at this point in the history
  • Loading branch information
BrownGenius committed Jan 13, 2024
1 parent 6953095 commit e1b86b2
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,40 @@

package frc.robot;

import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import frc.robot.commands.DriveBaseCommand;
import frc.robot.subsystems.drive.DriveBase;
import frc.robot.subsystems.drive.DriveSwerve;
import frc.robot.subsystems.drive.DriveTank;

public class RobotContainer {
public final XboxController controller;
public final DriveBase drivetrain;

public RobotContainer() {
controller = new XboxController(0);

boolean swerveBot = false;
boolean tankBot = false;

if (swerveBot) {
drivetrain = new DriveSwerve();
} else if (tankBot) {
drivetrain = new DriveTank();
} else {
drivetrain = new DriveBase();
}

configureBindings();
}

private void configureBindings() {}
private void configureBindings() {
drivetrain.setDefaultCommand(
new DriveBaseCommand(
drivetrain, () -> -controller.getLeftY(), () -> -controller.getLeftX()));
}

public Command getAutonomousCommand() {
return Commands.print("No autonomous command configured");
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/frc/robot/commands/DriveBaseCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package frc.robot.commands;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.drive.DriveBase;
import java.util.function.DoubleSupplier;

public class DriveBaseCommand extends Command {
DriveBase drive;
DoubleSupplier speed;
DoubleSupplier rot;

public DriveBaseCommand(DriveBase drive, DoubleSupplier speed, DoubleSupplier rot) {
this.drive = drive;
this.speed = speed;
this.rot = rot;

addRequirements(drive);
}

@Override
public void execute() {
ChassisSpeeds speeds =
new ChassisSpeeds(
speed.getAsDouble() * drive.getMaxLinearSpeed(),
0,
rot.getAsDouble() * drive.getMaxAngularSpeed());

drive.runVelocity(speeds);
}
}
21 changes: 21 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;

public interface Drive {
public void runVelocity(ChassisSpeeds speeds);

public double getMaxLinearSpeed();

public double getMaxAngularSpeed();

/*
public void stop();
public Pose2d getPose();
public void setPose(Pose2d Pose2d);
public Rotation2d getRotation();
*/
}
19 changes: 19 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class DriveBase extends SubsystemBase implements Drive {
public DriveBase() {}

public void runVelocity(ChassisSpeeds speeds) {}
;

public double getMaxLinearSpeed() {
return 0;
}

public double getMaxAngularSpeed() {
return 0;
}
}
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveSwerve.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;

public class DriveSwerve extends DriveBase {
@Override
public void runVelocity(ChassisSpeeds speeds) {
/* Swerve Controls Here */
}
}
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveTank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;

public class DriveTank extends DriveBase {
@Override
public void runVelocity(ChassisSpeeds speeds) {
/* Tank Controls Here */
}
}

0 comments on commit e1b86b2

Please sign in to comment.