Add version verification disable switch in photonlib (#437)

This commit is contained in:
Matt
2022-02-28 07:37:52 -05:00
committed by GitHub
parent 5655ca6890
commit 9090aa6bcc
5 changed files with 18 additions and 0 deletions

View File

@@ -45,6 +45,12 @@ public class PhotonCamera {
private final String path;
private static boolean VERSION_CHECK_ENABLED = true;
public static void setVersionCheckEnabled(boolean enabled) {
VERSION_CHECK_ENABLED = enabled;
}
Packet packet = new Packet(1);
/**
@@ -199,6 +205,8 @@ public class PhotonCamera {
}
private void verifyVersion() {
if (!VERSION_CHECK_ENABLED) return;
String versionString = versionEntry.getString("");
if (versionString.equals("")) {
DriverStation.reportError(

View File

@@ -100,6 +100,8 @@ void PhotonCamera::SetLEDMode(LEDMode mode) {
}
void PhotonCamera::VerifyVersion() const {
if (!PhotonCamera::VERSION_CHECK_ENABLED) return;
const std::string& versionString = versionEntry.GetString("");
if (versionString.empty()) {
std::string path_ = path;

View File

@@ -138,6 +138,10 @@ class PhotonCamera {
"This method should be replaced with PhotonPipelineResult::HasTargets()")
bool HasTargets() const { return GetLatestResult().HasTargets(); }
inline static void SetVersionCheckEnabled(bool enabled) {
PhotonCamera::VERSION_CHECK_ENABLED = enabled;
}
protected:
std::shared_ptr<nt::NetworkTable> mainTable;
std::shared_ptr<nt::NetworkTable> rootTable;
@@ -154,6 +158,8 @@ class PhotonCamera {
mutable Packet packet;
private:
inline static bool VERSION_CHECK_ENABLED = true;
void VerifyVersion() const;
};

View File

@@ -130,6 +130,7 @@ class SimVisionSystemTest {
new SimVisionSystem("Test", 80.0, 0.0, new Transform2d(), 1, 99999, 640, 480, 0);
sysUnderTest.addSimVisionTarget(new SimVisionTarget(targetPose, 1.0, 3.0, 3.0));
PhotonCamera.setVersionCheckEnabled(false);
var robotPose = new Pose2d(new Translation2d(5, 0), Rotation2d.fromDegrees(5));
sysUnderTest.processFrame(robotPose);
assertTrue(sysUnderTest.cam.getLatestResult().hasTargets());

View File

@@ -294,6 +294,7 @@ TEST_P(SimVisionSystemCameraPitchParamTest, CameraPitch) {
frc::Transform2d(frc::Translation2d(), frc::Rotation2d()), 0.0_m,
units::degree_t(testPitch));
photonlib::PhotonCamera::SetVersionCheckEnabled(false);
sysUnderTest.ProcessFrame(robotPose);
auto result = sysUnderTest.cam.GetLatestResult();
ASSERT_TRUE(result.HasTargets());