-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 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
46 changes: 46 additions & 0 deletions
46
src/main/java/frc/robot/subsystems/limelight/Limelight.java
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 |
---|---|---|
@@ -1 +1,47 @@ | ||
package frc.robot.subsystems.limelight; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.subsystems.drive.Drive; | ||
|
||
public class Limelight extends SubsystemBase { | ||
LimelightIO io; | ||
Drive drive; | ||
LimelightIOInputsAutoLogged inputs = new LimelightIOInputsAutoLogged(); | ||
public Limelight(LimelightIO io, Drive drive) { | ||
this.io = io; | ||
this.drive = drive; | ||
} | ||
|
||
public void periodic() { | ||
io.updateInputs(inputs); | ||
|
||
if (inputs.pose.getX() == 0) { | ||
return; | ||
} | ||
|
||
if (inputs.tagCount > 0) { | ||
double poseDifference = drive.getPose().getTranslation().getDistance(inputs.pose); | ||
double xyStds, degStds; | ||
|
||
// copied from limelight docs | ||
// https://docs.limelightvision.io/docs/docs-limelight/pipeline-apriltag/apriltag-robot-localization | ||
if (inputs.tagCount >= 2) { | ||
xyStds = 0.5; | ||
degStds = 6; | ||
} | ||
else if (inputs.averageTagArea > .4 && poseDifference < 0.5) { | ||
xyStds = 1.0; | ||
degStds = 12; | ||
} else if (inputs.averageTagArea > .05 && poseDifference < .5) { | ||
xyStds = 2.0; | ||
degStds = 30; | ||
} else { | ||
return; | ||
} | ||
|
||
drive.addVisionMeasurement(xyStds, degStds, new Pose2d(inputs.pose, inputs.yaw), inputs.latency); | ||
} | ||
|
||
} | ||
} |
11 changes: 5 additions & 6 deletions
11
src/main/java/frc/robot/subsystems/limelight/LimelightIO.java
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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
package frc.robot.subsystems.limelight; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
import edu.wpi.first.math.geometry.Translation3d; | ||
|
||
public interface LimelightIO { | ||
@AutoLog | ||
public static class LimelightIOInputs { | ||
public double latency = 0.0; | ||
|
||
public Translation3d pose = new Translation3d(); | ||
public double roll = 0.0, pitch = 0.0, yaw = 0.0; | ||
public Translation2d pose = new Translation2d(); | ||
public Rotation2d roll = new Rotation2d(), pitch = new Rotation2d(), yaw = new Rotation2d(); | ||
public double tagCount = 0.0, tagSpan = 0.0, averageTagDistance = 0.0, averageTagArea = 0.0; | ||
} | ||
|
||
public default void updateInputs(LimelightIOInputs inputs) { | ||
} | ||
public default void updateInputs(LimelightIOInputs inputs) {} | ||
} |
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