|
2 | 2 |
|
3 | 3 | import com.ctre.phoenix6.CANBus; |
4 | 4 | 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; |
5 | 9 | import edu.wpi.first.math.util.Units; |
6 | 10 | import edu.wpi.first.wpilibj.Alert; |
7 | 11 | import edu.wpi.first.wpilibj.Alert.AlertType; |
@@ -280,4 +284,33 @@ public static <T> T loggedValue(String key, T obj) { |
280 | 284 | } |
281 | 285 | return obj; |
282 | 286 | } |
| 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 | + } |
283 | 316 | } |
0 commit comments