mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpimath] Improve accuracy of ComputerVisionUtil.calculateDistanceToTarget() (#4215)
This commit is contained in:
@@ -32,15 +32,17 @@ public final class ComputerVisionUtil {
|
||||
* Positive values up.
|
||||
* @param targetPitchRadians The pitch of the target in the camera's lens in radians. Positive
|
||||
* values up.
|
||||
* @param targetYawRadians The yaw of the target in the camera's lens in radians.
|
||||
* @return The estimated distance to the target in meters.
|
||||
*/
|
||||
public static double calculateDistanceToTarget(
|
||||
double cameraHeightMeters,
|
||||
double targetHeightMeters,
|
||||
double cameraPitchRadians,
|
||||
double targetPitchRadians) {
|
||||
double targetPitchRadians,
|
||||
double targetYawRadians) {
|
||||
return (targetHeightMeters - cameraHeightMeters)
|
||||
/ Math.tan(cameraPitchRadians + targetPitchRadians);
|
||||
/ (Math.tan(cameraPitchRadians + targetPitchRadians) * Math.cos(targetYawRadians));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +78,11 @@ public final class ComputerVisionUtil {
|
||||
estimateCameraToTarget(
|
||||
new Translation2d(
|
||||
calculateDistanceToTarget(
|
||||
cameraHeightMeters, targetHeightMeters, cameraPitchRadians, targetPitchRadians),
|
||||
cameraHeightMeters,
|
||||
targetHeightMeters,
|
||||
cameraPitchRadians,
|
||||
targetPitchRadians,
|
||||
targetYaw.getRadians()),
|
||||
targetYaw),
|
||||
fieldToTarget,
|
||||
gyroAngle),
|
||||
|
||||
Reference in New Issue
Block a user