mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-01 02:41:42 +00:00
Add disabled param for PhotonCamera (#2484)
This commit is contained in:
@@ -54,6 +54,13 @@ class NTTopicSet:
|
||||
|
||||
self.fpsLimitSubscriber.getTopic().publish().setDefault(-1)
|
||||
|
||||
self.enabledPublisher = self.subTable.getBooleanTopic("enabled").publish()
|
||||
self.enabledSubscriber = self.subTable.getBooleanTopic(
|
||||
"enabledRequest"
|
||||
).subscribe(True)
|
||||
|
||||
self.enabledSubscriber.getTopic().publish().setDefault(True)
|
||||
|
||||
self.latencyMillisEntry = self.subTable.getDoubleTopic(
|
||||
"latencyMillis"
|
||||
).publish()
|
||||
|
||||
@@ -80,6 +80,12 @@ class PhotonCamera:
|
||||
self._fpsLimitSubscriber = self._cameraTable.getIntegerTopic(
|
||||
"fpsLimit"
|
||||
).subscribe(-1)
|
||||
self._enabledPublisher = self._cameraTable.getBooleanTopic(
|
||||
"enabledRequest"
|
||||
).publish()
|
||||
self._enabledSubscriber = self._cameraTable.getBooleanTopic(
|
||||
"enabled"
|
||||
).subscribe(True)
|
||||
self._inputSaveImgEntry = self._cameraTable.getIntegerTopic(
|
||||
"inputSaveImgCmd"
|
||||
).getEntry(0)
|
||||
@@ -204,11 +210,28 @@ class PhotonCamera:
|
||||
def setFPSLimit(self, fpsLimit: int) -> None:
|
||||
"""Sets the FPS limit on the camera.
|
||||
|
||||
:param fpsLimit: The FPS limit to set. Set to -1 for unlimited FPS.
|
||||
<p>A negative FPS limit is treated as no FPS limit, and will run as fast as possible.
|
||||
|
||||
<p>Otherwise, will limit processing to at most the provided FPS limit
|
||||
|
||||
:param fpsLimit: The FPS limit to set.
|
||||
"""
|
||||
|
||||
self._fpsLimitPublisher.set(fpsLimit)
|
||||
|
||||
def getEnabled(self) -> bool:
|
||||
""":returns: Whether the camera is enabled."""
|
||||
|
||||
return self._enabledSubscriber.get()
|
||||
|
||||
def setEnabled(self, enabled: bool) -> None:
|
||||
"""Sets whether the camera is enabled, default is true.
|
||||
|
||||
:param enabled: Whether to enable the camera.
|
||||
"""
|
||||
|
||||
self._enabledPublisher.set(enabled)
|
||||
|
||||
def takeInputSnapshot(self) -> None:
|
||||
"""Request the camera to save a new image file from the input camera stream with overlays. Images
|
||||
take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk
|
||||
|
||||
@@ -65,6 +65,8 @@ public class PhotonCamera implements AutoCloseable {
|
||||
BooleanSubscriber driverModeSubscriber;
|
||||
IntegerPublisher fpsLimitPublisher;
|
||||
IntegerSubscriber fpsLimitSubscriber;
|
||||
BooleanSubscriber enabledSubscriber;
|
||||
BooleanPublisher enabledPublisher;
|
||||
StringSubscriber versionEntry;
|
||||
IntegerEntry inputSaveImgEntry, outputSaveImgEntry;
|
||||
IntegerPublisher pipelineIndexRequest, ledModeRequest;
|
||||
@@ -82,6 +84,8 @@ public class PhotonCamera implements AutoCloseable {
|
||||
driverModeSubscriber.close();
|
||||
fpsLimitPublisher.close();
|
||||
fpsLimitSubscriber.close();
|
||||
enabledPublisher.close();
|
||||
enabledSubscriber.close();
|
||||
versionEntry.close();
|
||||
inputSaveImgEntry.close();
|
||||
outputSaveImgEntry.close();
|
||||
@@ -155,6 +159,8 @@ public class PhotonCamera implements AutoCloseable {
|
||||
driverModeSubscriber = cameraTable.getBooleanTopic("driverMode").subscribe(false);
|
||||
fpsLimitPublisher = cameraTable.getIntegerTopic("fpsLimitRequest").publish();
|
||||
fpsLimitSubscriber = cameraTable.getIntegerTopic("fpsLimit").subscribe(-1);
|
||||
enabledPublisher = cameraTable.getBooleanTopic("enabledRequest").publish();
|
||||
enabledSubscriber = cameraTable.getBooleanTopic("enabled").subscribe(true);
|
||||
inputSaveImgEntry = cameraTable.getIntegerTopic("inputSaveImgCmd").getEntry(0);
|
||||
outputSaveImgEntry = cameraTable.getIntegerTopic("outputSaveImgCmd").getEntry(0);
|
||||
pipelineIndexRequest = cameraTable.getIntegerTopic("pipelineIndexRequest").publish();
|
||||
@@ -344,8 +350,6 @@ public class PhotonCamera implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the FPS limit set on the camera.
|
||||
*
|
||||
* @return The current FPS limit.
|
||||
*/
|
||||
public int getFPSLimit() {
|
||||
@@ -355,12 +359,32 @@ public class PhotonCamera implements AutoCloseable {
|
||||
/**
|
||||
* Sets the FPS limit on the camera.
|
||||
*
|
||||
* @param fps The FPS limit to set. Set to -1 for unlimited FPS.
|
||||
* <p>A negative FPS limit is treated as no FPS limit, and will run as fast as possible.
|
||||
*
|
||||
* <p>Otherwise, will limit processing to at most the provided FPS limit
|
||||
*
|
||||
* @param fps The FPS limit to set.
|
||||
*/
|
||||
public void setFPSLimit(int fps) {
|
||||
fpsLimitPublisher.set(fps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the camera is enabled, default is true.
|
||||
*
|
||||
* @param enabled Whether to enable the camera.
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
enabledPublisher.set(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the camera is enabled.
|
||||
*/
|
||||
public boolean getEnabled() {
|
||||
return enabledSubscriber.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the camera to save a new image file from the input camera stream with overlays. Images
|
||||
* take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk
|
||||
|
||||
@@ -157,6 +157,8 @@ PhotonCamera::PhotonCamera(wpi::nt::NetworkTableInstance instance,
|
||||
fpsLimitSubscriber(rootTable->GetIntegerTopic("fpsLimit").Subscribe(-1)),
|
||||
fpsLimitPublisher(
|
||||
rootTable->GetIntegerTopic("fpsLimitRequest").Publish()),
|
||||
enabledSubscriber(rootTable->GetBooleanTopic("enabled").Subscribe(true)),
|
||||
enabledPublisher(rootTable->GetBooleanTopic("enabledRequest").Publish()),
|
||||
heartbeatSubscriber(
|
||||
rootTable->GetIntegerTopic("heartbeat").Subscribe(-1)),
|
||||
topicNameSubscriber(instance, PHOTON_PREFIX, {.topicsOnly = true}),
|
||||
@@ -291,6 +293,10 @@ void PhotonCamera::SetFPSLimit(int fpsLimit) {
|
||||
fpsLimitPublisher.Set(fpsLimit);
|
||||
}
|
||||
|
||||
bool PhotonCamera::GetEnabled() const { return enabledSubscriber.Get(); }
|
||||
|
||||
void PhotonCamera::SetEnabled(bool enabled) { enabledPublisher.Set(enabled); }
|
||||
|
||||
void PhotonCamera::TakeInputSnapshot() {
|
||||
inputSaveImgEntry.Set(inputSaveImgSubscriber.Get() + 1);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,17 @@ class PhotonCamera {
|
||||
bool GetDriverMode() const;
|
||||
|
||||
/**
|
||||
* @param fpsLimit The FPS limit to set. Use -1 for unlimited FPS.
|
||||
* Sets the FPS limit on the camera.
|
||||
*
|
||||
* <p>An FPS of 0 means to pause processing until a FPS limit greater than 0
|
||||
* is set.
|
||||
*
|
||||
* <p>A negative FPS limit is treated as no FPS limit, and will run as fast as
|
||||
* possible.
|
||||
*
|
||||
* <p>Otherwise, will limit processing to at most the provided FPS limit
|
||||
*
|
||||
* @param fps The FPS limit to set.
|
||||
*/
|
||||
void SetFPSLimit(int fpsLimit);
|
||||
|
||||
@@ -113,6 +123,17 @@ class PhotonCamera {
|
||||
*/
|
||||
int GetFPSLimit() const;
|
||||
|
||||
/**
|
||||
* Sets whether the camera is enabled, default is true.
|
||||
* @param enabled Whether to enable the camera.
|
||||
*/
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* @return Whether the camera is enabled.
|
||||
*/
|
||||
bool GetEnabled() const;
|
||||
|
||||
/**
|
||||
* Request the camera to save a new image file from the input
|
||||
* camera stream with overlays.
|
||||
@@ -233,6 +254,8 @@ class PhotonCamera {
|
||||
wpi::nt::BooleanPublisher driverModePublisher;
|
||||
wpi::nt::IntegerSubscriber fpsLimitSubscriber;
|
||||
wpi::nt::IntegerPublisher fpsLimitPublisher;
|
||||
wpi::nt::BooleanSubscriber enabledSubscriber;
|
||||
wpi::nt::BooleanPublisher enabledPublisher;
|
||||
|
||||
wpi::nt::IntegerSubscriber ledModeSubscriber;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user