Skip to content

Commit eacbe25

Browse files
committed
new imports
1 parent 6d78fb0 commit eacbe25

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
{
1919
"name": "WPIlibUnitTests",
2020
"workingDirectory": "${workspaceFolder}/build/jni/release",
21-
"vmargs": ["-Djava.library.path=${workspaceFolder}/build/jni/release"],
21+
"vmargs": [
22+
"-Djava.library.path=${workspaceFolder}/build/jni/release"
23+
],
2224
"env": {
2325
"LD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release",
2426
"DYLD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release"

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import edu.wpi.first.math.numbers.N1;
4040
import edu.wpi.first.math.numbers.N3;
4141
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.*;
4245
import edu.wpi.first.wpilibj.Alert;
4346
import edu.wpi.first.wpilibj.Alert.AlertType;
4447
import edu.wpi.first.wpilibj.DriverStation;
@@ -186,6 +189,27 @@ public void periodic() {
186189
module.stop();
187190
}
188191
}
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);
189213

190214
// Log empty setpoint states when disabled
191215
if (DriverStation.isDisabled()) {

0 commit comments

Comments
 (0)