Structure for sub-module
This commit is contained in:
parent
362c4d5cd9
commit
12bef1b6a0
|
|
@ -39,10 +39,10 @@ jobs:
|
|||
|
||||
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
|
||||
# the publishing section of your build.gradle
|
||||
- name: Publish to GitHub Packages
|
||||
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
|
||||
with:
|
||||
arguments: -Prelease publish
|
||||
env:
|
||||
USERNAME: ${{ github.actor }}
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# - name: Publish to GitHub Packages
|
||||
# uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
|
||||
# with:
|
||||
# arguments: -Prelease publish
|
||||
# env:
|
||||
# USERNAME: ${{ github.actor }}
|
||||
# TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
/build/
|
||||
/lib/bin
|
||||
|
||||
.vscode
|
||||
.settings
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>RoboLib</name>
|
||||
<comment>Project RoboLib created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1741394171792</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
wpiVersion = 2025.+
|
||||
ctreVersion = 5.+
|
||||
photonVisionVersion = v2024.+
|
||||
advantageKitVersion = 2.2.1
|
||||
|
|
@ -6,10 +6,17 @@
|
|||
* User Manual available at https://docs.gradle.org/7.4.2/userguide/building_java_projects.html
|
||||
*/
|
||||
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
|
||||
plugins {
|
||||
// Apply the java-library plugin for API and implementation separation.
|
||||
id 'java'
|
||||
id 'edu.wpi.first.GradleRIO' version "${wpiVersion}"
|
||||
id "edu.wpi.first.GradleRIO" version "${wpiVersion}"
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
@ -21,49 +28,26 @@ repositories {
|
|||
maven {url "https://maven.photonvision.org/repository/snapshots"}
|
||||
maven {url "https://maven.photonvision.org/repository/internal"}
|
||||
maven {url "https://maven.ctr-electronics.com/release/"}
|
||||
|
||||
maven {
|
||||
url = uri("https://maven.pkg.github.com/Mechanical-Advantage/AdvantageKit")
|
||||
credentials {
|
||||
username = "Mechanical-Advantage-Bot"
|
||||
password = "\u0067\u0068\u0070\u005f\u006e\u0056\u0051\u006a\u0055\u004f\u004c\u0061\u0079\u0066\u006e\u0078\u006e\u0037\u0051\u0049\u0054\u0042\u0032\u004c\u004a\u006d\u0055\u0070\u0073\u0031\u006d\u0037\u004c\u005a\u0030\u0076\u0062\u0070\u0063\u0051"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||
|
||||
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
|
||||
implementation 'com.google.guava:guava:30.1.1-jre'
|
||||
implementation "edu.wpi.first.cscore:cscore-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.cameraserver:cameraserver-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.ntcore:ntcore-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.wpilibj:wpilibj-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.wpiutil:wpiutil-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.wpimath:wpimath-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.hal:hal-java:${wpiVersion}"
|
||||
implementation "edu.wpi.first.apriltag:apriltag-java:${wpiVersion}"
|
||||
implementation "org.ejml:ejml-simple:0.38"
|
||||
implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0"
|
||||
implementation "com.fasterxml.jackson.core:jackson-core:2.10.0"
|
||||
implementation "com.fasterxml.jackson.core:jackson-databind:2.10.0"
|
||||
implementation 'edu.wpi.first.thirdparty.frc2022.opencv:opencv-java:4.5.2-1'
|
||||
// WPI Lib
|
||||
implementation "edu.wpi.first.cscore:cscore-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.cameraserver:cameraserver-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.ntcore:ntcore-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.wpilibj:wpilibj-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.wpiutil:wpiutil-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.wpimath:wpimath-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.wpiunits:wpiunits-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.hal:hal-java:$wpiVersion"
|
||||
implementation "edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:$wpiVersion"
|
||||
|
||||
// CTRE Phoenix
|
||||
implementation "com.ctre.phoenix:api-java:${ctreVersion}"
|
||||
implementation "com.ctre.phoenix:wpiapi-java:${ctreVersion}"
|
||||
|
||||
// PhotonVision
|
||||
implementation "org.photonvision:photonlib-java:${photonVisionVersion}"
|
||||
implementation "org.photonvision:photontargeting-java:${photonVisionVersion}"
|
||||
// CTRE Phoenix 6
|
||||
implementation "com.ctre.phoenix6:wpiapi-java:${ctreVersion}"
|
||||
|
||||
// AdvantageKit
|
||||
implementation "org.littletonrobotics.akit.junction:wpilib-shim:${advantageKitVersion}"
|
||||
implementation "org.littletonrobotics.akit.junction:junction-core:${advantageKitVersion}"
|
||||
implementation "org.littletonrobotics.akit.conduit:conduit-api:${advantageKitVersion}"
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
|
|
|
|||
|
|
@ -1,114 +0,0 @@
|
|||
package com.fairportrobotics.frc.poe.CameraTracking;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.photonvision.PhotonCamera;
|
||||
import org.photonvision.targeting.PhotonTrackedTarget;
|
||||
|
||||
import edu.wpi.first.math.geometry.Transform3d;
|
||||
|
||||
public class AprilTags implements Cloneable {
|
||||
// an ArrayList to store the cameras
|
||||
public final ArrayList<PhotonCamera> cameras = new ArrayList<>();
|
||||
public final ArrayList<PhotonTrackedTarget> frozenResults = new ArrayList<>();
|
||||
public boolean frozen = false;
|
||||
|
||||
public AprilTags(String...cameraNames) {
|
||||
for(String cameraName : cameraNames) {
|
||||
cameras.add(new PhotonCamera(cameraName));
|
||||
}
|
||||
}
|
||||
|
||||
//Method to get a list of all targets without any filtering
|
||||
public List<PhotonTrackedTarget> getAllTargets() {
|
||||
return frozen ? frozenResults : cameras.stream().flatMap((camera) -> camera.getLatestResult().getTargets().stream()).toList();
|
||||
}
|
||||
|
||||
// Method to get a list of all targets with duplicates removed
|
||||
public List<PhotonTrackedTarget> getTargets() {
|
||||
List<PhotonTrackedTarget> targets = new ArrayList<>();
|
||||
|
||||
for(PhotonTrackedTarget target : getAllTargets()) {
|
||||
boolean toAdd = true;
|
||||
List<PhotonTrackedTarget> tempTargets = targets;
|
||||
// check if the target is already in the list and if it has a higher pose ambiguity
|
||||
for(PhotonTrackedTarget arTarget : targets) {
|
||||
if(target.getFiducialId() == arTarget.getFiducialId() && target.getPoseAmbiguity() < arTarget.getPoseAmbiguity()) {
|
||||
// if it does, remove it from the list
|
||||
tempTargets.remove(arTarget);
|
||||
break;
|
||||
} else if(target.getFiducialId() == arTarget.getFiducialId()) {
|
||||
// if the target is already in the list and has the same ID, don't add it
|
||||
toAdd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(toAdd) { tempTargets.add(target); }
|
||||
targets = tempTargets;
|
||||
}
|
||||
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
// method to check if any camera has any targets
|
||||
public boolean hasTargets() {
|
||||
return getAllTargets().size() != 0;
|
||||
}
|
||||
|
||||
// method to get the closest target
|
||||
public PhotonTrackedTarget getClosestTarget() {
|
||||
if(!hasTargets()) { return null; }
|
||||
PhotonTrackedTarget closestTarget = null;
|
||||
for(PhotonTrackedTarget target : getTargets()) {
|
||||
if(closestTarget == null || calculateDistance(closestTarget.getBestCameraToTarget()) > calculateDistance(target.getBestCameraToTarget())) { closestTarget = target; }
|
||||
}
|
||||
return closestTarget;
|
||||
}
|
||||
|
||||
// method to get the target with the lowest pose ambiguity
|
||||
public PhotonTrackedTarget getLowestAmbiguityTarget() {
|
||||
if(!hasTargets()) { return null; }
|
||||
PhotonTrackedTarget lowestAmbiguity = null;
|
||||
for(PhotonTrackedTarget target : getTargets()) {
|
||||
// check if the target has a lower pose ambiguity than the current lowest ambiguity target
|
||||
if(lowestAmbiguity == null || lowestAmbiguity.getPoseAmbiguity() > target.getPoseAmbiguity()) { lowestAmbiguity = target; }
|
||||
}
|
||||
return lowestAmbiguity;
|
||||
}
|
||||
|
||||
private double calculateDistance(Transform3d t) {
|
||||
return Math.sqrt(t.getX()*t.getX() + t.getY()*t.getY());
|
||||
}
|
||||
|
||||
/*
|
||||
* In cases where data needs to be referenced more than once, use this function
|
||||
* to keep the data consistent and prevent any errors.
|
||||
*
|
||||
* Very Important!
|
||||
*/
|
||||
public void freeze() {
|
||||
frozenResults.addAll(getAllTargets());
|
||||
frozen = true;
|
||||
}
|
||||
|
||||
//Unfreeze opposite of freeze
|
||||
public void unFreeze() {
|
||||
frozenResults.clear();
|
||||
frozen = false;
|
||||
}
|
||||
|
||||
|
||||
// There might be a case where you need this so I'm keeping it
|
||||
public Object cloneAndFreeze() {
|
||||
try{
|
||||
AprilTags clone = (AprilTags) super.clone();
|
||||
clone.freeze();
|
||||
return clone;
|
||||
}catch(Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
package com.fairportrobotics.frc.poe.CameraTracking;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.photonvision.PhotonCamera;
|
||||
import org.photonvision.PhotonPoseEstimator;
|
||||
import org.photonvision.PhotonPoseEstimator.PoseStrategy;
|
||||
import org.photonvision.EstimatedRobotPose;
|
||||
|
||||
import edu.wpi.first.apriltag.AprilTagFieldLayout;
|
||||
import edu.wpi.first.apriltag.AprilTagFields;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import edu.wpi.first.math.geometry.Transform3d;
|
||||
|
||||
public class RobotFieldPosition {
|
||||
AprilTagFieldLayout layout;
|
||||
PhotonPoseEstimator photonPoseEstimator;
|
||||
PhotonCamera camera;
|
||||
Optional<EstimatedRobotPose> frozenPose;
|
||||
boolean frozen = false;
|
||||
|
||||
/*
|
||||
* Example of Transform3d:
|
||||
*
|
||||
* Transform3d robotToCam = new Transform3d(new Translation3d(0.5, 0.0, 0.5),
|
||||
* new Rotation3d(0,0,0));
|
||||
* Cam mounted facing forward, half a meter forward of center, half a meter up
|
||||
* from center.
|
||||
*/
|
||||
public RobotFieldPosition(String camera, Transform3d robotToCam, String layoutResourceFile) throws IOException {
|
||||
layout = AprilTagFieldLayout.loadFromResource(layoutResourceFile);
|
||||
|
||||
PhotonCamera cam = new PhotonCamera(camera);
|
||||
photonPoseEstimator = new PhotonPoseEstimator(layout, PoseStrategy.LOWEST_AMBIGUITY, cam, robotToCam);
|
||||
}
|
||||
|
||||
public RobotFieldPosition(String camera, Transform3d robotToCam, String layoutResourceFile, PoseStrategy strategy) throws IOException {
|
||||
layout = AprilTagFieldLayout.loadFromResource(layoutResourceFile);
|
||||
|
||||
PhotonCamera cam = new PhotonCamera(camera);
|
||||
photonPoseEstimator = new PhotonPoseEstimator(layout, strategy, cam, robotToCam);
|
||||
}
|
||||
|
||||
public RobotFieldPosition(String camera, Transform3d robotToCam, AprilTagFields fields) throws IOException {
|
||||
layout = AprilTagFieldLayout.loadFromResource(fields.m_resourceFile);
|
||||
|
||||
PhotonCamera cam = new PhotonCamera(camera);
|
||||
photonPoseEstimator = new PhotonPoseEstimator(layout, PoseStrategy.LOWEST_AMBIGUITY, cam, robotToCam);
|
||||
}
|
||||
|
||||
public RobotFieldPosition(String camera, Transform3d robotToCam, AprilTagFields fields, PoseStrategy strategy) throws IOException {
|
||||
layout = AprilTagFieldLayout.loadFromResource(fields.m_resourceFile);
|
||||
|
||||
PhotonCamera cam = new PhotonCamera(camera);
|
||||
photonPoseEstimator = new PhotonPoseEstimator(layout, strategy, cam, robotToCam);
|
||||
}
|
||||
|
||||
public RobotFieldPosition(String camera, Transform3d robotToCam, AprilTagFieldLayout layout, PoseStrategy strategy) throws IOException {
|
||||
this.layout = layout;
|
||||
|
||||
PhotonCamera cam = new PhotonCamera(camera);
|
||||
photonPoseEstimator = new PhotonPoseEstimator(layout, strategy, cam, robotToCam);
|
||||
}
|
||||
|
||||
public Optional<EstimatedRobotPose> getEstimatedGlobalPose() {
|
||||
return frozen ? frozenPose : photonPoseEstimator.update();
|
||||
}
|
||||
|
||||
public void setLastPose(Pose2d pose) {
|
||||
photonPoseEstimator.setLastPose(pose);
|
||||
}
|
||||
|
||||
public PhotonPoseEstimator getPhotonPoseEstimator(){
|
||||
return photonPoseEstimator;
|
||||
}
|
||||
|
||||
public PhotonCamera getPhotonCamera(){
|
||||
return camera;
|
||||
}
|
||||
|
||||
// For when you want it to stay the same across lines
|
||||
public void freeze() {
|
||||
frozen = true;
|
||||
frozenPose = photonPoseEstimator.update();
|
||||
}
|
||||
|
||||
public void unfreeze() {
|
||||
frozen = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
package com.fairportrobotics.frc.poe.CameraTracking.WPILIB;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import edu.wpi.first.apriltag.AprilTagDetection;
|
||||
import edu.wpi.first.apriltag.AprilTagDetector;
|
||||
import edu.wpi.first.apriltag.AprilTagFieldLayout;
|
||||
import edu.wpi.first.apriltag.AprilTagFields;
|
||||
import edu.wpi.first.apriltag.AprilTagPoseEstimator;
|
||||
import edu.wpi.first.apriltag.AprilTagPoseEstimator.Config;
|
||||
import edu.wpi.first.cscore.VideoCamera;
|
||||
import edu.wpi.first.math.geometry.Pose3d;
|
||||
import edu.wpi.first.math.geometry.Transform3d;
|
||||
import edu.wpi.first.vision.VisionPipeline;
|
||||
import edu.wpi.first.vision.VisionRunner;
|
||||
|
||||
public class WPI_AprilTagPoseEstimator {
|
||||
|
||||
private final AprilTagDetector aprilTagDetector;
|
||||
private final AprilTagPoseEstimator aprilTagPoseEstimator;
|
||||
private AprilTagFieldLayout aprilTagFieldLayout;
|
||||
private Pose3d estimatedPose = new Pose3d();
|
||||
|
||||
private VisionRunner<AprilTagsDetectorPipeline> visionRunner;
|
||||
|
||||
public WPI_AprilTagPoseEstimator(VideoCamera imageSource) {
|
||||
aprilTagDetector = new AprilTagDetector();
|
||||
aprilTagDetector.addFamily("tag16h5");
|
||||
AprilTagPoseEstimator.Config poseEstimatorConfig = new Config(0.203, 0, 0, 0, 0);
|
||||
aprilTagPoseEstimator = new AprilTagPoseEstimator(poseEstimatorConfig);
|
||||
|
||||
try {
|
||||
aprilTagFieldLayout = new AprilTagFieldLayout(AprilTagFields.kDefaultField.m_resourceFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
visionRunner = new VisionRunner<AprilTagsDetectorPipeline>(imageSource, new AprilTagsDetectorPipeline(), new VisionSystemCallback());
|
||||
}
|
||||
|
||||
public void runDetectorPipeline(){
|
||||
new Thread(() -> {
|
||||
try{
|
||||
visionRunner.runForever();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public Pose3d getEstimatedGlobalPose() {
|
||||
return estimatedPose;
|
||||
}
|
||||
|
||||
private final class AprilTagsDetectorPipeline implements VisionPipeline {
|
||||
|
||||
private Pose3d estPose = new Pose3d();
|
||||
|
||||
@Override
|
||||
public void process(Mat image) {
|
||||
AprilTagDetection[] aprilTags = aprilTagDetector.detect(image);
|
||||
|
||||
for (AprilTagDetection aprilTag : aprilTags) {
|
||||
Transform3d tagRelativeToRobot = aprilTagPoseEstimator.estimate(aprilTag);
|
||||
Optional<Pose3d> tagRelativeToFieldOptional = aprilTagFieldLayout.getTagPose(aprilTag.getId());
|
||||
|
||||
if (tagRelativeToFieldOptional.isPresent()) {
|
||||
Pose3d tagRelativeToFieldPose = tagRelativeToFieldOptional.get();
|
||||
Pose3d estimatedFieldPos = tagRelativeToFieldPose.plus(tagRelativeToRobot);
|
||||
// Logger.getInstance().recordOutput("April Tag Pose", tagRelativeToFieldPose);
|
||||
estPose = estimatedFieldPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Pose3d getEstimatedPose(){
|
||||
return estPose;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final class VisionSystemCallback implements VisionRunner.Listener<AprilTagsDetectorPipeline> {
|
||||
@Override
|
||||
public void copyPipelineOutputs(AprilTagsDetectorPipeline pipeline) {
|
||||
estimatedPose = pipeline.getEstimatedPose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package com.fairportrobotics.frc.poe;
|
||||
|
||||
public class Library {
|
||||
public boolean someLibraryMethod() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.fairportrobotics.frc.poe.DriveSystems.SwerveDrive;
|
||||
package org.fairportrobotics.frc.robolib.DriveSystems.SwerveDrive;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.fairportrobotics.frc.poe.controllers.lighting;
|
||||
package org.fairportrobotics.frc.robolib.controllers.lighting;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.fairportrobotics.frc.poe.sensors.colorsensors;
|
||||
package org.fairportrobotics.frc.robolib.sensors.colorsensors;
|
||||
|
||||
import edu.wpi.first.wpilibj.I2C;
|
||||
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package com.fairportrobotics.frc.poe;
|
||||
package com.fairportrobotics.frc.robolib;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LibraryTest {
|
||||
@Test void someLibraryMethodReturnsTrue() {
|
||||
Library classUnderTest = new Library();
|
||||
assertTrue(classUnderTest.someLibraryMethod(), "someLibraryMethod should return 'true'");
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue