Package frc.robot.Subsystems.Vision
Class ObjectDetection
java.lang.Object
frc.robot.Subsystems.Vision.ObjectDetection
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectDetectionedu.wpi.first.math.geometry.Pose2dThe current robot pose.List of targets that are being tracked. -
Method Summary
Modifier and TypeMethodDescriptionReturns the closest target to the robot.doublegetDistance(double width, double height, int x_center) Calculates the diagonal distance from the camera to the target.doublegetLateralDistance(double normal_distance, int x_center) Calculates the distance from the camera horizontal ray to the target center.doublegetNormalDistance(double width, double height) Uses an inverse regression function to calculate the normal distance of the target.edu.wpi.first.math.geometry.Pose2dgetTargetPose(double width, double height, int x_center, edu.wpi.first.math.geometry.Transform2d camera_transform) Calculates the target's field-relative pose.voidupdateTrackedObjects(org.photonvision.targeting.PhotonPipelineResult pipeline_result, edu.wpi.first.math.geometry.Transform2d camera_transform)
-
Field Details
-
instance
-
robot_pose
public edu.wpi.first.math.geometry.Pose2d robot_poseThe current robot pose. -
tracked_targets
List of targets that are being tracked.
-
-
Method Details
-
getNormalDistance
public double getNormalDistance(double width, double height) Uses an inverse regression function to calculate the normal distance of the target.- Parameters:
width- The width of the target's bounding box in pixels.height- The height of the target's bounding box in pixels.- Returns:
- The normal distance of the target in meters.
-
getLateralDistance
public double getLateralDistance(double normal_distance, int x_center) Calculates the distance from the camera horizontal ray to the target center.- Parameters:
normal_distance- The normal distance to the target in meters.x_center- The horizontal center of the target's bounding box in pixels.- Returns:
- The lateral distance to the target in meters.
-
getDistance
public double getDistance(double width, double height, int x_center) Calculates the diagonal distance from the camera to the target.- Parameters:
width- The width of the target's bounding box in pixels.height- The height of the target's bounding box in pixels.x_center- The normal distance of the target in meters.- Returns:
- The distance to the target in meters.
-
getTargetPose
public edu.wpi.first.math.geometry.Pose2d getTargetPose(double width, double height, int x_center, edu.wpi.first.math.geometry.Transform2d camera_transform) Calculates the target's field-relative pose.- Parameters:
width- The width of the target's bounding box in pixels.height- The height of the target's bounding box in pixels.x_center- The normal distance of the target in meters.- Returns:
- The calculated pose.
-
getClosestTarget
Returns the closest target to the robot. Accounts for robot orientation.- Returns:
- The best target object.
-
updateTrackedObjects
public void updateTrackedObjects(org.photonvision.targeting.PhotonPipelineResult pipeline_result, edu.wpi.first.math.geometry.Transform2d camera_transform)
-