-
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.
Update camera data structuring to hold camera names in an object inst…
…ead of as an input
- Loading branch information
1 parent
858ebc6
commit a53b924
Showing
10 changed files
with
138 additions
and
124 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
80 changes: 80 additions & 0 deletions
80
src/main/java/frc/robot/subsystems/localization/Camera.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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package frc.robot.subsystems.localization; | ||
|
||
import org.littletonrobotics.junction.Logger; | ||
|
||
import edu.wpi.first.math.Matrix; | ||
import edu.wpi.first.math.numbers.N1; | ||
import edu.wpi.first.math.numbers.N3; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
import frc.robot.Constants.FieldConstants; | ||
import frc.robot.Constants.VisionConstants; | ||
import frc.robot.Constants.VisionConstants.CameraParams; | ||
import frc.robot.subsystems.localization.VisionLocalizer.CameraMeasurement; | ||
|
||
public class Camera { | ||
|
||
public enum CameraTrustZone { | ||
LEFT, | ||
RIGHT, | ||
MIDDLE, | ||
} | ||
|
||
public final String name; | ||
public final CameraTrustZone zone; | ||
|
||
private final CameraIO io; | ||
private final CameraIOInputsAutoLogged inputs; | ||
|
||
|
||
public Camera(CameraParams params, CameraIO io) { | ||
name = params.name(); | ||
zone = params.zone(); | ||
|
||
this.io = io; | ||
inputs = new CameraIOInputsAutoLogged(); | ||
} | ||
|
||
public void update() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Vision/" + name, inputs); | ||
} | ||
|
||
public boolean hasNewMeasurement() { | ||
return inputs.wasAccepted; | ||
} | ||
|
||
public boolean isConnected() { | ||
return inputs.connected; | ||
} | ||
|
||
public CameraMeasurement getLatestMeasurement() { | ||
return new CameraMeasurement(inputs.latestFieldToRobot, inputs.latestTimestampSeconds, getLatestVariance()); | ||
} | ||
|
||
public Matrix<N3, N1> getLatestVariance() { | ||
if (!DriverStation.isTeleop()) { | ||
if (inputs.latestFieldToRobot.getY() > FieldConstants.fieldToBlueSpeaker.getY() - 2 | ||
&& zone == CameraTrustZone.LEFT) { | ||
return VisionConstants.highCameraUncertainty; | ||
} | ||
|
||
if (inputs.latestFieldToRobot.getY() < FieldConstants.fieldToBlueSpeaker.getY() + 2 | ||
&& zone == CameraTrustZone.RIGHT) { | ||
return VisionConstants.highCameraUncertainty; | ||
} | ||
} | ||
|
||
if (inputs.averageTagDistanceM < VisionConstants.skewCutoffDistance) { | ||
if (!DriverStation.isTeleop()) { | ||
return VisionConstants.lowCameraUncertainty; | ||
} else { | ||
return VisionConstants.teleopCameraUncertainty; | ||
} | ||
} else if (inputs.averageTagDistanceM < VisionConstants.lowUncertaintyCutoffDistance | ||
&& Math.abs(inputs.averageTagYaw.getDegrees()) < VisionConstants.skewCutoffRotation) { | ||
return VisionConstants.lowCameraUncertainty; | ||
} else { | ||
return VisionConstants.highCameraUncertainty; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.