Class AprilTagVisionSubsystem
java.lang.Object
org.wpilib.command2.SubsystemBase
xbot.common.subsystems.vision.AprilTagVisionSubsystem
- All Implemented Interfaces:
org.wpilib.command2.Subsystem, org.wpilib.telemetry.TelemetryLoggable
@Singleton
public class AprilTagVisionSubsystem
extends org.wpilib.command2.SubsystemBase
Subsystem for processing AprilTag vision data.
Based on the AdvantageKit sample implementation by team 6328.
-
Constructor Summary
ConstructorsConstructorDescriptionAprilTagVisionSubsystem(TunableFactory tunableFactory, org.wpilib.fields.Fields fieldLayout, XCameraElectricalContract contract, AprilTagVisionIOFactory visionIOFactory, DataFrameRegistry registry) -
Method Summary
Modifier and TypeMethodDescriptioncamerasWithTagVisible(int tagId) Returns the set of cameras that can see the specified tag.List<xbot.common.subsystems.vision.AprilTagVisionCameraHelper> Retrieves the set of cameras that should be used for pose estimationsGets all the pose observations in this iteration of the scheduler loop.getBestTargetId(int cameraIndex) Returns the ID of the best target.intReturns the number of cameras.org.wpilib.math.geometry.Transform3dgetCameraPosition(int cameraIndex) Gets the position of the camera relative to the robot.getLatestTargetObservation(int cameraIndex) Returns the latest target observation.getTargetObservation(int cameraIndex, int tagId) Returns the raw observation data for the specified target.org.wpilib.math.geometry.Rotation2dgetTargetX(int cameraIndex) Returns the X angle to the best target, which can be used for simple servoing with vision.Optional<org.wpilib.math.geometry.Rotation2d> getTargetX(int cameraIndex, int tagId) Returns the X angle to the specified target, which can be used for simple servoing with vision.booleanisCameraConnected(int cameraIndex) voidperiodic()booleantagVisibleByAnyCamera(int tagId) Returnstrue if any camera can see the specified tag.booleantagVisibleByCamera(int cameraIndex, int tagId) Returnstrue if the camera can see the specified tag.Methods inherited from class org.wpilib.command2.SubsystemBase
getName, getTelemetryType, logTo, setNameMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.wpilib.command2.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
AprilTagVisionSubsystem
@Inject public AprilTagVisionSubsystem(TunableFactory tunableFactory, org.wpilib.fields.Fields fieldLayout, XCameraElectricalContract contract, AprilTagVisionIOFactory visionIOFactory, DataFrameRegistry registry)
-
-
Method Details
-
getCameraCount
public int getCameraCount()Returns the number of cameras. -
getCameraPosition
public org.wpilib.math.geometry.Transform3d getCameraPosition(int cameraIndex) Gets the position of the camera relative to the robot.- Parameters:
cameraIndex- The index of the camera to use.- Returns:
- The 3D position of the camera relative to the robot.
-
getLatestTargetObservation
Returns the latest target observation.- Parameters:
cameraIndex- The index of the camera to use.- Returns:
- The latest target observation.
-
getTargetX
public org.wpilib.math.geometry.Rotation2d getTargetX(int cameraIndex) Returns the X angle to the best target, which can be used for simple servoing with vision.- Parameters:
cameraIndex- The index of the camera to use.
-
getTargetX
Returns the X angle to the specified target, which can be used for simple servoing with vision.- Parameters:
cameraIndex- The index of the camera to use.tagId- The tag to check.- Returns:
- The X angle to the specified target.
-
getBestTargetId
Returns the ID of the best target.- Parameters:
cameraIndex- The index of the camera to use.- Returns:
- The ID of the best target.
-
getTargetObservation
public Optional<AprilTagVisionIO.TargetObservation> getTargetObservation(int cameraIndex, int tagId) Returns the raw observation data for the specified target.- Parameters:
cameraIndex- The index of the camera to use.tagId- The tag to check.- Returns:
- The raw observation data for the specified target.
-
tagVisibleByCamera
public boolean tagVisibleByCamera(int cameraIndex, int tagId) Returnstrue if the camera can see the specified tag.- Parameters:
cameraIndex- The camera to check.tagId- The tag to check.- Returns:
true if the camera can see the tag.
-
tagVisibleByAnyCamera
public boolean tagVisibleByAnyCamera(int tagId) Returnstrue if any camera can see the specified tag.- Parameters:
tagId- The tag to check.- Returns:
true if any camera can see the tag.
-
camerasWithTagVisible
-
isCameraConnected
public boolean isCameraConnected(int cameraIndex) -
getAllPoseCameras
Retrieves the set of cameras that should be used for pose estimations- Returns:
- The set of cameras that are meant for pose.
-
getAllPoseObservations
Gets all the pose observations in this iteration of the scheduler loop.- Returns:
- A list of pose observations.
-
periodic
public void periodic()
-