Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.

Commit eb56cc2

Browse files
authored
Merge pull request #34 from Gongoliers/3_19_2024_drive_testing
3 19 2024 drive testing
2 parents d465a5a + 5ff6eec commit eb56cc2

File tree

5 files changed

+31
-45
lines changed

5 files changed

+31
-45
lines changed

Diff for: src/main/java/frc/robot/RobotConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ public enum Subsystem {
5353
Subsystem.SHOOTER,
5454
Subsystem.SWERVE);
5555

56-
public static final Set<Subsystem> REAL_SUBSYSTEMS = ALL_SUBSYSTEMS;
56+
public static final Set<Subsystem> REAL_SUBSYSTEMS = EnumSet.of(Subsystem.ODOMETRY, Subsystem.SWERVE);
5757
}

Diff for: src/main/java/frc/robot/odometry/Odometry.java

+16-19
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class Odometry extends Subsystem {
4747
private final Field2d field;
4848

4949
/** List of functions to be called when pose is manually updated. */
50-
private final List<Consumer<Pose2d>> poseUpdateConsumers;
50+
private final List<Consumer<Rotation2d>> yawUpdateConsumers;
5151

5252
/** Creates a new instance of the odometry subsystem. */
5353
private Odometry() {
@@ -73,7 +73,7 @@ private Odometry() {
7373

7474
field = new Field2d();
7575

76-
poseUpdateConsumers = new ArrayList<Consumer<Pose2d>>();
76+
yawUpdateConsumers= new ArrayList<Consumer<Rotation2d>>();
7777
}
7878

7979
/**
@@ -102,11 +102,16 @@ public void periodic() {
102102

103103
@Override
104104
public void addToShuffleboard(ShuffleboardTab tab) {
105+
ShuffleboardLayout shouldFlip = Telemetry.addColumn(tab, "Should Flip?");
106+
107+
shouldFlip.addBoolean("Should Flip?", () -> AllianceFlipHelper.shouldFlip());
108+
105109
ShuffleboardLayout position = Telemetry.addColumn(tab, "Position");
106110

107111
position.addDouble("X (m)", () -> getPosition().getX());
108112
position.addDouble("Y (m)", () -> getPosition().getY());
109-
position.addDouble("Rotation (deg)", () -> getPosition().getRotation().getDegrees());
113+
position.addDouble("Field Rotation (deg)", () -> getFieldRelativeHeading().getDegrees());
114+
position.addDouble("Driver Rotation (deg)", () -> getDriverRelativeHeading().getDegrees());
110115

111116
ShuffleboardLayout velocity = Telemetry.addColumn(tab, "Velocity");
112117

@@ -146,13 +151,9 @@ public Rotation2d getFieldRelativeHeading() {
146151
* alliance.
147152
*/
148153
public Rotation2d getDriverRelativeHeading() {
149-
Rotation2d fieldRelativeHeading = getFieldRelativeHeading();
150-
151-
if (AllianceFlipHelper.shouldFlip()) {
152-
return fieldRelativeHeading.plus(Rotation2d.fromDegrees(180));
153-
}
154+
gyroscope.update(gyroscopeValues);
154155

155-
return fieldRelativeHeading;
156+
return Rotation2d.fromRotations(gyroscopeValues.yawRotations);
156157
}
157158

158159
/**
@@ -183,25 +184,21 @@ public void setRotation(Rotation2d rotation) {
183184
*
184185
* @param consumer consumer for when pose is manually updated.
185186
*/
186-
public void onPoseUpdate(Consumer<Pose2d> consumer) {
187-
poseUpdateConsumers.add(consumer);
187+
public void onYawUpdate(Consumer<Rotation2d> consumer) {
188+
yawUpdateConsumers.add(consumer);
188189
}
189190

190191
/**
191-
* Tares the rotation of the robot.
192+
* Zeroes the driver-relative rotation of the robot.
192193
*
193-
* @return a command that zeroes the rotation of the robot.
194+
* @return a command that zeroes the driver-relative rotation of the robot.
194195
*/
195196
public Command tare() {
196197
return Commands.runOnce(
197198
() -> {
198-
if (AllianceFlipHelper.shouldFlip()) {
199-
setRotation(Rotation2d.fromDegrees(180));
200-
} else {
201-
setRotation(Rotation2d.fromDegrees(0));
202-
}
199+
gyroscope.setYaw(0.0);
203200

204-
poseUpdateConsumers.forEach(consumer -> consumer.accept(getPosition()));
201+
yawUpdateConsumers.forEach(consumer -> consumer.accept(Rotation2d.fromDegrees(0)));
205202
});
206203
}
207204

Diff for: src/main/java/frc/robot/swerve/DriveCommand.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public DriveCommand(CommandXboxController driverController) {
5656

5757
headingSnapper = SnapRotation.to(Rotation2d.fromDegrees(90));
5858

59-
odometry.onPoseUpdate(newPose -> resetHeadingGoal());
59+
odometry.onYawUpdate(newPose -> resetHeadingGoal());
6060
}
6161

6262
@Override
@@ -73,22 +73,22 @@ public void execute() {
7373

7474
Rotation2d driverRelativeHeading = odometry.getDriverRelativeHeading();
7575

76-
if (DriveRequest.startedDrifting(previousRequest, request)) {
77-
resetHeadingGoal();
78-
}
76+
// if (DriveRequest.startedDrifting(previousRequest, request)) {
77+
// resetHeadingGoal();
78+
// }
7979

80-
if (request.isSnapping()) {
81-
setPositionHeadingGoal(headingSnapper.snap(request.fieldHeading()));
82-
}
80+
// if (request.isSnapping()) {
81+
// setPositionHeadingGoal(headingSnapper.snap(request.driverHeading()));
82+
// }
8383

84-
Rotation2d omega;
84+
Rotation2d omega = new Rotation2d();
8585

8686
if (request.isSpinning()) {
8787
updateVelocity(request.omega());
8888

8989
omega = request.omega();
9090
} else {
91-
omega = calculateHeadingProfileOmega();
91+
// omega = calculateHeadingProfileOmega();
9292
}
9393

9494
ChassisSpeeds chassisSpeeds =
@@ -152,7 +152,7 @@ private ChassisSpeeds clampChassisSpeeds(ChassisSpeeds desiredChassisSpeeds) {
152152
* @return the reference heading to use with the heading motion profile.
153153
*/
154154
private Rotation2d getReferenceHeading() {
155-
return odometry.getFieldRelativeHeading();
155+
return odometry.getDriverRelativeHeading();
156156
}
157157

158158
/**

Diff for: src/main/java/frc/robot/swerve/DriveRequest.java

-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import edu.wpi.first.math.geometry.Rotation2d;
55
import edu.wpi.first.math.geometry.Translation2d;
66
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
7-
import frc.lib.AllianceFlipHelper;
87

98
public record DriveRequest(
109
DriveRequest.TranslationMode translationMode,
@@ -103,14 +102,4 @@ public Rotation2d omega() {
103102
public Rotation2d driverHeading() {
104103
return rotation().getAngle();
105104
}
106-
107-
public Rotation2d fieldHeading() {
108-
Rotation2d heading = driverHeading();
109-
110-
if (AllianceFlipHelper.shouldFlip()) {
111-
heading = heading.plus(Rotation2d.fromDegrees(180));
112-
}
113-
114-
return heading;
115-
}
116105
}

Diff for: src/main/java/frc/robot/swerve/SwerveConstants.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,28 @@ public static class MK4iConstants {
6767
new SwerveModuleConfig(
6868
new SwerveModuleCAN(11, 10, 12, SWERVE_BUS),
6969
new Translation2d(X_OFFSET, Y_OFFSET),
70-
Rotation2d.fromRotations(-0.027100));
70+
Rotation2d.fromRotations(-0.385742));
7171

7272
/** Module configuration for the north east swerve module. */
7373
public static final SwerveModuleConfig NORTH_EAST_MODULE_CONFIG =
7474
new SwerveModuleConfig(
7575
new SwerveModuleCAN(2, 1, 3, SWERVE_BUS),
7676
new Translation2d(X_OFFSET, -Y_OFFSET),
77-
Rotation2d.fromRotations(-0.429688));
77+
Rotation2d.fromRotations(-0.229004));
7878

7979
/** Module configuration for the south east swerve module. */
8080
public static final SwerveModuleConfig SOUTH_EAST_MODULE_CONFIG =
8181
new SwerveModuleConfig(
8282
new SwerveModuleCAN(5, 4, 6, SWERVE_BUS),
8383
new Translation2d(-X_OFFSET, -Y_OFFSET),
84-
Rotation2d.fromRotations(-0.097168));
84+
Rotation2d.fromRotations(-0.096436));
8585

8686
/** Module configuration for the south west swerve module. */
8787
public static final SwerveModuleConfig SOUTH_WEST_MODULE_CONFIG =
8888
new SwerveModuleConfig(
8989
new SwerveModuleCAN(8, 7, 9, SWERVE_BUS),
9090
new Translation2d(-X_OFFSET, Y_OFFSET),
91-
Rotation2d.fromRotations(-0.309814));
91+
Rotation2d.fromRotations(-0.448242));
9292

9393
/**
9494
* Calculates the maximum attainable open loop speed in meters per second.

0 commit comments

Comments
 (0)