-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from frc3512/vision_jonny
Vision with Auto Aim
- Loading branch information
Showing
6 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package frc3512.robot.subsystems; | ||
|
||
import edu.wpi.first.apriltag.AprilTagFieldLayout; | ||
import edu.wpi.first.apriltag.AprilTagFields; | ||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc3512.robot.Constants; | ||
import java.util.Optional; | ||
import org.photonvision.EstimatedRobotPose; | ||
import org.photonvision.PhotonCamera; | ||
import org.photonvision.PhotonPoseEstimator; | ||
import org.photonvision.PhotonPoseEstimator.PoseStrategy; | ||
|
||
public class Vision extends SubsystemBase { | ||
public PhotonCamera photonCamera = new PhotonCamera(Constants.VisionConstants.cameraName); | ||
public PhotonPoseEstimator photonPoseEstimator; | ||
public AprilTagFieldLayout atfl; | ||
|
||
public Vision() { | ||
PhotonCamera.setVersionCheckEnabled(false); | ||
// photonCamera.setDriverMode(true); | ||
|
||
atfl = AprilTagFields.kDefaultField.loadAprilTagLayoutField(); | ||
|
||
// Create pose estimator | ||
photonPoseEstimator = | ||
new PhotonPoseEstimator( | ||
atfl, | ||
PoseStrategy.LOWEST_AMBIGUITY, | ||
photonCamera, | ||
Constants.VisionConstants.robotToCam); | ||
} | ||
|
||
/** | ||
* @param estimatedRobotPose The current best guess at robot pose | ||
* @return A pair of the fused camera observations to a single Pose2d on the field, and the time | ||
* of the observation. Assumes a planar field and the robot is always firmly on the ground | ||
*/ | ||
public Optional<EstimatedRobotPose> getEstimatedGlobalPose(Pose2d prevEstimatedRobotPose) { | ||
photonPoseEstimator.setReferencePose(prevEstimatedRobotPose); | ||
return photonPoseEstimator.update(); | ||
} | ||
|
||
public PhotonCamera returnCamera(Vision vision) { | ||
return vision.photonCamera; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"fileName": "photonlib.json", | ||
"name": "photonlib", | ||
"version": "v2024.2.4", | ||
"uuid": "515fe07e-bfc6-11fa-b3de-0242ac130004", | ||
"frcYear": "2024", | ||
"mavenUrls": [ | ||
"https://maven.photonvision.org/repository/internal", | ||
"https://maven.photonvision.org/repository/snapshots" | ||
], | ||
"jsonUrl": "https://maven.photonvision.org/repository/internal/org/photonvision/photonlib-json/1.0/photonlib-json-1.0.json", | ||
"jniDependencies": [], | ||
"cppDependencies": [ | ||
{ | ||
"groupId": "org.photonvision", | ||
"artifactId": "photonlib-cpp", | ||
"version": "v2024.2.4", | ||
"libName": "photonlib", | ||
"headerClassifier": "headers", | ||
"sharedLibrary": true, | ||
"skipInvalidPlatforms": true, | ||
"binaryPlatforms": [ | ||
"windowsx86-64", | ||
"linuxathena", | ||
"linuxx86-64", | ||
"osxuniversal" | ||
] | ||
}, | ||
{ | ||
"groupId": "org.photonvision", | ||
"artifactId": "photontargeting-cpp", | ||
"version": "v2024.2.4", | ||
"libName": "photontargeting", | ||
"headerClassifier": "headers", | ||
"sharedLibrary": true, | ||
"skipInvalidPlatforms": true, | ||
"binaryPlatforms": [ | ||
"windowsx86-64", | ||
"linuxathena", | ||
"linuxx86-64", | ||
"osxuniversal" | ||
] | ||
} | ||
], | ||
"javaDependencies": [ | ||
{ | ||
"groupId": "org.photonvision", | ||
"artifactId": "photonlib-java", | ||
"version": "v2024.2.4" | ||
}, | ||
{ | ||
"groupId": "org.photonvision", | ||
"artifactId": "photontargeting-java", | ||
"version": "v2024.2.4" | ||
} | ||
] | ||
} |