PhotonVision C++ v2027.0.0-alpha-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 <utility>
22
23#include <wpi/units/time.hpp>
24
26#include "PhotonTrackedTarget.h"
27#include "fmt/base.h"
29
30namespace photon {
31/**
32 * Represents a pipeline result from a PhotonCamera.
33 */
36
37 public:
39 explicit PhotonPipelineResult(Base&& data) : Base(data) {}
40
41 // Don't forget to deal with our ntReceiveTimestamp
47 : Base(std::move(other)),
48 ntReceiveTimestamp(std::move(other.ntReceiveTimestamp)) {}
49 auto& operator=(const PhotonPipelineResult& other) {
50 Base::operator=(other);
52 return *this;
53 }
55 ntReceiveTimestamp = other.ntReceiveTimestamp;
56 Base::operator=(std::move(other));
57 return *this;
58 }
59
60 template <typename... Args>
61 explicit PhotonPipelineResult(Args&&... args)
62 : Base{std::forward<Args>(args)...} {}
63
64 /**
65 * Returns the best target in this pipeline result. If there are no targets,
66 * this method will return null. The best target is determined by the target
67 * sort mode in the PhotonVision UI.
68 *
69 * @return The best target of the pipeline result.
70 */
72 if (!HasTargets() && !HAS_WARNED) {
73 fmt::println(
74 "WARNING: This PhotonPipelineResult object has no targets associated "
75 "with it! "
76 "Please check HasTargets() before calling this method. For more "
77 "information, please review the PhotonLib documentation at "
78 "http://docs.photonvision.org");
79 HAS_WARNED = true;
80 }
81 return HasTargets() ? targets[0] : PhotonTrackedTarget{};
82 }
83
84 /**
85 * Returns the latency in the pipeline.
86 * @return The latency in the pipeline.
87 */
88 wpi::units::millisecond_t GetLatency() const {
89 return wpi::units::microsecond_t{static_cast<double>(
91 }
92
93 /**
94 * Returns the estimated time the frame was taken, in the Time Sync Server's
95 * time base (nt::Now). This is calculated using the estimated offset between
96 * Time Sync Server time and local time. The robot shall run a server, so the
97 * offset shall be 0.
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 wpi::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 `MultiTagResult().has_value()` before using
109 * the pose estimate!
110 *
111 * @return The multi-target result. Empty if there's no multi-target
112 * result/Multi-Target Estimation is disabled in the UI.
113 */
114 const std::optional<MultiTargetPNPResult>& MultiTagResult() const {
115 return multitagResult;
116 }
117
118 /**
119 * The number of non-empty frames processed by this camera since boot. Useful
120 * to checking if a camera is alive.
121 */
122 int64_t SequenceID() const { return metadata.sequenceID; }
123
124 /** Sets the FPGA timestamp this result was Received by robot code */
125 void SetReceiveTimestamp(const wpi::units::second_t timestamp) {
126 this->ntReceiveTimestamp = timestamp;
127 }
128
129 /**
130 * Returns whether the pipeline has targets.
131 * @return Whether the pipeline has targets.
132 */
133 bool HasTargets() const { return targets.size() > 0; }
134
135 /**
136 * Returns a reference to the vector of targets.
137 * <p> Returned in the order set by target sort mode. </p>
138 * @return A reference to the vector of targets.
139 */
140 const std::span<const PhotonTrackedTarget> GetTargets() const {
141 return targets;
142 }
143
145 PhotonPipelineResult const&) = default;
146
147 // Since we don't trust NT time sync, keep track of when we got this packet
148 // into robot code
149 wpi::units::microsecond_t ntReceiveTimestamp = -1_s;
150
151 inline static bool HAS_WARNED = false;
152};
153} // namespace photon
154
Represents a pipeline result from a PhotonCamera.
Definition PhotonPipelineResult.h:34
void SetReceiveTimestamp(const wpi::units::second_t timestamp)
Sets the FPGA timestamp this result was Received by robot code.
Definition PhotonPipelineResult.h:125
auto & operator=(const PhotonPipelineResult &other)
Definition PhotonPipelineResult.h:49
const std::span< const PhotonTrackedTarget > GetTargets() const
Returns a reference to the vector of targets.
Definition PhotonPipelineResult.h:140
wpi::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:102
static bool HAS_WARNED
Definition PhotonPipelineResult.h:151
int64_t SequenceID() const
The number of non-empty frames processed by this camera since boot.
Definition PhotonPipelineResult.h:122
wpi::units::millisecond_t GetLatency() const
Returns the latency in the pipeline.
Definition PhotonPipelineResult.h:88
PhotonTrackedTarget GetBestTarget() const
Returns the best target in this pipeline result.
Definition PhotonPipelineResult.h:71
PhotonPipelineResult(PhotonPipelineResult &&other)
Definition PhotonPipelineResult.h:46
auto & operator=(PhotonPipelineResult &&other)
Definition PhotonPipelineResult.h:54
PhotonPipelineResult(PhotonPipelineResult &other)
Definition PhotonPipelineResult.h:44
PhotonPipelineResult(Base &&data)
Definition PhotonPipelineResult.h:39
friend bool operator==(PhotonPipelineResult const &, PhotonPipelineResult const &)=default
bool HasTargets() const
Returns whether the pipeline has targets.
Definition PhotonPipelineResult.h:133
wpi::units::microsecond_t ntReceiveTimestamp
Definition PhotonPipelineResult.h:149
PhotonPipelineResult(const PhotonPipelineResult &other)
Definition PhotonPipelineResult.h:42
PhotonPipelineResult()
Definition PhotonPipelineResult.h:38
const std::optional< MultiTargetPNPResult > & MultiTagResult() const
Return the latest mulit-target result, as calculated on your coprocessor.
Definition PhotonPipelineResult.h:114
PhotonPipelineResult(Args &&... args)
Definition PhotonPipelineResult.h:61
Represents a tracked target within a pipeline.
Definition PhotonTrackedTarget.h:31
Definition VisionEstimation.h:30
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