Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Drive Interface/Stub #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */
}
}