Class ObjectDetection

java.lang.Object
frc.robot.Subsystems.Vision.ObjectDetection

public class ObjectDetection extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ObjectDetection
     
    edu.wpi.first.math.geometry.Pose2d
    The current robot pose.
    List of targets that are being tracked.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the closest target to the robot.
    double
    getDistance(double width, double height, int x_center)
    Calculates the diagonal distance from the camera to the target.
    double
    getLateralDistance(double normal_distance, int x_center)
    Calculates the distance from the camera horizontal ray to the target center.
    double
    getNormalDistance(double width, double height)
    Uses an inverse regression function to calculate the normal distance of the target.
    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.
    void
    updateTrackedObjects(org.photonvision.targeting.PhotonPipelineResult pipeline_result, edu.wpi.first.math.geometry.Transform2d camera_transform)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • instance

      public static final ObjectDetection instance
    • robot_pose

      public edu.wpi.first.math.geometry.Pose2d robot_pose
      The current robot pose.
    • tracked_targets

      public List<VisionTarget> 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

      public Optional<VisionTarget> 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)