PhotonVision C++ dev-v2025.3.1-2-gf92cf62a
Loading...
Searching...
No Matches
PhotonCameraSim.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 <cameraserver/CameraServer.h>
28#include <photon/PhotonCamera.h>
36
37#include <algorithm>
38#include <limits>
39#include <string>
40#include <utility>
41#include <vector>
42
43#include <frc/Timer.h>
44#include <frc/apriltag/AprilTagFieldLayout.h>
45#include <frc/apriltag/AprilTagFields.h>
46#include <units/math.h>
47#include <wpi/timestamp.h>
48
49namespace photon {
51 public:
52 explicit PhotonCameraSim(PhotonCamera* camera);
54 const frc::AprilTagFieldLayout& tagLayout =
55 frc::AprilTagFieldLayout::LoadField(
56 frc::AprilTagField::kDefaultField));
58 double minTargetAreaPercent, units::meter_t maxSightRange);
59
60 inline PhotonCamera* GetCamera() { return cam; }
61 inline double GetMinTargetAreaPercent() { return minTargetAreaPercent; }
62 inline double GetMinTargetAreaPixels() {
63 return minTargetAreaPercent / 100.0 * prop.GetResArea();
64 }
65 inline units::meter_t GetMaxSightRange() { return maxSightRange; }
66 inline const cs::CvSource& GetVideoSimRaw() { return videoSimRaw; }
67 inline const cv::Mat& GetVideoSimFrameRaw() { return videoSimFrameRaw; }
68
69 bool CanSeeTargetPose(const frc::Pose3d& camPose,
70 const VisionTargetSim& target);
71 bool CanSeeCorner(const std::vector<cv::Point2f>& points);
72 std::optional<uint64_t> ConsumeNextEntryTime();
73
74 inline void SetMinTargetAreaPercent(double areaPercent) {
75 minTargetAreaPercent = areaPercent;
76 }
77 inline void SetMinTargetAreaPixels(double areaPx) {
78 minTargetAreaPercent = areaPx / prop.GetResArea() * 100;
79 }
80 inline void SetMaxSightRange(units::meter_t range) { maxSightRange = range; }
81 inline void EnableRawStream(bool enabled) { videoSimRawEnabled = enabled; }
82 inline void EnableDrawWireframe(bool enabled) {
83 videoSimWireframeEnabled = enabled;
84 }
85 inline void SetWireframeResolution(double resolution) {
86 videoSimWireframeResolution = resolution;
87 }
88 inline void EnabledProcessedStream(double enabled) {
89 videoSimProcEnabled = enabled;
90 }
91 PhotonPipelineResult Process(units::second_t latency,
92 const frc::Pose3d& cameraPose,
93 std::vector<VisionTargetSim> targets);
94
97 uint64_t ReceiveTimestamp);
98
100
101 private:
102 PhotonCamera* cam;
103
104 NTTopicSet ts{};
105 int64_t heartbeatCounter{0};
106
107 uint64_t nextNTEntryTime{wpi::Now()};
108
109 units::meter_t maxSightRange{std::numeric_limits<double>::max()};
110 static constexpr double kDefaultMinAreaPx{100};
111 double minTargetAreaPercent;
112
113 frc::AprilTagFieldLayout tagLayout;
114
115 cs::CvSource videoSimRaw;
116 cv::Mat videoSimFrameRaw{};
117 bool videoSimRawEnabled{true};
118 bool videoSimWireframeEnabled{false};
119 double videoSimWireframeResolution{0.1};
120 cs::CvSource videoSimProcessed;
121 cv::Mat videoSimFrameProcessed{};
122 bool videoSimProcEnabled{true};
123};
124} // namespace photon
Definition NTTopicSet.h:37
Represents a camera that is connected to PhotonVision.
Definition PhotonCamera.h:56
Definition PhotonCameraSim.h:50
std::optional< uint64_t > ConsumeNextEntryTime()
SimCameraProperties prop
Definition PhotonCameraSim.h:99
void SetWireframeResolution(double resolution)
Definition PhotonCameraSim.h:85
const cs::CvSource & GetVideoSimRaw()
Definition PhotonCameraSim.h:66
const cv::Mat & GetVideoSimFrameRaw()
Definition PhotonCameraSim.h:67
PhotonCamera * GetCamera()
Definition PhotonCameraSim.h:60
PhotonCameraSim(PhotonCamera *camera, const SimCameraProperties &props, const frc::AprilTagFieldLayout &tagLayout=frc::AprilTagFieldLayout::LoadField(frc::AprilTagField::kDefaultField))
void EnableDrawWireframe(bool enabled)
Definition PhotonCameraSim.h:82
double GetMinTargetAreaPixels()
Definition PhotonCameraSim.h:62
PhotonCameraSim(PhotonCamera *camera, const SimCameraProperties &props, double minTargetAreaPercent, units::meter_t maxSightRange)
void EnabledProcessedStream(double enabled)
Definition PhotonCameraSim.h:88
units::meter_t GetMaxSightRange()
Definition PhotonCameraSim.h:65
PhotonPipelineResult Process(units::second_t latency, const frc::Pose3d &cameraPose, std::vector< VisionTargetSim > targets)
void SubmitProcessedFrame(const PhotonPipelineResult &result)
bool CanSeeCorner(const std::vector< cv::Point2f > &points)
void SetMinTargetAreaPixels(double areaPx)
Definition PhotonCameraSim.h:77
void SubmitProcessedFrame(const PhotonPipelineResult &result, uint64_t ReceiveTimestamp)
void EnableRawStream(bool enabled)
Definition PhotonCameraSim.h:81
double GetMinTargetAreaPercent()
Definition PhotonCameraSim.h:61
void SetMaxSightRange(units::meter_t range)
Definition PhotonCameraSim.h:80
bool CanSeeTargetPose(const frc::Pose3d &camPose, const VisionTargetSim &target)
PhotonCameraSim(PhotonCamera *camera)
void SetMinTargetAreaPercent(double areaPercent)
Definition PhotonCameraSim.h:74
Represents a pipeline result from a PhotonCamera.
Definition PhotonPipelineResult.h:37
Definition SimCameraProperties.h:44
int GetResArea() const
Definition SimCameraProperties.h:80
Definition VisionTargetSim.h:34
Definition VisionEstimation.h:32