PhotonVision C++ v2027.0.0-alpha-2
Loading...
Searching...
No Matches
VisionTargetSim.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) PhotonVision
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#pragma once
26
27#include <vector>
28
29#include <wpi/math/geometry/Pose3d.hpp>
30
32
33namespace photon {
34/** Describes a vision target located somewhere on the field that your vision
35 * system can detect. */
37 public:
38 /**
39 * Describes a retro-reflective/colored shape vision target located somewhere
40 * on the field that your vision system can detect.
41 *
42 * @param pose Pose3d of the tag in field-relative coordinates
43 * @param model TargetModel which describes the geometry of the target
44 */
45 VisionTargetSim(const wpi::math::Pose3d& pose, const TargetModel& model)
46 : fiducialId(-1),
47 objDetClassId(-1),
48 objDetConf(-1),
49 pose(pose),
50 model(model) {}
51
52 /**
53 * Describes a fiducial tag located somewhere on the field that your vision
54 * system can detect.
55 *
56 * @param pose Pose3d of the tag in field-relative coordinates
57 * @param model TargetModel which describes the geometry of the target(tag)
58 * @param id The ID of this fiducial tag
59 */
60 VisionTargetSim(const wpi::math::Pose3d& pose, const TargetModel& model,
61 int id)
62 : fiducialId(id),
63 objDetClassId(-1),
64 objDetConf(-1),
65 pose(pose),
66 model(model) {}
67
68 /**
69 * Describes an object-detection vision target located somewhere on the field
70 * that your vision system can detect. Class ID is the (zero-indexed) index of
71 * the object's class ID in the list of all classes. Confidence can be
72 * specified, or pass -1 to estimate confidence based on 2 * sqrt(target area
73 * / total image area)
74 *
75 * @param pose Pose3d of the target in field-relative coordinates
76 * @param model TargetModel which describes the geometry of the target
77 * @param objDetClassId The object detection class ID, if -1 it will not be
78 * detected by object detection
79 * @param objDetConf The object detection confidence, or -1 in which case the
80 * simulation will compute a confidence based on the area of the target in the
81 * camera's field of view
82 */
83 VisionTargetSim(const wpi::math::Pose3d& pose, const TargetModel& model,
84 int objDetClassId, float objDetConf)
85 : fiducialId(-1),
86 objDetClassId(objDetClassId),
87 objDetConf(objDetConf),
88 pose(pose),
89 model(model) {}
90
91 /**
92 * Sets the pose of this target on the field.
93 *
94 * @param newPose The pose in field-relative coordinates
95 */
96 void SetPose(const wpi::math::Pose3d& newPose) { pose = newPose; }
97
98 /**
99 * Sets the model describing this target's geometry.
100 *
101 * @param newModel The model of the target
102 */
103 void SetModel(const TargetModel& newModel) { model = newModel; }
104
105 /**
106 * Returns the pose of this target on the field.
107 *
108 * @return The pose in field-relative coordinates
109 */
110 wpi::math::Pose3d GetPose() const { return pose; }
111
112 /**
113 * Returns the model describing this target's geometry.
114 *
115 * @return The model of the target
116 */
117 TargetModel GetModel() const { return model; }
118
119 /**
120 * Returns the fiducial ID of this target, or -1 if not a fiducial target.
121 *
122 * @return The fiducial ID
123 */
124 int GetFiducialId() const { return fiducialId; }
125
126 /**
127 * Returns the object detection class ID of this target, or -1 if not an
128 * object detection target.
129 *
130 * @return The object detection class ID
131 */
132 int GetObjDetClassId() const { return objDetClassId; }
133
134 /**
135 * Returns the object detection confidence of this target, or -1 if
136 * confidence is estimated from target area or is not an object.
137 *
138 * @return The object detection confidence
139 */
140 float GetObjDetConf() const { return objDetConf; }
141
142 /**
143 * This target's vertices offset from its field pose.
144 * @return A vector of Translation3d representing the vertices of the target
145 */
146 std::vector<wpi::math::Translation3d> GetFieldVertices() const {
147 return model.GetFieldVertices(pose);
148 }
149
150 bool operator<(const VisionTargetSim& right) const {
151 return pose.Translation().Norm() < right.pose.Translation().Norm();
152 }
153
154 bool operator==(const VisionTargetSim& other) const {
155 return wpi::units::math::abs(pose.Translation().X() -
156 other.GetPose().Translation().X()) < 1_in &&
157 wpi::units::math::abs(pose.Translation().Y() -
158 other.GetPose().Translation().Y()) < 1_in &&
159 wpi::units::math::abs(pose.Translation().Z() -
160 other.GetPose().Translation().Z()) < 1_in &&
161 wpi::units::math::abs(pose.Rotation().X() -
162 other.GetPose().Rotation().X()) < 1_deg &&
163 wpi::units::math::abs(pose.Rotation().Y() -
164 other.GetPose().Rotation().Y()) < 1_deg &&
165 wpi::units::math::abs(pose.Rotation().Z() -
166 other.GetPose().Rotation().Z()) < 1_deg &&
167 model.GetIsPlanar() == other.GetModel().GetIsPlanar();
168 }
169
170 private:
171 int fiducialId;
172 int objDetClassId;
173 float objDetConf;
174 wpi::math::Pose3d pose;
175 TargetModel model;
176};
177} // namespace photon
Definition TargetModel.h:28
std::vector< wpi::math::Translation3d > GetFieldVertices(const wpi::math::Pose3d &targetPose) const
Definition TargetModel.h:79
bool GetIsPlanar() const
Definition TargetModel.h:107
Describes a vision target located somewhere on the field that your vision system can detect.
Definition VisionTargetSim.h:36
TargetModel GetModel() const
Returns the model describing this target's geometry.
Definition VisionTargetSim.h:117
VisionTargetSim(const wpi::math::Pose3d &pose, const TargetModel &model, int id)
Describes a fiducial tag located somewhere on the field that your vision system can detect.
Definition VisionTargetSim.h:60
float GetObjDetConf() const
Returns the object detection confidence of this target, or -1 if confidence is estimated from target ...
Definition VisionTargetSim.h:140
VisionTargetSim(const wpi::math::Pose3d &pose, const TargetModel &model)
Describes a retro-reflective/colored shape vision target located somewhere on the field that your vis...
Definition VisionTargetSim.h:45
int GetObjDetClassId() const
Returns the object detection class ID of this target, or -1 if not an object detection target.
Definition VisionTargetSim.h:132
VisionTargetSim(const wpi::math::Pose3d &pose, const TargetModel &model, int objDetClassId, float objDetConf)
Describes an object-detection vision target located somewhere on the field that your vision system ca...
Definition VisionTargetSim.h:83
void SetPose(const wpi::math::Pose3d &newPose)
Sets the pose of this target on the field.
Definition VisionTargetSim.h:96
wpi::math::Pose3d GetPose() const
Returns the pose of this target on the field.
Definition VisionTargetSim.h:110
int GetFiducialId() const
Returns the fiducial ID of this target, or -1 if not a fiducial target.
Definition VisionTargetSim.h:124
std::vector< wpi::math::Translation3d > GetFieldVertices() const
This target's vertices offset from its field pose.
Definition VisionTargetSim.h:146
bool operator==(const VisionTargetSim &other) const
Definition VisionTargetSim.h:154
void SetModel(const TargetModel &newModel)
Sets the model describing this target's geometry.
Definition VisionTargetSim.h:103
bool operator<(const VisionTargetSim &right) const
Definition VisionTargetSim.h:150
Definition VisionEstimation.h:30