diff --git a/photon-lib/.styleguide b/photon-lib/.styleguide index 645ca1a39..02c108125 100644 --- a/photon-lib/.styleguide +++ b/photon-lib/.styleguide @@ -15,6 +15,7 @@ includeProject { includeOtherLibs { ^frc/ + ^networktables/ ^units/ ^wpi/ } diff --git a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java index e75ed5c1b..4cf88578a 100644 --- a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java +++ b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java @@ -195,6 +195,7 @@ public class PhotonCamera { * @deprecated This method should be replaced with {@link PhotonPipelineResult#hasTargets()} * @return Whether the latest target result has targets. */ + @Deprecated public boolean hasTargets() { return getLatestResult().hasTargets(); } diff --git a/photon-lib/src/main/native/cpp/photonlib/PhotonPipelineResult.cpp b/photon-lib/src/main/native/cpp/photonlib/PhotonPipelineResult.cpp index 69354da9f..5f4b726fa 100644 --- a/photon-lib/src/main/native/cpp/photonlib/PhotonPipelineResult.cpp +++ b/photon-lib/src/main/native/cpp/photonlib/PhotonPipelineResult.cpp @@ -21,13 +21,10 @@ namespace photonlib { PhotonPipelineResult::PhotonPipelineResult( units::second_t latency, wpi::ArrayRef targets) : latency(latency), - targets(targets.data(), targets.data() + targets.size()) { - hasTargets = targets.size() != 0; -} + targets(targets.data(), targets.data() + targets.size()) {} bool PhotonPipelineResult::operator==(const PhotonPipelineResult& other) const { - return latency == other.latency && hasTargets == other.hasTargets && - targets == other.targets; + return latency == other.latency && targets == other.targets; } bool PhotonPipelineResult::operator!=(const PhotonPipelineResult& other) const { @@ -35,8 +32,8 @@ bool PhotonPipelineResult::operator!=(const PhotonPipelineResult& other) const { } Packet& operator<<(Packet& packet, const PhotonPipelineResult& result) { - // Encode latency, existence of targets, and number of targets. - packet << result.latency.to() * 1000 << result.hasTargets + // Encode latency and number of targets. + packet << result.latency.to() * 1000 << static_cast(result.targets.size()); // Encode the information of each target. @@ -50,7 +47,7 @@ Packet& operator>>(Packet& packet, PhotonPipelineResult& result) { // Decode latency, existence of targets, and number of targets. int8_t targetCount = 0; double latencyMillis = 0; - packet >> latencyMillis >> result.hasTargets >> targetCount; + packet >> latencyMillis >> targetCount; result.latency = units::second_t(latencyMillis / 1000.0); result.targets.clear(); diff --git a/photon-lib/src/main/native/include/photonlib/PhotonCamera.h b/photon-lib/src/main/native/include/photonlib/PhotonCamera.h index 9cf844933..57b8c6ff4 100644 --- a/photon-lib/src/main/native/include/photonlib/PhotonCamera.h +++ b/photon-lib/src/main/native/include/photonlib/PhotonCamera.h @@ -17,12 +17,13 @@ #pragma once +#include +#include + #include #include #include - -#include -#include +#include #include "photonlib/PhotonPipelineResult.h" @@ -118,9 +119,11 @@ class PhotonCamera { * This method is deprecated; {@link PhotonPipelineResult#hasTargets()} should * be used instead. * @deprecated This method should be replaced with {@link - * PhotonPipelineResult#hasTargets()} + * PhotonPipelineResult#HasTargets()} * @return Whether the latest target result has targets. */ + WPI_DEPRECATED( + "This method should be replaced with PhotonPipelineResult::HasTargets()") bool HasTargets() const { return GetLatestResult().HasTargets(); } private: diff --git a/photon-lib/src/main/native/include/photonlib/PhotonPipelineResult.h b/photon-lib/src/main/native/include/photonlib/PhotonPipelineResult.h index c7b41fb07..413d2529e 100644 --- a/photon-lib/src/main/native/include/photonlib/PhotonPipelineResult.h +++ b/photon-lib/src/main/native/include/photonlib/PhotonPipelineResult.h @@ -57,12 +57,12 @@ class PhotonPipelineResult { if (!HasTargets() && !HAS_WARNED) { ::frc::DriverStation::ReportError( "This PhotonPipelineResult object has no targets associated with it! " - "Please check hasTargets() before calling this method. For more " + "Please check HasTargets() before calling this method. For more " "information, please review the PhotonLib documentation at " "http://docs.photonvision.org"); HAS_WARNED = true; } - return hasTargets ? targets[0] : PhotonTrackedTarget(); + return HasTargets() ? targets[0] : PhotonTrackedTarget(); } /** @@ -75,7 +75,7 @@ class PhotonPipelineResult { * Returns whether the pipeline has targets. * @return Whether the pipeline has targets. */ - bool HasTargets() const { return hasTargets; } + bool HasTargets() const { return targets.size() > 0; } /** * Returns a reference to the vector of targets. @@ -93,7 +93,6 @@ class PhotonPipelineResult { private: units::second_t latency = 0_s; - bool hasTargets = false; wpi::SmallVector targets; inline static bool HAS_WARNED = false; }; diff --git a/photon-lib/src/test/native/cpp/SimVisionSystemTest.cpp b/photon-lib/src/test/native/cpp/SimVisionSystemTest.cpp index b6389aa38..c392be5c8 100644 --- a/photon-lib/src/test/native/cpp/SimVisionSystemTest.cpp +++ b/photon-lib/src/test/native/cpp/SimVisionSystemTest.cpp @@ -18,7 +18,6 @@ #include #include #include - #include #include diff --git a/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java b/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java index 07d9abc9f..479b09458 100644 --- a/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java +++ b/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java @@ -26,7 +26,11 @@ public class Packet { // Read and write positions. int readPos, writePos; - /** Constructs an empty packet. */ + /** + * Constructs an empty packet. + * + * @param size The size of the packet buffer. + */ public Packet(int size) { this.size = size; packetData = new byte[size]; diff --git a/photon-targeting/src/main/java/org/photonvision/targeting/PhotonPipelineResult.java b/photon-targeting/src/main/java/org/photonvision/targeting/PhotonPipelineResult.java index 5764b7a24..308964468 100644 --- a/photon-targeting/src/main/java/org/photonvision/targeting/PhotonPipelineResult.java +++ b/photon-targeting/src/main/java/org/photonvision/targeting/PhotonPipelineResult.java @@ -33,9 +33,6 @@ public class PhotonPipelineResult { // Latency in milliseconds. private double latencyMillis; - // Whether targets exist. - private boolean hasTargets; - /** Constructs an empty pipeline result. */ public PhotonPipelineResult() {} @@ -47,7 +44,6 @@ public class PhotonPipelineResult { */ public PhotonPipelineResult(double latencyMillis, List targets) { this.latencyMillis = latencyMillis; - this.hasTargets = targets.size() != 0; this.targets.addAll(targets); } @@ -67,7 +63,7 @@ public class PhotonPipelineResult { * @return The best target of the pipeline result. */ public PhotonTrackedTarget getBestTarget() { - if (!hasTargets && !HAS_WARNED) { + if (!hasTargets() && !HAS_WARNED) { String errStr = "This PhotonPipelineResult object has no targets associated with it! Please check hasTargets() " + "before calling this method. For more information, please review the PhotonLib " @@ -76,7 +72,7 @@ public class PhotonPipelineResult { new Exception().printStackTrace(); HAS_WARNED = true; } - return hasTargets ? targets.get(0) : null; + return hasTargets() ? targets.get(0) : null; } /** @@ -94,7 +90,7 @@ public class PhotonPipelineResult { * @return Whether the pipeline has targets. */ public boolean hasTargets() { - return hasTargets; + return targets.size() > 0; } /** @@ -112,14 +108,13 @@ public class PhotonPipelineResult { if (o == null || getClass() != o.getClass()) return false; PhotonPipelineResult that = (PhotonPipelineResult) o; boolean latencyMatch = Double.compare(that.latencyMillis, latencyMillis) == 0; - boolean hasTargetsMatch = that.hasTargets == hasTargets; boolean targetsMatch = that.targets.equals(targets); - return latencyMatch && hasTargetsMatch && targetsMatch; + return latencyMatch && targetsMatch; } @Override public int hashCode() { - return Objects.hash(latencyMillis, hasTargets, targets); + return Objects.hash(latencyMillis, targets); } /** @@ -131,7 +126,6 @@ public class PhotonPipelineResult { public Packet createFromPacket(Packet packet) { // Decode latency, existence of targets, and number of targets. latencyMillis = packet.decodeDouble(); - hasTargets = packet.decodeBoolean(); byte targetCount = packet.decodeByte(); targets.clear(); @@ -155,7 +149,6 @@ public class PhotonPipelineResult { public Packet populatePacket(Packet packet) { // Encode latency, existence of targets, and number of targets. packet.encode(latencyMillis); - packet.encode(hasTargets); packet.encode((byte) targets.size()); // Encode the information of each target.