PhotonVision C++ dev-v2025.0.0-beta-8-2-gbd1c5c03
Loading...
Searching...
No Matches
PhotonPipelineResult.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Photon Vision.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <span>
21#include <string>
22#include <utility>
23
24#include <units/time.h>
25#include <wpi/SmallVector.h>
26
28#include "PhotonTrackedTarget.h"
29#include "fmt/base.h"
32
33namespace photon {
34/**
35 * Represents a pipeline result from a PhotonCamera.
36 */
39
40 public:
42 explicit PhotonPipelineResult(Base&& data) : Base(data) {}
43
44 // Don't forget to deal with our ntReceiveTimestamp
50 : Base(std::move(other)),
51 ntReceiveTimestamp(std::move(other.ntReceiveTimestamp)) {}
52 auto& operator=(const PhotonPipelineResult& other) {
53 Base::operator=(other);
55 return *this;
56 }
58 ntReceiveTimestamp = other.ntReceiveTimestamp;
59 Base::operator=(std::move(other));
60 return *this;
61 }
62
63 template <typename... Args>
64 explicit PhotonPipelineResult(Args&&... args)
65 : Base{std::forward<Args>(args)...} {}
66
67 /**
68 * Returns the best target in this pipeline result. If there are no targets,
69 * this method will return null. The best target is determined by the target
70 * sort mode in the PhotonVision UI.
71 *
72 * @return The best target of the pipeline result.
73 */
75 if (!HasTargets() && !HAS_WARNED) {
76 fmt::println(
77 "WARNING: This PhotonPipelineResult object has no targets associated "
78 "with it! "
79 "Please check HasTargets() before calling this method. For more "
80 "information, please review the PhotonLib documentation at "
81 "http://docs.photonvision.org");
82 HAS_WARNED = true;
83 }
84 return HasTargets() ? targets[0] : PhotonTrackedTarget{};
85 }
86
87 /**
88 * Returns the latency in the pipeline.
89 * @return The latency in the pipeline.
90 */
91 units::millisecond_t GetLatency() const {
92 return units::microsecond_t{static_cast<double>(
94 }
95
96 /**
97 * Returns the estimated time the frame was taken,
98 * This is much more accurate than using GetLatency()
99 * @return The timestamp in seconds or -1 if this result was not initiated
100 * with a timestamp.
101 */
102 units::second_t GetTimestamp() const {
104 }
105
106 /**
107 * Return the latest mulit-target result, as calculated on your coprocessor.
108 * Be sure to check getMultiTagResult().estimatedPose.isPresent before using
109 * the pose estimate!
110 */
111 const std::optional<MultiTargetPNPResult>& MultiTagResult() const {
112 return multitagResult;
113 }
114
115 /**
116 * The number of non-empty frames processed by this camera since boot. Useful
117 * to checking if a camera is alive.
118 */
119 int64_t SequenceID() const { return metadata.sequenceID; }
120
121 /** Sets the FPGA timestamp this result was Received by robot code */
122 void SetReceiveTimestamp(const units::second_t timestamp) {
123 this->ntReceiveTimestamp = timestamp;
124 }
125
126 /**
127 * Returns whether the pipeline has targets.
128 * @return Whether the pipeline has targets.
129 */
130 bool HasTargets() const { return targets.size() > 0; }
131
132 /**
133 * Returns a reference to the vector of targets.
134 * <p> Returned in the order set by target sort mode. </p>
135 * @return A reference to the vector of targets.
136 */
137 const std::span<const PhotonTrackedTarget> GetTargets() const {
138 return targets;
139 }
140
142 PhotonPipelineResult const&) = default;
143
144 // Since we don't trust NT time sync, keep track of when we got this packet
145 // into robot code
146 units::microsecond_t ntReceiveTimestamp = -1_s;
147
148 inline static bool HAS_WARNED = false;
149};
150} // namespace photon
151
Represents a pipeline result from a PhotonCamera.
Definition PhotonPipelineResult.h:37
auto & operator=(const PhotonPipelineResult &other)
Definition PhotonPipelineResult.h:52
const std::span< const PhotonTrackedTarget > GetTargets() const
Returns a reference to the vector of targets.
Definition PhotonPipelineResult.h:137
static bool HAS_WARNED
Definition PhotonPipelineResult.h:148
int64_t SequenceID() const
The number of non-empty frames processed by this camera since boot.
Definition PhotonPipelineResult.h:119
units::second_t GetTimestamp() const
Returns the estimated time the frame was taken, This is much more accurate than using GetLatency()
Definition PhotonPipelineResult.h:102
PhotonTrackedTarget GetBestTarget() const
Returns the best target in this pipeline result.
Definition PhotonPipelineResult.h:74
PhotonPipelineResult(PhotonPipelineResult &&other)
Definition PhotonPipelineResult.h:49
auto & operator=(PhotonPipelineResult &&other)
Definition PhotonPipelineResult.h:57
units::millisecond_t GetLatency() const
Returns the latency in the pipeline.
Definition PhotonPipelineResult.h:91
PhotonPipelineResult(PhotonPipelineResult &other)
Definition PhotonPipelineResult.h:47
PhotonPipelineResult(Base &&data)
Definition PhotonPipelineResult.h:42
friend bool operator==(PhotonPipelineResult const &, PhotonPipelineResult const &)=default
bool HasTargets() const
Returns whether the pipeline has targets.
Definition PhotonPipelineResult.h:130
void SetReceiveTimestamp(const units::second_t timestamp)
Sets the FPGA timestamp this result was Received by robot code.
Definition PhotonPipelineResult.h:122
units::microsecond_t ntReceiveTimestamp
Definition PhotonPipelineResult.h:146
PhotonPipelineResult(const PhotonPipelineResult &other)
Definition PhotonPipelineResult.h:45
PhotonPipelineResult()
Definition PhotonPipelineResult.h:41
const std::optional< MultiTargetPNPResult > & MultiTagResult() const
Return the latest mulit-target result, as calculated on your coprocessor.
Definition PhotonPipelineResult.h:111
PhotonPipelineResult(Args &&... args)
Definition PhotonPipelineResult.h:64
Represents a tracked target within a pipeline.
Definition PhotonTrackedTarget.h:34
Definition VisionEstimation.h:32
int64_t sequenceID
Definition PhotonPipelineMetadataStruct.h:29
int64_t captureTimestampMicros
Definition PhotonPipelineMetadataStruct.h:30
int64_t publishTimestampMicros
Definition PhotonPipelineMetadataStruct.h:31
Definition PhotonPipelineResultStruct.h:33
std::vector< photon::PhotonTrackedTarget > targets
Definition PhotonPipelineResultStruct.h:35
photon::PhotonPipelineMetadata metadata
Definition PhotonPipelineResultStruct.h:34
std::optional< photon::MultiTargetPNPResult > multitagResult
Definition PhotonPipelineResultStruct.h:36