Package frc.robot.Subsystems.Vision
Class VisionTarget
java.lang.Object
frc.robot.Subsystems.Vision.VisionTarget
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVisionTarget(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 TypeMethodDescriptionedu.wpi.first.math.geometry.Rotation2dgetAngle(edu.wpi.first.math.geometry.Pose2d other_pose) Calculates the angle from the frame of reference of a pose.edu.wpi.first.math.geometry.Rotation2dgetAngle(edu.wpi.first.math.geometry.Translation2d other_pose) Calculates the field-relative angle of the object from a position.doublegetDistance(edu.wpi.first.math.geometry.Pose2d other_pose) Calculates the distance from a pose to the object.doublegetDistance(edu.wpi.first.math.geometry.Translation2d other_pose) Calculates the distance from a position to the object.edu.wpi.first.math.geometry.Pose2dgetPose()Returns the object's pose as a Pose2d.edu.wpi.first.math.geometry.Pose3dReturns the object's pose as a Pose3d.booleaninAngularTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose) booleaninDistanceTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose, edu.wpi.first.math.geometry.Pose2d robot_pose) booleaninPositionTolerance(edu.wpi.first.math.geometry.Pose2d observed_pose) booleanmatch(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.booleanmatch(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.voidResets the target's deletion marks without updating the pose.voidupdatePosition(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.Pose2dupdatePosition(edu.wpi.first.math.geometry.Pose2d new_pose, double weight) Returns the vision-estimated positoin of the object and resets its timeout.
-
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.
-