PhotonVision C++ dev-v2025.0.0-beta-8-2-gbd1c5c03
Loading...
Searching...
No Matches
TargetModel.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 <vector>
21
22#include <frc/geometry/Pose3d.h>
23#include <frc/geometry/Translation3d.h>
24
25#include "RotTrlTransform3d.h"
26
27namespace photon {
29 public:
30 TargetModel(units::meter_t width, units::meter_t height)
31 : vertices({frc::Translation3d{0_m, -width / 2.0, -height / 2.0},
32 frc::Translation3d{0_m, width / 2.0, -height / 2.0},
33 frc::Translation3d{0_m, width / 2.0, height / 2.0},
34 frc::Translation3d{0_m, -width / 2.0, height / 2.0}}),
35 isPlanar(true),
36 isSpherical(false) {}
37
38 TargetModel(units::meter_t length, units::meter_t width,
39 units::meter_t height)
40 : TargetModel({
41 frc::Translation3d{length / 2.0, -width / 2.0, -height / 2.0},
42 frc::Translation3d{length / 2.0, width / 2.0, -height / 2.0},
43 frc::Translation3d{length / 2.0, width / 2.0, height / 2.0},
44 frc::Translation3d{length / 2.0, -width / 2.0, height / 2.0},
45 frc::Translation3d{-length / 2.0, -width / 2.0, height / 2.0},
46 frc::Translation3d{-length / 2.0, width / 2.0, height / 2.0},
47 frc::Translation3d{-length / 2.0, width / 2.0, -height / 2.0},
48 frc::Translation3d{-length / 2.0, -width / 2.0, -height / 2.0},
49 }) {}
50
51 explicit TargetModel(units::meter_t diameter)
52 : vertices({
53 frc::Translation3d{0_m, -diameter / 2.0, 0_m},
54 frc::Translation3d{0_m, 0_m, -diameter / 2.0},
55 frc::Translation3d{0_m, diameter / 2.0, 0_m},
56 frc::Translation3d{0_m, 0_m, diameter / 2.0},
57 }),
58 isPlanar(false),
59 isSpherical(true) {}
60
61 explicit TargetModel(const std::vector<frc::Translation3d>& verts)
62 : isSpherical(false) {
63 if (verts.size() <= 2) {
64 vertices = std::vector<frc::Translation3d>();
65 isPlanar = false;
66 } else {
67 bool cornersPlanar = true;
68 for (const auto& corner : verts) {
69 if (corner.X() != 0_m) {
70 cornersPlanar = false;
71 }
72 }
73 isPlanar = cornersPlanar;
74 }
75 vertices = verts;
76 }
77
78 std::vector<frc::Translation3d> GetFieldVertices(
79 const frc::Pose3d& targetPose) const {
80 RotTrlTransform3d basisChange{targetPose.Rotation(),
81 targetPose.Translation()};
82 std::vector<frc::Translation3d> retVal;
83 retVal.reserve(vertices.size());
84 for (const auto& vert : vertices) {
85 retVal.emplace_back(basisChange.Apply(vert));
86 }
87 return retVal;
88 }
89
90 static frc::Pose3d GetOrientedPose(const frc::Translation3d& tgtTrl,
91 const frc::Translation3d& cameraTrl) {
92 frc::Translation3d relCam = cameraTrl - tgtTrl;
93 frc::Rotation3d orientToCam = frc::Rotation3d{
94 0_rad,
95 frc::Rotation2d{units::math::hypot(relCam.X(), relCam.Y()).to<double>(),
96 -relCam.Z().to<double>()}
97 .Radians(),
98 frc::Rotation2d{relCam.X().to<double>(), relCam.Y().to<double>()}
99 .Radians()};
100 return frc::Pose3d{tgtTrl, orientToCam};
101 }
102
103 std::vector<frc::Translation3d> GetVertices() const { return vertices; }
104 bool GetIsPlanar() const { return isPlanar; }
105 bool GetIsSpherical() const { return isSpherical; }
106
107 private:
108 std::vector<frc::Translation3d> vertices;
109 bool isPlanar;
110 bool isSpherical;
111};
112
113static const TargetModel kAprilTag16h5{6_in, 6_in};
114static const TargetModel kAprilTag36h11{6.5_in, 6.5_in};
115} // namespace photon
Definition RotTrlTransform3d.h:27
Definition TargetModel.h:28
TargetModel(units::meter_t length, units::meter_t width, units::meter_t height)
Definition TargetModel.h:38
TargetModel(units::meter_t width, units::meter_t height)
Definition TargetModel.h:30
static frc::Pose3d GetOrientedPose(const frc::Translation3d &tgtTrl, const frc::Translation3d &cameraTrl)
Definition TargetModel.h:90
bool GetIsSpherical() const
Definition TargetModel.h:105
std::vector< frc::Translation3d > GetVertices() const
Definition TargetModel.h:103
std::vector< frc::Translation3d > GetFieldVertices(const frc::Pose3d &targetPose) const
Definition TargetModel.h:78
TargetModel(const std::vector< frc::Translation3d > &verts)
Definition TargetModel.h:61
TargetModel(units::meter_t diameter)
Definition TargetModel.h:51
bool GetIsPlanar() const
Definition TargetModel.h:104
Definition VisionEstimation.h:32
static const TargetModel kAprilTag36h11
Definition TargetModel.h:114
static const TargetModel kAprilTag16h5
Definition TargetModel.h:113