Update PhotonCamera error messages to be more specific (#697)

Closes #692
This commit is contained in:
Nick Hadley
2023-01-05 19:28:32 -05:00
committed by GitHub
parent 05198ef294
commit 0f427bb52b
6 changed files with 68 additions and 23 deletions

View File

@@ -33,10 +33,11 @@
namespace photonlib {
constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s;
static const std::vector<std::string_view> PHOTON_PREFIX = {"/photonvision/"};
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
PhotonCamera::PhotonCamera(nt::NetworkTableInstance instance,
const std::string_view cameraName)
: mainTable(instance->GetTable("photonvision")),
: mainTable(instance.GetTable("photonvision")),
rootTable(mainTable->GetSubTable(cameraName)),
rawBytesEntry(rootTable->GetRawTopic("rawBytes").Subscribe("raw", {})),
driverModeEntry(rootTable->GetBooleanTopic("driverMode").Publish()),
@@ -56,13 +57,12 @@ PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
pipelineIndexSubscriber(
rootTable->GetIntegerTopic("pipelineIndex").Subscribe(-1)),
ledModeSubscriber(mainTable->GetIntegerTopic("ledMode").Subscribe(0)),
m_topicNameSubscriber(instance, PHOTON_PREFIX, {.topicsOnly = true}),
path(rootTable->GetPath()),
m_cameraName(cameraName) {}
PhotonCamera::PhotonCamera(const std::string_view cameraName)
: PhotonCamera(std::make_shared<nt::NetworkTableInstance>(
nt::NetworkTableInstance::GetDefault()),
cameraName) {}
: PhotonCamera(nt::NetworkTableInstance::GetDefault(), cameraName) {}
PhotonPipelineResult PhotonCamera::GetLatestResult() {
if (test) return testResult;
@@ -134,10 +134,29 @@ void PhotonCamera::VerifyVersion() {
const std::string& versionString = versionEntry.Get("");
if (versionString.empty()) {
std::string path_ = path;
FRC_ReportError(
frc::warn::Warning,
"PhotonVision coprocessor at path {} not found on NetworkTables!",
path_);
std::vector<std::string> cameraNames =
rootTable->GetInstance().GetTable("photonvision")->GetSubTables();
if (cameraNames.empty()) {
FRC_ReportError(frc::warn::Warning,
"Could not find any PhotonVision coprocessors on "
"NetworkTables. Double check that PhotonVision is "
"running, and that your camera is connected!");
} else {
FRC_ReportError(
frc::warn::Warning,
"PhotonVision coprocessor at path {} not found on NetworkTables. "
"Double check that your camera names match!",
path_);
std::string cameraNameOutString;
for (unsigned int i = 0; i < cameraNames.size(); i++) {
cameraNameOutString += "\n" + cameraNames[i];
}
FRC_ReportError(
frc::warn::Warning,
"Found the following PhotonVision cameras on NetworkTables:{}",
cameraNameOutString);
}
} else if (!VersionMatches(versionString)) {
FRC_ReportError(frc::warn::Warning,
"Photon version {} does not match coprocessor version {}!",