Skip to content

Commit 3341d0c

Browse files
authored
Merge pull request #102 from errorcodexero/bugfixes-postcais
Potential fix for oscillation
2 parents 512f521 + 69446c0 commit 3341d0c

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/main/java/frc/robot/commands/robot/RobotCommands.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public static Command shootHub(Shooter shooter, Hopper hopper, IntakeSubsystem i
3636
BooleanSupplier shouldXWheels =
3737
() -> drive.rotationIsNear(RobotState.rotationToHub(), ShooterConstants.xWheelTolerance);
3838

39+
BooleanSupplier shouldRotateAgain =
40+
() -> !drive.rotationIsNear(RobotState.rotationToHub(), ShooterConstants.unXWheelTolerance);
41+
3942
return shootHubNoAim(shooter, hopper, intake, drive).alongWith(
4043
DriveCommands.joystickDriveAtAngle(
4144
drive,
@@ -44,7 +47,7 @@ public static Command shootHub(Shooter shooter, Hopper hopper, IntakeSubsystem i
4447
RobotState::rotationToHub
4548
)
4649
.until(shouldXWheels)
47-
.andThen(drive.stopWithXCmd(), drive.idle().onlyWhile(shouldXWheels))
50+
.andThen(drive.stopWithXCmd(), drive.idle().until(shouldRotateAgain))
4851
.repeatedly()
4952
);
5053
}

src/main/java/frc/robot/subsystems/drive/Drive.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
package frc.robot.subsystems.drive;
1515

16+
import static edu.wpi.first.units.Units.Degrees;
1617
import static edu.wpi.first.units.Units.MetersPerSecond;
18+
import static edu.wpi.first.units.Units.Radians;
1719
import static edu.wpi.first.units.Units.Volts;
20+
import static edu.wpi.first.units.Units.derive;
1821

1922
import java.util.concurrent.locks.Lock;
2023
import java.util.concurrent.locks.ReentrantLock;
@@ -51,6 +54,7 @@
5154
import edu.wpi.first.math.numbers.N1;
5255
import edu.wpi.first.math.numbers.N3;
5356
import edu.wpi.first.math.system.plant.DCMotor;
57+
import edu.wpi.first.units.AngleUnit;
5458
import edu.wpi.first.units.measure.Angle;
5559
import edu.wpi.first.units.measure.AngularVelocity;
5660
import edu.wpi.first.units.measure.LinearVelocity;
@@ -59,6 +63,7 @@
5963
import edu.wpi.first.wpilibj.DriverStation;
6064
import edu.wpi.first.wpilibj.DriverStation.Alliance;
6165
import edu.wpi.first.wpilibj2.command.Command;
66+
import edu.wpi.first.wpilibj2.command.Commands;
6267
import edu.wpi.first.wpilibj2.command.SubsystemBase;
6368
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
6469
import frc.robot.Constants;
@@ -447,7 +452,8 @@ public Rotation2d getRotation() {
447452

448453
/** Whether the rotation of the robot is near to a target. */
449454
public boolean rotationIsNear(Rotation2d target, Angle tolerance) {
450-
return target.getMeasure().isNear(getRotation().getMeasure(), tolerance);
455+
var difference = Degrees.of(target.minus(getRotation()).getMeasure().abs(Degrees));
456+
return difference.lt(tolerance);
451457
}
452458

453459
/** Resets the current odometry pose. */

src/main/java/frc/robot/subsystems/shooter/ShooterConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class ShooterConstants {
3939
public static final Angle defenseTolerance = Degrees.of(7.5);
4040

4141
public static final Angle xWheelTolerance = Degrees.of(1);
42+
public static final Angle unXWheelTolerance = Degrees.of(3);
4243

4344
public static final Distance allowedTrenchDistance = Meters.of(1.0);
4445

0 commit comments

Comments
 (0)