8000 Add delay to version check by mcm001 · Pull Request #466 · PhotonVision/photonvision · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add delay to version check #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions photon-lib/src/main/java/org/photonvision/PhotonCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.common.hardware.VisionLEDMode;
import org.photonvision.targeting.PhotonPipelineResult;
Expand All @@ -46,6 +47,8 @@ public class PhotonCamera {
private final String path;

private static boolean VERSION_CHECK_ENABLED = true;
private static long VERSION_CHECK_INTERVAL = 1;
private double lastVersionCheckTime = 0;

public static void setVersionCheckEnabled(boolean enabled) {
VERSION_CHECK_ENABLED = enabled;
Expand Down Expand Up @@ -207,6 +210,9 @@ public boolean hasTargets() {
private void verifyVersion() {
if (!VERSION_CHECK_ENABLED) return;

if ((Timer.getFPGATimestamp() - lastVersionCheckTime) < VERSION_CHECK_INTERVAL) return;
lastVersionCheckTime = Timer.getFPGATimestamp();

String versionString = versionEntry.getString("");
if (versionString.equals("")) {
DriverStation.reportError(
Expand Down
13 changes: 11 additions & 2 deletions photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
#include "photonlib/PhotonCamera.h"

#include <frc/Errors.h>
#include <frc/Timer.h>

#include "PhotonVersion.h"
#include "photonlib/Packet.h"

namespace photonlib {

constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s;

PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
const std::string& cameraName)
: mainTable(instance->GetTable("photonvision")),
Expand All @@ -48,7 +52,7 @@ PhotonCamera::PhotonCamera(const std::string& cameraName)
nt::NetworkTableInstance::GetDefault()),
cameraName) {}

PhotonPipelineResult PhotonCamera::GetLatestResult() const {
PhotonPipelineResult PhotonCamera::GetLatestResult() {
// Prints warning if not connected
VerifyVersion();

Expand Down Expand Up @@ -99,9 +103,14 @@ void PhotonCamera::SetLEDMode(LEDMode mode) {
ledModeEntry.SetDouble(static_cast<double>(static_cast<int>(mode)));
}

void PhotonCamera::VerifyVersion() const {
void PhotonCamera::VerifyVersion() {
if (!PhotonCamera::VERSION_CHECK_ENABLED) return;

if ((frc::Timer::GetFPGATimestamp() - lastVersionCheckTime) <
VERSION_CHECK_INTERVAL)
return;
this->lastVersionCheckTime = frc::Timer::GetFPGATimestamp();

const std::string& versionString = versionEntry.GetString("");
if (versionString.empty()) {
std::string path_ = path;
Expand Down
8 changes: 5 additions & 3 deletions photon-lib/src/main/native/include/photonlib/PhotonCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableEntry.h>
#include <networktables/NetworkTableInstance.h>
#include <units/time.h>
#include <wpi/deprecated.h>

#include "photonlib/PhotonPipelineResult.h"
Expand Down Expand Up @@ -66,7 +67,7 @@ class PhotonCamera {
* Returns the latest pipeline result.
* @return The latest pipeline result.
*/
PhotonPipelineResult GetLatestResult() const;
PhotonPipelineResult GetLatestResult();

/**
* Toggles driver mode.
Expand Down Expand Up @@ -136,7 +137,7 @@ class PhotonCamera {
*/
WPI_DEPRECATED(
"This method should be replaced with PhotonPipelineResult::HasTargets()")
bool HasTargets() const { return GetLatestResult().HasTargets(); }
bool HasTargets() { return GetLatestResult().HasTargets(); }

inline static void SetVersionCheckEnabled(bool enabled) {
PhotonCamera::VERSION_CHECK_ENABLED = enabled;
Expand All @@ -158,9 +159,10 @@ class PhotonCamera {
mutable Packet packet;

private:
units::second_t lastVersionCheckTime = 0_s;
inline static bool VERSION_CHECK_ENABLED = true;

void VerifyVersion() const;
void VerifyVersion();
};

} // namespace photonlib
0