2021-01-16 20:41:47 -08:00
|
|
|
/*
|
2023-11-19 15:16:22 -05:00
|
|
|
* Copyright (C) Photon Vision.
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2023-11-19 15:16:22 -05:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2023-11-19 15:16:22 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2023-11-19 15:16:22 -05:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2021-01-16 20:41:47 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-12-16 17:05:23 -08:00
|
|
|
#include <span>
|
2021-01-16 20:41:47 -08:00
|
|
|
#include <string>
|
|
|
|
|
|
2021-11-21 17:22:56 -08:00
|
|
|
#include <frc/Errors.h>
|
2021-01-16 20:41:47 -08:00
|
|
|
#include <units/time.h>
|
|
|
|
|
#include <wpi/SmallVector.h>
|
|
|
|
|
|
2023-11-19 15:16:22 -05:00
|
|
|
#include "MultiTargetPNPResult.h"
|
|
|
|
|
#include "PhotonTrackedTarget.h"
|
|
|
|
|
#include "photon/dataflow/structures/Packet.h"
|
2021-01-16 20:41:47 -08:00
|
|
|
|
2023-11-19 15:16:22 -05:00
|
|
|
namespace photon {
|
2021-01-16 20:41:47 -08:00
|
|
|
/**
|
|
|
|
|
* Represents a pipeline result from a PhotonCamera.
|
|
|
|
|
*/
|
|
|
|
|
class PhotonPipelineResult {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2023-11-19 15:16:22 -05:00
|
|
|
* Constructs an empty pipeline result
|
2021-01-16 20:41:47 -08:00
|
|
|
*/
|
|
|
|
|
PhotonPipelineResult() = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs a pipeline result.
|
|
|
|
|
* @param latency The latency in the pipeline.
|
|
|
|
|
* @param targets The list of targets identified by the pipeline.
|
|
|
|
|
*/
|
2023-12-31 00:14:21 -05:00
|
|
|
PhotonPipelineResult(units::millisecond_t latency,
|
2022-12-16 17:05:23 -08:00
|
|
|
std::span<const PhotonTrackedTarget> targets);
|
2021-01-16 20:41:47 -08:00
|
|
|
|
2023-11-19 15:16:22 -05:00
|
|
|
/**
|
|
|
|
|
* Constructs a pipeline result.
|
|
|
|
|
* @param latency The latency in the pipeline.
|
|
|
|
|
* @param targets The list of targets identified by the pipeline.
|
|
|
|
|
* @param multitagResult The multitarget result
|
|
|
|
|
*/
|
2023-12-31 00:14:21 -05:00
|
|
|
PhotonPipelineResult(units::millisecond_t latency,
|
2023-11-19 15:16:22 -05:00
|
|
|
std::span<const PhotonTrackedTarget> targets,
|
|
|
|
|
MultiTargetPNPResult multitagResult);
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
/**
|
|
|
|
|
* Returns the best target in this pipeline result. If there are no targets,
|
2023-11-19 15:16:22 -05:00
|
|
|
* this method will return null. The best target is determined by the target
|
|
|
|
|
* sort mode in the PhotonVision UI.
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
|
|
|
|
* @return The best target of the pipeline result.
|
|
|
|
|
*/
|
|
|
|
|
PhotonTrackedTarget GetBestTarget() const {
|
|
|
|
|
if (!HasTargets() && !HAS_WARNED) {
|
2021-11-21 17:22:56 -08:00
|
|
|
FRC_ReportError(
|
|
|
|
|
frc::warn::Warning, "{}",
|
2021-01-16 20:41:47 -08:00
|
|
|
"This PhotonPipelineResult object has no targets associated with it! "
|
2021-09-03 19:19:38 -07:00
|
|
|
"Please check HasTargets() before calling this method. For more "
|
2021-01-16 20:41:47 -08:00
|
|
|
"information, please review the PhotonLib documentation at "
|
|
|
|
|
"http://docs.photonvision.org");
|
|
|
|
|
HAS_WARNED = true;
|
|
|
|
|
}
|
2021-09-03 19:19:38 -07:00
|
|
|
return HasTargets() ? targets[0] : PhotonTrackedTarget();
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the latency in the pipeline.
|
|
|
|
|
* @return The latency in the pipeline.
|
|
|
|
|
*/
|
2023-12-31 00:14:21 -05:00
|
|
|
units::millisecond_t GetLatency() const { return latency; }
|
2021-01-16 20:41:47 -08:00
|
|
|
|
2022-11-07 11:09:55 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the estimated time the frame was taken,
|
|
|
|
|
* This is much more accurate than using GetLatency()
|
|
|
|
|
* @return The timestamp in seconds or -1 if this result was not initiated
|
|
|
|
|
* with a timestamp.
|
|
|
|
|
*/
|
|
|
|
|
units::second_t GetTimestamp() const { return timestamp; }
|
|
|
|
|
|
2023-10-17 10:20:00 -04:00
|
|
|
/**
|
|
|
|
|
* Return the latest mulit-target result, as calculated on your coprocessor.
|
2023-11-19 15:16:22 -05:00
|
|
|
* Be sure to check getMultiTagResult().estimatedPose.isPresent before using
|
|
|
|
|
* the pose estimate!
|
2023-10-17 10:20:00 -04:00
|
|
|
*/
|
2023-11-19 15:16:22 -05:00
|
|
|
const MultiTargetPNPResult& MultiTagResult() const { return multitagResult; }
|
2023-10-17 10:20:00 -04:00
|
|
|
|
2022-11-07 11:09:55 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the timestamp in seconds
|
|
|
|
|
* @param timestamp The timestamp in seconds
|
|
|
|
|
*/
|
|
|
|
|
void SetTimestamp(const units::second_t timestamp) {
|
|
|
|
|
this->timestamp = timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
/**
|
|
|
|
|
* Returns whether the pipeline has targets.
|
|
|
|
|
* @return Whether the pipeline has targets.
|
|
|
|
|
*/
|
2021-09-03 19:19:38 -07:00
|
|
|
bool HasTargets() const { return targets.size() > 0; }
|
2021-01-16 20:41:47 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a reference to the vector of targets.
|
|
|
|
|
* @return A reference to the vector of targets.
|
|
|
|
|
*/
|
2022-12-16 17:05:23 -08:00
|
|
|
const std::span<const PhotonTrackedTarget> GetTargets() const {
|
2021-01-16 20:41:47 -08:00
|
|
|
return targets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(const PhotonPipelineResult& other) const;
|
|
|
|
|
|
|
|
|
|
friend Packet& operator<<(Packet& packet, const PhotonPipelineResult& result);
|
|
|
|
|
friend Packet& operator>>(Packet& packet, PhotonPipelineResult& result);
|
|
|
|
|
|
2023-12-31 00:14:21 -05:00
|
|
|
units::millisecond_t latency = 0_s;
|
2022-11-07 11:09:55 -07:00
|
|
|
units::second_t timestamp = -1_s;
|
2021-01-16 20:41:47 -08:00
|
|
|
wpi::SmallVector<PhotonTrackedTarget, 10> targets;
|
2023-11-19 15:16:22 -05:00
|
|
|
MultiTargetPNPResult multitagResult;
|
2021-01-16 20:41:47 -08:00
|
|
|
inline static bool HAS_WARNED = false;
|
|
|
|
|
};
|
2023-11-19 15:16:22 -05:00
|
|
|
} // namespace photon
|