Class VisionTarget

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

public class VisionTarget extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    edu.wpi.first.math.geometry.Translation2d
     
    int
     
    edu.wpi.first.wpilibj.Timer
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    VisionTarget(edu.wpi.first.math.geometry.Pose2d position)
    Creates a new Target.
    VisionTarget(edu.wpi.first.math.geometry.Translation2d position)
    Creates a new Target.
  • Method Summary

    Modifier and Type
    Method
    Description
    edu.wpi.first.math.geometry.Rotation2d
    getAngle(edu.wpi.first.math.geometry.Pose2d other_pose)
    Calculates the angle from the frame of reference of a pose.
    edu.wpi.first.math.geometry.Rotation2d
    getAngle(edu.wpi.first.math.geometry.Translation2d other_pose)
    Calculates the field-relative angle of the object from a position.
    double
    getDistance(edu.wpi.first.math.geometry.Pose2d other_pose)
    Calculates the distance from a pose to the object.
    double
    getDistance(edu.wpi.first.math.geometry.Translation2d other_pose)
    Calculates the distance from a position to the object.
    edu.wpi.first.math.geometry.Pose2d
    Returns the object's pose as a Pose2d.
    edu.wpi.first.math.geometry.Pose3d
    Returns the object's pose as a Pose3d.
    boolean
    inAngularTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose)
     
    boolean
    inDistanceTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose)
     
    boolean
    inPositionTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose)
     
    boolean
    match(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose, boolean update_pose)
    Returns whether the observed target matches this target's position.
    boolean
    match(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose, double weight)
    Checks whether the observed target matches this target's position.
    void
    Resets the target's deletion marks without updating the pose.
    void
    updatePosition(edu.wpi.first.math.geometry.Pose2d new_pose)
    Updates the vision-estimated position of the object and resets its timeout.
    edu.wpi.first.math.geometry.Pose2d
    updatePosition(edu.wpi.first.math.geometry.Pose2d new_pose, double weight)
    Returns the vision-estimated positoin of the object and resets its timeout.

    Methods inherited from class java.lang.Object

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

    • position

      public edu.wpi.first.math.geometry.Translation2d position
    • timer

      public edu.wpi.first.wpilibj.Timer timer
    • timeout

      public int timeout
  • Constructor Details

    • VisionTarget

      public VisionTarget(edu.wpi.first.math.geometry.Pose2d position)
      Creates a new Target.
    • VisionTarget

      public VisionTarget(edu.wpi.first.math.geometry.Translation2d position)
      Creates a new Target.
  • Method Details

    • getPose

      public edu.wpi.first.math.geometry.Pose2d getPose()
      Returns the object's pose as a Pose2d.
      Returns:
      The object's pose.
    • getPose3d

      public edu.wpi.first.math.geometry.Pose3d getPose3d()
      Returns the object's pose as a Pose3d.
      Returns:
      The object's pose with a small Z offset.
    • getDistance

      public double getDistance(edu.wpi.first.math.geometry.Pose2d other_pose)
      Calculates the distance from a pose to the object.
      Parameters:
      other_pose - The reference pose.
      Returns:
      The calculated distance in meters.
    • getDistance

      public double getDistance(edu.wpi.first.math.geometry.Translation2d other_pose)
      Calculates the distance from a position to the object.
      Parameters:
      other_pose - The reference position.
      Returns:
      The calculated distance in meters.
    • getAngle

      public edu.wpi.first.math.geometry.Rotation2d getAngle(edu.wpi.first.math.geometry.Pose2d other_pose)
      Calculates the angle from the frame of reference of a pose.
      Parameters:
      other_pose - The reference pose. The rotation of this pose affects the output.
      Returns:
      The calculated angle.
    • getAngle

      public edu.wpi.first.math.geometry.Rotation2d getAngle(edu.wpi.first.math.geometry.Translation2d other_pose)
      Calculates the field-relative angle of the object from a position.
      Parameters:
      other_pose - The reference position.
      Returns:
      The calculated angle.
    • updatePosition

      public void updatePosition(edu.wpi.first.math.geometry.Pose2d new_pose)
      Updates the vision-estimated position of the object and resets its timeout.
      Parameters:
      new_pose - The new pose.
    • updatePosition

      public edu.wpi.first.math.geometry.Pose2d updatePosition(edu.wpi.first.math.geometry.Pose2d new_pose, double weight)
      Returns the vision-estimated positoin of the object and resets its timeout.
      Parameters:
      new_pose - The estimated pose.
      weight - The relative weight to be given to the new pose. 0 is no weight, and 1 overrides the stored pose.
      Returns:
      The new calculated pose of the target.
    • resetTimer

      public void resetTimer()
      Resets the target's deletion marks without updating the pose.
    • inAngularTolerance

      public boolean inAngularTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose)
    • inDistanceTolerance

      public boolean inDistanceTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose)
    • inPositionTolerance

      public boolean inPositionTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose)
    • match

      public boolean match(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose, boolean update_pose)
      Returns whether the observed target matches this target's position. Unmarks this target if so.
      Parameters:
      observed_pose - The observed target pose.
      robot_pose - The robot's current pose.
      update_pose - Whether or not to update the position of the target with this observation if matched.
      Returns:
      Whether or not the observed target matches this target.
    • match

      public boolean match(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose, double weight)
      Checks whether the observed target matches this target's position. Unmarks this target if so.
      Parameters:
      observed_pose - The observed target pose.
      robot_pose - The robot's current pose.
      weight - The weight of the new estimate
      Returns:
      Whether the target was matched.