Skip to content

Commit

Permalink
WIP - Move vision to correct file location and begin rewriting to sup…
Browse files Browse the repository at this point in the history
…port sim
  • Loading branch information
aidnem committed Nov 17, 2024
1 parent b4d9af1 commit e90ad3a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 48 deletions.
15 changes: 12 additions & 3 deletions vision/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import java.text.SimpleDateFormat
plugins {
id "java"
id "maven-publish"
id "edu.wpi.first.GradleRIO" version "2024.3.2"
id "com.peterabeles.gversion" version "1.10"
id "com.diffplug.spotless" version "6.24.0"
}
Expand All @@ -29,12 +28,18 @@ compileJava.finalizedBy checkAkitInstall
// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 5.
dependencies {
implementation 'edu.wpi.first.wpilibj:wpilibj-java:2024.3.2'
implementation 'edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:2024.3.2'
implementation 'edu.wpi.first.apriltag:apriltag-java:2024.3.2'

def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$akitJson.version"
annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:3.2.1"

implementation wpi.java.deps.wpilib()
implementation wpi.java.vendor.java()
implementation 'org.littletonrobotics.akit.junction:junction-core:3.2.1'

implementation 'org.photonvision:photonlib-java:v2025.0.0-alpha-0'
implementation 'org.photonvision:photontargeting-java:v2025.0.0-alpha-0'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

Expand Down Expand Up @@ -75,6 +80,10 @@ repositories {
}
}
gradlePluginPortal()
maven {
name "photonvisionRepositoryReleases"
url "https://maven.photonvision.org/releases"
}
}


Expand Down
9 changes: 0 additions & 9 deletions vision/src/main/java/VisionSimWrapper.java

This file was deleted.

11 changes: 0 additions & 11 deletions vision/src/main/java/VisionSimWrapperBlank.java

This file was deleted.

25 changes: 0 additions & 25 deletions vision/src/main/java/VisionSimWrapperSimulated.java

This file was deleted.

28 changes: 28 additions & 0 deletions vision/src/main/java/coppercore/vision/CameraIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package coppercore.vision;

import org.littletonrobotics.junction.AutoLog;
import org.photonvision.targeting.PhotonPipelineResult;

public interface CameraIO {
@AutoLog
public static class CameraInputs {
public boolean isConnected;

/**
* The last set of unread results from photonvision that wasn't empty. This is purely for
* logging purposes (so that logs aren't empty most of the time)
*/
public PhotonPipelineResult[] latestResults;

/**
* The results of calling getAllUnreadResults() These can be processed once per call of
* updateInputs without any issues with duplicates.
*/
public PhotonPipelineResult[] unreadResults;

/** The timestamp of the latest measurement result, calculated by photonvision */
public double latestTimestampSeconds;
}

public default void updateInputs(CameraInputs inputs) {}
}
25 changes: 25 additions & 0 deletions vision/src/main/java/coppercore/vision/CameraIOPhoton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package coppercore.vision;

import coppercore.vision.CameraIO.CameraInputs;
import java.util.List;
import org.photonvision.PhotonCamera;
import org.photonvision.targeting.PhotonPipelineResult;

public class CameraIOPhoton implements CameraIO {
PhotonCamera camera;

public CameraIOPhoton(CameraParams cameraParams) {
camera = cameraParams.camera();
}

@Override
public void updateInputs(CameraInputs inputs) {
inputs.isConnected = camera.isConnected();
List<PhotonPipelineResult> results = camera.getAllUnreadResults();
if (!results.isEmpty()) {
inputs.latestResults =
camera.getAllUnreadResults().toArray(new PhotonPipelineResult[0]);
inputs.latestTimestampSeconds = results.get(results.size() - 1).getTimestampSeconds();
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e90ad3a

Please sign in to comment.