mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Improve accuracy of ComputerVisionUtil.calculateDistanceToTarget() (#4215)
This commit is contained in:
@@ -11,9 +11,11 @@ namespace frc {
|
||||
units::meter_t CalculateDistanceToTarget(units::meter_t cameraHeight,
|
||||
units::meter_t targetHeight,
|
||||
units::radian_t cameraPitch,
|
||||
units::radian_t targetPitch) {
|
||||
units::radian_t targetPitch,
|
||||
units::radian_t targetYaw) {
|
||||
return (targetHeight - cameraHeight) /
|
||||
units::math::tan(cameraPitch + targetPitch);
|
||||
(units::math::tan(cameraPitch + targetPitch) *
|
||||
units::math::cos(targetYaw));
|
||||
}
|
||||
|
||||
frc::Pose2d EstimateFieldToRobot(
|
||||
@@ -22,11 +24,12 @@ frc::Pose2d EstimateFieldToRobot(
|
||||
const frc::Rotation2d& targetYaw, const frc::Rotation2d& gyroAngle,
|
||||
const frc::Pose2d& fieldToTarget, const frc::Transform2d& cameraToRobot) {
|
||||
return EstimateFieldToRobot(
|
||||
EstimateCameraToTarget(frc::Translation2d{CalculateDistanceToTarget(
|
||||
cameraHeight, targetHeight,
|
||||
cameraPitch, targetPitch),
|
||||
targetYaw},
|
||||
fieldToTarget, gyroAngle),
|
||||
EstimateCameraToTarget(
|
||||
frc::Translation2d{
|
||||
CalculateDistanceToTarget(cameraHeight, targetHeight, cameraPitch,
|
||||
targetPitch, targetYaw.Radians()),
|
||||
targetYaw},
|
||||
fieldToTarget, gyroAngle),
|
||||
fieldToTarget, cameraToRobot);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user