@@ -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
0 commit comments