|
39 | 39 | import edu.wpi.first.math.numbers.N1; |
40 | 40 | import edu.wpi.first.math.numbers.N3; |
41 | 41 | import edu.wpi.first.math.system.plant.DCMotor; |
| 42 | +import edu.wpi.first.units.collections.*; |
| 43 | +import edu.wpi.first.units.measure.*; |
| 44 | +import edu.wpi.first.units.mutable.*; |
42 | 45 | import edu.wpi.first.wpilibj.Alert; |
43 | 46 | import edu.wpi.first.wpilibj.Alert.AlertType; |
44 | 47 | import edu.wpi.first.wpilibj.DriverStation; |
@@ -186,6 +189,27 @@ public void periodic() { |
186 | 189 | module.stop(); |
187 | 190 | } |
188 | 191 | } |
| 192 | + // Retrieve the current pose from odometry |
| 193 | + Pose2d currentPose = poseEstimator.getEstimatedPosition(); |
| 194 | + double xMeters = currentPose.getX(); |
| 195 | + double yMeters = currentPose.getY(); |
| 196 | + double headingRadians = currentPose.getRotation().getRadians(); |
| 197 | + |
| 198 | + // Convert to feet, inches, and degrees using WPILib Units library |
| 199 | + double xFeet = Meters.of(xMeters).in(Feet); |
| 200 | + double yFeet = Meters.of(yMeters).in(Feet); |
| 201 | + double xInches = Meters.of(xMeters).in(Inches); |
| 202 | + double yInches = Meters.of(yMeters).in(Inches); |
| 203 | + double headingDegrees = Math.toDegrees(headingRadians); |
| 204 | + |
| 205 | + // Log the current pose in various units |
| 206 | + Logger.recordOutput("Pose/X (meters)", xMeters); |
| 207 | + Logger.recordOutput("Pose/Y (meters)", yMeters); |
| 208 | + Logger.recordOutput("Pose/X (feet)", xFeet); |
| 209 | + Logger.recordOutput("Pose/Y (feet)", yFeet); |
| 210 | + Logger.recordOutput("Pose/X (inches)", xInches); |
| 211 | + Logger.recordOutput("Pose/Y (inches)", yInches); |
| 212 | + Logger.recordOutput("Pose/Heading (degrees)", headingDegrees); |
189 | 213 |
|
190 | 214 | // Log empty setpoint states when disabled |
191 | 215 | if (DriverStation.isDisabled()) { |
|
0 commit comments