From 2f04ffe92562ec741872c7dda38d440ad0a86c80 Mon Sep 17 00:00:00 2001 From: Aarav Date: Wed, 15 Mar 2023 13:50:35 -0600 Subject: [PATCH] lime stuff --- src/main/java/frc4388/robot/Constants.java | 15 ++++++ .../frc4388/robot/subsystems/Limelight.java | 53 +++++++++++++++++++ vendordeps/photonlib.json | 41 ++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 src/main/java/frc4388/robot/subsystems/Limelight.java create mode 100644 vendordeps/photonlib.json diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index 83ac014..9953934 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -142,4 +142,19 @@ public final class Constants { public static final double RIGHT_AXIS_DEADBAND = 0.6; public static final boolean SKEW_STICKS = true; // ! this might have to actually be false, merge conflicts are confusing } + + public static final class VisionConstants { + public static final String NAME = "Aarav is poopy"; + + public static final int LIME_FOV = -1; + + public static final double LIME_HEIGHT = -1.0; + public static final double LIME_ANGLE = -1.0; + + public static final double HIGH_TARGET_HEIGHT = -1.0; + public static final double HIGHT_TAPE_HEIGHT = -1.0; + + public static final double MID_TARGET_HEIGHT = -1.0; + public static final double MID_TAPE_HEIGHT = -1.0; + } } diff --git a/src/main/java/frc4388/robot/subsystems/Limelight.java b/src/main/java/frc4388/robot/subsystems/Limelight.java new file mode 100644 index 0000000..a6d951a --- /dev/null +++ b/src/main/java/frc4388/robot/subsystems/Limelight.java @@ -0,0 +1,53 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc4388.robot.subsystems; + +import java.util.ArrayList; +import java.util.List; + +import org.opencv.core.Point; +import org.photonvision.PhotonCamera; +import org.photonvision.common.hardware.VisionLEDMode; +import org.photonvision.targeting.PhotonPipelineResult; +import org.photonvision.targeting.TargetCorner; + +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc4388.robot.Constants.VisionConstants; +import frc4388.utility.AbhiIsADumbass; + +public class Limelight extends SubsystemBase { + private PhotonCamera cam; + /** Creates a new LImelight. */ + public Limelight() { + cam = new PhotonCamera(VisionConstants.NAME); + } + + public void setLEDs(boolean on) { + cam.setLED(on ? VisionLEDMode.kOn : VisionLEDMode.kOff); + } + + public void setDriverMode(boolean driverMode) { + cam.setDriverMode(driverMode); + } + + public Point getTargetPoints() throws AbhiIsADumbass { + PhotonPipelineResult result = cam.getLatestResult(); + + if (!result.hasTargets()) throw new AbhiIsADumbass(); + + Point point = new Point(); + List corners = result.getTargets().get(0).getDetectedCorners(); + + double x1, x2, y1, y2; + double mx, my; + + return new Point(mx, my); + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} diff --git a/vendordeps/photonlib.json b/vendordeps/photonlib.json new file mode 100644 index 0000000..dad3105 --- /dev/null +++ b/vendordeps/photonlib.json @@ -0,0 +1,41 @@ +{ + "fileName": "photonlib.json", + "name": "photonlib", + "version": "v2023.4.2", + "uuid": "515fe07e-bfc6-11fa-b3de-0242ac130004 ", + "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": "v2023.4.2", + "libName": "Photon", + "headerClassifier": "headers", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxathena", + "linuxx86-64", + "osxuniversal" + ] + } + ], + "javaDependencies": [ + { + "groupId": "org.photonvision", + "artifactId": "PhotonLib-java", + "version": "v2023.4.2" + }, + { + "groupId": "org.photonvision", + "artifactId": "PhotonTargeting-java", + "version": "v2023.4.2" + } + ] +} \ No newline at end of file