mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-04 03:11:40 +00:00
Expose camera name in PhotonCamera (#523)
Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -80,6 +80,7 @@ public class PhotonCamera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final String path;
|
private final String path;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
private static boolean VERSION_CHECK_ENABLED = true;
|
private static boolean VERSION_CHECK_ENABLED = true;
|
||||||
private static long VERSION_CHECK_INTERVAL = 5;
|
private static long VERSION_CHECK_INTERVAL = 5;
|
||||||
@@ -104,6 +105,7 @@ public class PhotonCamera {
|
|||||||
* @param cameraName The name of the camera, as seen in the UI.
|
* @param cameraName The name of the camera, as seen in the UI.
|
||||||
*/
|
*/
|
||||||
public PhotonCamera(NetworkTableInstance instance, String cameraName) {
|
public PhotonCamera(NetworkTableInstance instance, String cameraName) {
|
||||||
|
name = cameraName;
|
||||||
var mainTable = instance.getTable("photonvision");
|
var mainTable = instance.getTable("photonvision");
|
||||||
this.rootTable = mainTable.getSubTable(cameraName);
|
this.rootTable = mainTable.getSubTable(cameraName);
|
||||||
path = rootTable.getPath();
|
path = rootTable.getPath();
|
||||||
@@ -252,6 +254,16 @@ public class PhotonCamera {
|
|||||||
return getLatestResult().hasTargets();
|
return getLatestResult().hasTargets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the camera. This will return the same value that was given to the
|
||||||
|
* constructor as cameraName.
|
||||||
|
*
|
||||||
|
* @return The name of the camera.
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the camera is connected and actively returning new data. Connection status is
|
* Returns whether the camera is connected and actively returning new data. Connection status is
|
||||||
* debounced.
|
* debounced.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace photonlib {
|
|||||||
constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s;
|
constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s;
|
||||||
|
|
||||||
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
||||||
const std::string& cameraName)
|
const std::string_view cameraName)
|
||||||
: mainTable(instance->GetTable("photonvision")),
|
: mainTable(instance->GetTable("photonvision")),
|
||||||
rootTable(mainTable->GetSubTable(cameraName)),
|
rootTable(mainTable->GetSubTable(cameraName)),
|
||||||
rawBytesEntry(rootTable->GetRawTopic("rawBytes").Subscribe("raw", {})),
|
rawBytesEntry(rootTable->GetRawTopic("rawBytes").Subscribe("raw", {})),
|
||||||
@@ -52,9 +52,10 @@ PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
|||||||
pipelineIndexSubscriber(
|
pipelineIndexSubscriber(
|
||||||
rootTable->GetIntegerTopic("pipelineIndex").Subscribe(-1)),
|
rootTable->GetIntegerTopic("pipelineIndex").Subscribe(-1)),
|
||||||
ledModeSubscriber(mainTable->GetIntegerTopic("ledMode").Subscribe(0)),
|
ledModeSubscriber(mainTable->GetIntegerTopic("ledMode").Subscribe(0)),
|
||||||
path(rootTable->GetPath()) {}
|
path(rootTable->GetPath()),
|
||||||
|
m_cameraName(cameraName) {}
|
||||||
|
|
||||||
PhotonCamera::PhotonCamera(const std::string& cameraName)
|
PhotonCamera::PhotonCamera(const std::string_view cameraName)
|
||||||
: PhotonCamera(std::make_shared<nt::NetworkTableInstance>(
|
: PhotonCamera(std::make_shared<nt::NetworkTableInstance>(
|
||||||
nt::NetworkTableInstance::GetDefault()),
|
nt::NetworkTableInstance::GetDefault()),
|
||||||
cameraName) {}
|
cameraName) {}
|
||||||
@@ -109,6 +110,10 @@ void PhotonCamera::SetLEDMode(LEDMode mode) {
|
|||||||
ledModeEntry.Set(static_cast<double>(static_cast<int>(mode)));
|
ledModeEntry.Set(static_cast<double>(static_cast<int>(mode)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string_view PhotonCamera::GetCameraName() const {
|
||||||
|
return m_cameraName;
|
||||||
|
}
|
||||||
|
|
||||||
void PhotonCamera::VerifyVersion() {
|
void PhotonCamera::VerifyVersion() {
|
||||||
if (!PhotonCamera::VERSION_CHECK_ENABLED) return;
|
if (!PhotonCamera::VERSION_CHECK_ENABLED) return;
|
||||||
|
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ class PhotonCamera {
|
|||||||
* over.
|
* over.
|
||||||
*/
|
*/
|
||||||
explicit PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
explicit PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
||||||
const std::string& cameraName);
|
const std::string_view cameraName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a PhotonCamera from the name of the camera.
|
* Constructs a PhotonCamera from the name of the camera.
|
||||||
* @param cameraName The nickname of the camera (found in the PhotonVision
|
* @param cameraName The nickname of the camera (found in the PhotonVision
|
||||||
* UI).
|
* UI).
|
||||||
*/
|
*/
|
||||||
explicit PhotonCamera(const std::string& cameraName);
|
explicit PhotonCamera(const std::string_view cameraName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the latest pipeline result.
|
* Returns the latest pipeline result.
|
||||||
@@ -131,6 +131,14 @@ class PhotonCamera {
|
|||||||
*/
|
*/
|
||||||
void SetLEDMode(LEDMode led);
|
void SetLEDMode(LEDMode led);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the camera.
|
||||||
|
* This will return the same value that was given to the constructor as
|
||||||
|
* cameraName.
|
||||||
|
* @return The name of the camera.
|
||||||
|
*/
|
||||||
|
const std::string_view GetCameraName() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the latest target result has targets.
|
* Returns whether the latest target result has targets.
|
||||||
* This method is deprecated; {@link PhotonPipelineResult#hasTargets()} should
|
* This method is deprecated; {@link PhotonPipelineResult#hasTargets()} should
|
||||||
@@ -163,6 +171,7 @@ class PhotonCamera {
|
|||||||
nt::IntegerSubscriber ledModeSubscriber;
|
nt::IntegerSubscriber ledModeSubscriber;
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
std::string m_cameraName;
|
||||||
|
|
||||||
mutable Packet packet;
|
mutable Packet packet;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user