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