PhotonVision C++ v2026.2.2
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, in the Time Sync Server's
98 * time base (nt::Now). This is calculated using the estimated offset between
99 * Time Sync Server time and local time. The robot shall run a server, so the
100 * offset shall be 0.
101 * This is much more accurate than using GetLatency()
102 * @return The timestamp in seconds or -1 if this result was not initiated
103 * with a timestamp.
104 */
105 units::second_t GetTimestamp() const {
107 }
108
109 /**
110 * Return the latest mulit-target result, as calculated on your coprocessor.
111 * Be sure to check `MultiTagResult().has_value()` before using
112 * the pose estimate!
113 *
114 * @return The multi-target result. Empty if there's no multi-target
115 * result/Multi-Target Estimation is disabled in the UI.
116 */
117 const std::optional<MultiTargetPNPResult>& MultiTagResult() const {
118 return multitagResult;
119 }
120
121 /**
122 * The number of non-empty frames processed by this camera since boot. Useful
123 * to checking if a camera is alive.
124 */
125 int64_t SequenceID() const { return metadata.sequenceID; }
126
127 /** Sets the FPGA timestamp this result was Received by robot code */
128 void SetReceiveTimestamp(const units::second_t timestamp) {
129 this->ntReceiveTimestamp = timestamp;
130 }
131
132 /**
133 * Returns whether the pipeline has targets.
134 * @return Whether the pipeline has targets.
135 */
136 bool HasTargets() const { return targets.size() > 0; }
137
138 /**
139 * Returns a reference to the vector of targets.
140 * <p> Returned in the order set by target sort mode. </p>
141 * @return A reference to the vector of targets.
142 */
143 const std::span<const PhotonTrackedTarget> GetTargets() const {
144 return targets;
145 }
146
148 PhotonPipelineResult const&) = default;
149
150 // Since we don't trust NT time sync, keep track of when we got this packet
151 // into robot code
152 units::microsecond_t ntReceiveTimestamp = -1_s;
153
154 inline static bool HAS_WARNED = false;
155};
156} // namespace photon
157
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:143
static bool HAS_WARNED
Definition PhotonPipelineResult.h:154
int64_t SequenceID() const
The number of non-empty frames processed by this camera since boot.
Definition PhotonPipelineResult.h:125
units::second_t GetTimestamp() const
Returns the estimated time the frame was taken, in the Time Sync Server's time base (nt::Now).
Definition PhotonPipelineResult.h:105
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:136
void SetReceiveTimestamp(const units::second_t timestamp)
Sets the FPGA timestamp this result was Received by robot code.
Definition PhotonPipelineResult.h:128
units::microsecond_t ntReceiveTimestamp
Definition PhotonPipelineResult.h:152
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:117
PhotonPipelineResult(Args &&... args)
Definition PhotonPipelineResult.h:64
Represents a tracked target within a pipeline.
Definition PhotonTrackedTarget.h:34
Definition TargetModel.h:27
int64_t sequenceID
Definition PhotonPipelineMetadataStruct.h:36
int64_t captureTimestampMicros
Definition PhotonPipelineMetadataStruct.h:37
int64_t publishTimestampMicros
Definition PhotonPipelineMetadataStruct.h:38
Definition PhotonPipelineResultStruct.h:40
std::vector< photon::PhotonTrackedTarget > targets
Definition PhotonPipelineResultStruct.h:42
photon::PhotonPipelineMetadata metadata
Definition PhotonPipelineResultStruct.h:41
std::optional< photon::MultiTargetPNPResult > multitagResult
Definition PhotonPipelineResultStruct.h:43