Skip to content

Commit

Permalink
make drive template extend subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
linglejack06 committed Nov 14, 2024
1 parent 497822a commit f268c65
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package coppercore.wpilib_interface;

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

public interface DriveTemplate {
public interface DriveTemplate extends Subsystem {
public void setGoalSpeeds(ChassisSpeeds goalSpeeds, boolean fieldCentric);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,33 @@ public class DriveWithJoysticks extends Command {
private double maxAngularVelocity;

public DriveWithJoysticks(
DriveTemplate drive, CommandJoystick leftJoystick, CommandJoystick rightJoystick, double maxLinearVelocity, double maxAngularVelocity) {
DriveTemplate drive,
CommandJoystick leftJoystick,
CommandJoystick rightJoystick,
double maxLinearVelocity,
double maxAngularVelocity) {
this.drive = drive;
this.leftJoystick = leftJoystick;
this.rightJoystick = rightJoystick;
this.maxLinearVelocity = maxLinearVelocity;
this.maxAngularVelocity = maxAngularVelocity;

addRequirements(this.drive);
}

@Override
public void execute() {
Translation2d linearSpeeds = getLinearVelocity(leftJoystick.getX(), leftJoystick.getY());
Translation2d linearSpeeds = getLinearVelocity(-leftJoystick.getX(), -leftJoystick.getY());

double omega = Deadband.oneAxisDeadband(rightJoystick.getX(), 0.1);
double omega = Deadband.oneAxisDeadband(-rightJoystick.getX(), 0.1);
omega = Math.copySign(omega * omega, omega);

drive.setGoalSpeeds(new ChassisSpeeds(linearSpeeds.getX() * maxLinearVelocity, linearSpeeds.getY() * maxLinearVelocity, omega * maxAngularVelocity), true);
drive.setGoalSpeeds(
new ChassisSpeeds(
linearSpeeds.getX() * maxLinearVelocity,
linearSpeeds.getY() * maxLinearVelocity,
omega * maxAngularVelocity),
true);
}

public Translation2d getLinearVelocity(double x, double y) {
Expand Down
26 changes: 12 additions & 14 deletions wpilib_interface/src/main/java/frc/robot/BuildConstants.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package frc.robot;

/**
* Automatically generated file containing build version information.
*/
/** Automatically generated file containing build version information. */
public final class BuildConstants {
public static final String MAVEN_GROUP = "com.github.team401";
public static final String MAVEN_NAME = "wpi_interface";
public static final String VERSION = "0.0";
public static final int GIT_REVISION = 31;
public static final String GIT_SHA = "6665ac076ea8c0effafb5558d88433ff386cf7b6";
public static final String GIT_DATE = "2024-10-07 18:03:40 EDT";
public static final String GIT_BRANCH = "drive-command";
public static final String BUILD_DATE = "2024-11-11 19:38:24 EST";
public static final long BUILD_UNIX_TIME = 1731371904305L;
public static final int DIRTY = 1;
public static final String MAVEN_GROUP = "com.github.team401";
public static final String MAVEN_NAME = "wpilib_interface";
public static final String VERSION = "0.0";
public static final int GIT_REVISION = 35;
public static final String GIT_SHA = "497822ac6367923d18b42fc721160171e690af59";
public static final String GIT_DATE = "2024-11-13 18:53:56 EST";
public static final String GIT_BRANCH = "drive-command";
public static final String BUILD_DATE = "2024-11-13 19:02:59 EST";
public static final long BUILD_UNIX_TIME = 1731542579980L;
public static final int DIRTY = 1;

private BuildConstants(){}
private BuildConstants() {}
}

0 comments on commit f268c65

Please sign in to comment.