Skip to content

Commit

Permalink
Fix field oriented drive (#19)
Browse files Browse the repository at this point in the history
* "back/select" button resets odometry
* Increased joystick deadband to prevent drift
  • Loading branch information
BrownGenius authored Jan 27, 2024
1 parent 6b2773e commit 3f5779e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ private void configureBindings() {
drive.setDefaultCommand(
new DriveCommand(
drive,
() -> MathUtil.applyDeadband(-controller.getLeftY(), 0.01),
() -> MathUtil.applyDeadband(-controller.getLeftX(), 0.01),
() -> MathUtil.applyDeadband(-controller.getRightX(), 0.01)));
() -> MathUtil.applyDeadband(-controller.getLeftY(), 0.05),
() -> MathUtil.applyDeadband(-controller.getLeftX(), 0.05),
() -> MathUtil.applyDeadband(-controller.getRightX(), 0.05)));
// TODO: Move deadband to constants file

controller
.start()
.onTrue(
new InstantCommand(() -> drive.setFieldOrientedDrive(!drive.isFieldOrientedDrive())));

controller.back().onTrue(new InstantCommand(() -> drive.resetOdometry()));
}

public Command getAutonomousCommand() {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/frc/robot/subsystems/drive/DriveSwerveYAGSL.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.Filesystem;
import java.io.File;
import org.littletonrobotics.junction.AutoLogOutput;
import swervelib.SwerveDrive;
import swervelib.parser.SwerveParser;

public class DriveSwerveYAGSL extends DriveBase {
private final double maximumSpeed =
Units.feetToMeters(2); // * TODO: Calculate actual max speed */
Units.feetToMeters(4.5); // * TODO: Calculate actual max speed */
private final File swerveJsonDirectory =
new File(Filesystem.getDeployDirectory(), "swervePracticeBot");
private SwerveDrive swerveDrive;
private boolean fieldOrientedDrive = false;
@AutoLogOutput private boolean fieldOrientedDrive = false;

public DriveSwerveYAGSL() {
try {
Expand Down Expand Up @@ -49,4 +51,8 @@ public void setFieldOrientedDrive(boolean enable) {
public boolean isFieldOrientedDrive() {
return fieldOrientedDrive;
}

public void resetOdometry() {
swerveDrive.resetOdometry(new Pose2d());
}
}

0 comments on commit 3f5779e

Please sign in to comment.