Skip to content

Commit f7e884b

Browse files
committed
add onshape offsets
1 parent de67918 commit f7e884b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/main/java/org/steelhawks/Constants.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import com.ctre.phoenix6.CANBus;
44
import com.pathplanner.lib.path.PathConstraints;
5+
import edu.wpi.first.math.geometry.Rotation2d;
6+
import edu.wpi.first.math.geometry.Rotation3d;
7+
import edu.wpi.first.math.geometry.Transform3d;
8+
import edu.wpi.first.math.geometry.Translation2d;
59
import edu.wpi.first.math.util.Units;
610
import edu.wpi.first.wpilibj.Alert;
711
import edu.wpi.first.wpilibj.Alert.AlertType;
@@ -280,4 +284,33 @@ public static <T> T loggedValue(String key, T obj) {
280284
}
281285
return obj;
282286
}
287+
288+
/**
289+
* Automatically returns a Transform3d that correctly converts the Onshape coordinate system into the WPILib coordinate system.
290+
* <br>
291+
* <br>
292+
* Learn more <a href="https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html">here</a> about the WPILib coordinate system.
293+
* @param x From Onshape
294+
* @param y From Onshape
295+
* @param z From Onshape
296+
* @param roll From Onshape
297+
* @param pitch From Onshape
298+
* @param yaw From Onshape
299+
* @return The WPILib coordinate system ready Transform3d
300+
*/
301+
public static Transform3d fromOnshapeCoordinates(
302+
double x, double y, double z,
303+
double roll, double pitch, double yaw
304+
) {
305+
return new Transform3d(
306+
Units.inchesToMeters(y),
307+
Units.inchesToMeters(-x),
308+
Units.inchesToMeters(-z),
309+
new Rotation3d(
310+
Units.degreesToRadians(roll),
311+
Units.degreesToRadians(pitch),
312+
Units.degreesToRadians(yaw )
313+
)
314+
);
315+
}
283316
}

src/main/java/org/steelhawks/subsystems/vision/VisionConstants.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public static Transform3d[] robotToCamera() {
9595
// Up-Down: 6.900835
9696
// CHANGE DEPENDING HOW HIGH THE CAMERA IS MOUNTED ON THE BEAM
9797
// This assumes that the camera takes up holes 7 and 8 in the beam, counted from the top
98-
Units.inchesToMeters(3.134462),
99-
Units.inchesToMeters(-9.062338),
100-
Units.inchesToMeters(6.900835),
98+
Units.inchesToMeters(3.134462), // y
99+
Units.inchesToMeters(-9.062338), // -x
100+
Units.inchesToMeters(6.900835), // -z
101101
new Rotation3d(
102102
Units.degreesToRadians(0),
103103
Units.degreesToRadians(-15),

0 commit comments

Comments
 (0)