2021-01-16 20:41:47 -08:00
|
|
|
/*
|
2022-01-20 19:35:28 -08:00
|
|
|
* MIT License
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* Copyright (c) 2022 PhotonVision
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2021-01-16 20:41:47 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "photonlib/PhotonCamera.h"
|
|
|
|
|
|
|
|
|
|
#include "photonlib/Packet.h"
|
|
|
|
|
|
|
|
|
|
namespace photonlib {
|
|
|
|
|
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTable> rootTable)
|
|
|
|
|
: rawBytesEntry(rootTable->GetEntry("rawBytes")),
|
|
|
|
|
driverModeEntry(rootTable->GetEntry("driverMode")),
|
|
|
|
|
inputSaveImgEntry(rootTable->GetEntry("inputSaveImgCmd")),
|
|
|
|
|
outputSaveImgEntry(rootTable->GetEntry("outputSaveImgCmd")),
|
|
|
|
|
pipelineIndexEntry(rootTable->GetEntry("pipelineIndex")),
|
2021-12-15 11:16:09 -06:00
|
|
|
ledModeEntry(mainTable->GetEntry("ledMode")) {}
|
2021-01-16 20:41:47 -08:00
|
|
|
|
|
|
|
|
PhotonCamera::PhotonCamera(const std::string& cameraName)
|
|
|
|
|
: PhotonCamera(nt::NetworkTableInstance::GetDefault()
|
|
|
|
|
.GetTable("photonvision")
|
|
|
|
|
->GetSubTable(cameraName)) {}
|
|
|
|
|
|
|
|
|
|
PhotonPipelineResult PhotonCamera::GetLatestResult() const {
|
|
|
|
|
// Clear the current packet.
|
|
|
|
|
packet.Clear();
|
|
|
|
|
|
|
|
|
|
// Create the new result;
|
|
|
|
|
PhotonPipelineResult result;
|
|
|
|
|
|
|
|
|
|
// Fill the packet with latest data and populate result.
|
2021-03-21 15:29:29 -05:00
|
|
|
std::shared_ptr<nt::Value> ntvalue = rawBytesEntry.GetValue();
|
|
|
|
|
if (!ntvalue) return result;
|
|
|
|
|
|
2021-11-21 17:22:56 -08:00
|
|
|
std::string value{ntvalue->GetRaw()};
|
2021-01-16 20:41:47 -08:00
|
|
|
std::vector<char> bytes{value.begin(), value.end()};
|
|
|
|
|
|
|
|
|
|
photonlib::Packet packet{bytes};
|
|
|
|
|
|
|
|
|
|
packet >> result;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhotonCamera::SetDriverMode(bool driverMode) {
|
2021-12-15 11:16:09 -06:00
|
|
|
driverModeEntry.SetBoolean(driverMode);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhotonCamera::TakeInputSnapshot() { inputSaveImgEntry.SetBoolean(true); }
|
|
|
|
|
|
|
|
|
|
void PhotonCamera::TakeOutputSnapshot() { outputSaveImgEntry.SetBoolean(true); }
|
|
|
|
|
|
2021-12-15 11:16:09 -06:00
|
|
|
bool PhotonCamera::GetDriverMode() const {
|
|
|
|
|
return driverModeEntry.GetBoolean(false);
|
|
|
|
|
}
|
2021-01-16 20:41:47 -08:00
|
|
|
|
|
|
|
|
void PhotonCamera::SetPipelineIndex(int index) {
|
2021-12-15 11:16:09 -06:00
|
|
|
pipelineIndexEntry.SetDouble(static_cast<double>(index));
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
2021-12-15 11:16:09 -06:00
|
|
|
int PhotonCamera::GetPipelineIndex() const {
|
|
|
|
|
return static_cast<int>(pipelineIndexEntry.GetDouble(0));
|
|
|
|
|
}
|
2021-01-16 20:41:47 -08:00
|
|
|
|
|
|
|
|
LEDMode PhotonCamera::GetLEDMode() const {
|
2021-12-15 11:16:09 -06:00
|
|
|
return static_cast<LEDMode>(static_cast<int>(ledModeEntry.GetDouble(-1.0)));
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
2021-12-15 11:16:09 -06:00
|
|
|
void PhotonCamera::SetLEDMode(LEDMode mode) {
|
|
|
|
|
ledModeEntry.SetDouble(static_cast<double>(static_cast<int>(mode)));
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
} // namespace photonlib
|