Skip to content

Commit

Permalink
Merge pull request #77 from frc937/swerve-max-speed
Browse files Browse the repository at this point in the history
Swerve max speed
  • Loading branch information
MarissaKoglesby authored Feb 21, 2024
2 parents 73e4f2d + f41ad49 commit ec006a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants;
import frc.robot.RobotContainer;
import frc.robot.subsystems.Drive;
import java.util.function.Supplier;
Expand Down Expand Up @@ -46,9 +45,9 @@ public void initialize() {}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
double x = this.xSupplier.get() * Constants.Drive.MAX_SPEED;
double y = this.ySupplier.get() * Constants.Drive.MAX_SPEED;
double z = this.zSupplier.get() * Constants.Drive.MAX_ANGULAR_SPEED;
double x = this.xSupplier.get() * drive.getMaximumSpeed();
double y = this.ySupplier.get() * drive.getMaximumSpeed();
double z = this.zSupplier.get() * drive.getMaximumAngularSpeed();
Translation2d translation = new Translation2d(x, y);

drive.driveFieldOriented(translation, z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants;
import frc.robot.RobotContainer;
import frc.robot.subsystems.Drive;
import java.util.function.Supplier;
Expand All @@ -27,7 +25,6 @@
*/
public class DriveFieldOrientedHeadingSnapping extends Command {
private Drive drive;
private XboxController controller;
private final Supplier<Double> xSupplier, ySupplier, zSupplier;
private final Supplier<Boolean> upSupplier, downSupplier, leftSupplier, rightSupplier;

Expand All @@ -52,7 +49,6 @@ public DriveFieldOrientedHeadingSnapping(
Supplier<Boolean> downSupplier,
Supplier<Boolean> leftSupplier,
Supplier<Boolean> rightSupplier) {
this.controller = RobotContainer.driverController.getHID();
this.drive = RobotContainer.drive;
this.xSupplier = xSupplier;
this.ySupplier = ySupplier;
Expand Down Expand Up @@ -93,7 +89,7 @@ public void execute() {

Translation2d translation = SwerveController.getTranslation2d(desiredSpeeds);
if (headingX == 0 && headingY == 0 && Math.abs(zSupplier.get()) > 0) {
drive.driveFieldOriented(translation, zSupplier.get() * Constants.Drive.MAX_ANGULAR_SPEED);
drive.driveFieldOriented(translation, zSupplier.get() * drive.getMaximumAngularSpeed());
} else {
drive.driveFieldOriented(translation, desiredSpeeds.omegaRadiansPerSecond);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants;
import frc.robot.RobotContainer;
import frc.robot.subsystems.Drive;
import java.util.function.Supplier;
Expand Down Expand Up @@ -46,9 +45,9 @@ public void initialize() {}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
double x = xSupplier.get() * Constants.Drive.MAX_SPEED;
double y = ySupplier.get() * Constants.Drive.MAX_SPEED;
double z = zSupplier.get() * Constants.Drive.MAX_ANGULAR_SPEED;
double x = xSupplier.get() * drive.getMaximumSpeed();
double y = ySupplier.get() * drive.getMaximumSpeed();
double z = zSupplier.get() * drive.getMaximumAngularSpeed();
Translation2d translation = new Translation2d(x, y);

drive.driveRobotOriented(translation, z);
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/frc/robot/subsystems/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ public void enterXMode() {
drive.lockPose();
}

/**
* Gets the maximum speed the robot chassis can acheive in m/s.
*
* @return Maximum speed the robot chassis can acheive in m/s.
*/
public double getMaximumSpeed() {
return drive.getMaximumVelocity();
}

/**
* Gets the maximum angular speed the robot chassis can acheive in rad/s.
*
* @return Maximum angular speed the robot chassis can acheive in rad/s.
*/
public double getMaximumAngularSpeed() {
return drive.getMaximumAngularVelocity();
}

/**
* Set the heading correction capabilities of YAGSL. Should only be enabled when heading
* correction capabilities are in use
Expand Down

0 comments on commit ec006a1

Please sign in to comment.