Skip to content
Cameron Myhre edited this page Jul 17, 2024 · 33 revisions

Purpose

This class serves as a manager of cameras, running operations that use data from multiple cameras to complete tasks.

How to use

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();

Constructors

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.

Methods

estimateRobotPose()

  • Access Modifier: public
  • Return Type: Pose2d or Null 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.

getDistanceToTag(int id)

  • Access Modifier: public
  • Parameters:
    • id:
      • Type: int
      • Description: The ID of the tag you want to get the distance to.
  • Return Type: TagPose3d or null if the tag with the given ID cannot be seen.
  • Description:

snamshot(String cameraName)

  • Access Modifier: public
  • Parameters:
    • cameraName:
      • Type: String
      • Description: The name of the camera you want to take a photo.
  • Description: Takes a photo using the camera with the given name.

snapshotAll()

  • Access Modifier: public
  • Description: Takes a photon using all managed cameras.

getPhotonVisionCamera(String cameraName)

  • Access Modifier: public
  • Parameters:
    • cameraName:
      • Type: String
      • Description: The name of the camera you want to find.
  • Return Type: PhotonVisionCamera or Null 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.

getLimelightCamera(String cameraName)

  • Access Modifier: public
  • Parameters:
    • cameraName:
      • Type: String
      • Description: The name of the camera you want to find.
  • Return Type: LimelightCamera or Null 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.

validatePhotonTrackedTarget(PhotonVisionCamera camera, int targetId)

  • Access Modifier: private
  • Parameters:
    • camera:
      • Type: PhotonVisionCamera
      • Description: The camera you want to check if can see an ApriLTag with the given ID.
    • targetId:
      • Type: int
      • Description: The ID of the tag you want to see if the provided camera can see.
  • Return Type: PhotonTrackedTarget or null 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.

Properties

photonVisionCameras

  • Access Modifier: private
  • Type: ArrayList<PhotonVisionCamera>
  • Descriptio: An ArrayList that stores all of the PhotonVisionCameras that this RobotVision manages.

limelightCameras

  • Access Modifier: private
  • Type: ArrayList<LimelightCamera>
  • Descriptio: An ArrayList that stores all of the LimelightCameras that this RobotVision manages.

Example

Robot Pose Estimation

// 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);

Dependencies

Overview

Below is a list of all

WPILib

  • 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 the SubsystemBase class.

PhotonVision

  • 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

Version History

Overview

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.

Version 1.0.0

  • 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), and snapshotAll() methods.

How to read version numbers

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.

Author

Cameron Myhre

References

Official Documentation

Installation Guides

Relevant Articles