-
Notifications
You must be signed in to change notification settings - Fork 0
Robot Vision
This class serves as a manager of cameras, running operations that use data from multiple cameras to complete tasks.
Using RobotVision
is incredibly easy. Firstly, you need to create a variable with the RobotVision
type and set it equal to a new instance of the RobotVision subclass known as Builder
. This will look something similar to the following:
RobotVision robotVision = new RobotVision.Builder();
After that, you have to add all the cameras you want this RobotVision
object to manage and use to the Builder
. This can be done by using either the addLimelightCamera()
or addPhotonVisionCamera()
methods. This should look similar to the below example:
RobotVision robotVision = new RobotVision.Builder()
.addLimelightCamera(limelight3g)
.addPhotonVisionCamera(VisionConstants.COLOR_CAMERA_NAME, VisionConstants.COLOR_CAMERA_OFFSET,
VisionConstants.COLOR_CAMERA_STARTING_PIPELINE);
Finally, call the build()
method. This will return a RobotVision
object that manages all of the added camera. If you've followed everything as instructed, your code should look something like this:
RobotVision robotVision = new RobotVision.Builder()
.addLimelightCamera(limelight3g)
.addPhotonVisionCamera(VisionConstants.COLOR_CAMERA_NAME, VisionConstants.COLOR_CAMERA_OFFSET,
VisionConstants.COLOR_CAMERA_STARTING_PIPELINE)
.build();
This class has a private constructor that cannot be accessed by anything other than this class' Builder
subclass. Information detailing how to create a RobotVision
object can be found in the How to use section.
-
Access Modifier:
public
-
Return Type:
Pose2d
orNull
if the robot's position cannot be estimated. -
Description: The
estimateRobotPose()
method is a method that can be used to get the vision estimated robot position. It should be noted that the returned value is the average of all managed cameras' estimated positions.
-
Access Modifier:
public
-
Parameters:
-
id:
- Type:
int
- Description: The ID of the tag you want to get the distance to.
- Type:
-
-
Return Type:
TagPose3d
ornull
if the tag with the given ID cannot be seen. - Description:
-
Access Modifier:
public
-
Parameters:
-
cameraName:
- Type:
String
- Description: The name of the camera you want to take a photo.
- Type:
-
- Description: Takes a photo using the camera with the given name.
-
Access Modifier:
public
- Description: Takes a photon using all managed cameras.
-
Access Modifier:
public
-
Parameters:
-
cameraName:
- Type:
String
- Description: The name of the camera you want to find.
- Type:
-
-
Return Type:
PhotonVisionCamera
orNull
if no camera with the given name can be found. -
Description: Looks through all of this
RobotVision
`s managed photon vision cameras for a camera with the given name. Then, if a camera with the given name can be found, it returns that camera. Otherwise it will return null.
-
Access Modifier:
public
-
Parameters:
-
cameraName:
- Type:
String
- Description: The name of the camera you want to find.
- Type:
-
-
Return Type:
LimelightCamera
orNull
if no camera with the given name can be found. -
Description: Looks through all of this
RobotVision
`s managed limelight cameras for a camera with the given name. Then, if a camera with the given name can be found, it is returned. Otherwise it will return null.
-
Access Modifier:
private
-
Parameters:
-
camera:
- Type:
PhotonVisionCamera
- Description: The camera you want to check if can see an ApriLTag with the given ID.
- Type:
-
targetId:
- Type:
int
- Description: The ID of the tag you want to see if the provided camera can see.
- Type:
-
-
Return Type:
PhotonTrackedTarget
ornull
if the desired AprilTag cannot be seen. -
Description: Checks if the provided camera can see an AprilTag with the given ID. If it can, then it will return a
PhotonTrackedTarget
with the desired tag's data. Otiose this method will return null.
-
Access Modifier:
private
-
Type:
ArrayList<PhotonVisionCamera>
-
Descriptio: An
ArrayList
that stores all of thePhotonVisionCamera
s that this RobotVision manages.
-
Access Modifier:
private
-
Type:
ArrayList<LimelightCamera>
-
Descriptio: An
ArrayList
that stores all of theLimelightCamera
s that this RobotVision manages.
// Create camera object for all of the robot's cameras so that they can be added to a RobotVision object and used for pose estimation.
LimelightCamera blackAndWhiteCamera = new LimelightCamera("limelight", 0, 0, 1, 0);
PhotonVisionCamera colorCamera = new PhotonVisionCamera(VisionConstants.COLOR_CAMERA_NAME, VisionConstants.COLOR_CAMERA_OFFSET);
colorCamera.setPipeline(VisionConstants.COLOR_CAMERA_PIPELINE)
// Create a new RobotVision object to manage all of the above created cameras.
RobotVision robotVision = new RobotVision.Builder()
.addLimelightCamera(blackAndWhiteCamera)
.addPhotonVisionCamera(colorCamera)
.build();
// Create a new Drive Subsystem and pass the RobotVision's "estimateRobotPose()" method so that the robot can account for the vision estimated position.
private final DriveSubsystem driveSubsystem = new DriveSubsystem(true, robotVision::estimateRobotPose);
Below is a list of all
- Version: 2024.3.2+
-
Use: WPILib is required in order to access various geometry classes, communicate with SmartDashboard, and make the
RobotVision
class a subsystem through the inheritance of theSubsystemBase
class.
- Version: 24.2.0+
-
Use: Required to preform operations using
PhotonVisionCamera
objects. -
Vendor App:
https://maven.photonvision.org/repository/internal/org/photonvision/photonlib-json/1.0/photonlib-json-1.0.json
This section provides a general overview of the history of changes made to this class. Each entry will include several details: a version number; the date that the changes were made — m/d/y; a summery of the changes; and a list of all of the changes made.
- Release Date: 02/17/24
- Summery: Creation of this class.
-
Details:
- Created class with
estimateRobotPose()
,getDistanceToTag(int id)
,validatePhotonTrackedTarget(PhotonVisionCamera camera, int targetId)
,snapshot(String cameraName)
, andsnapshotAll()
methods.
- Created class with
We follow the Semantic Versioning (SemVer) for our version numbers. Each version number is in the following format: MAJOR.MINOR.PATCH
.
-
MAJOR
version increments indicate breaking changes. -
MINOR
version increments indicate the addition of new features in a backwards-compatible manner. -
PATCH
version increments indicate backwards-compatible bug fixes.
- Role: Author and developer.
- Contact: [email protected]