PhotonVision C++ dev-v2025.0.0-beta-8-2-gbd1c5c03
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);
55 double minTargetAreaPercent, units::meter_t maxSightRange);
56
57 inline PhotonCamera* GetCamera() { return cam; }
58 inline double GetMinTargetAreaPercent() { return minTargetAreaPercent; }
59 inline double GetMinTargetAreaPixels() {
60 return minTargetAreaPercent / 100.0 * prop.GetResArea();
61 }
62 inline units::meter_t GetMaxSightRange() { return maxSightRange; }
63 inline const cs::CvSource& GetVideoSimRaw() { return videoSimRaw; }
64 inline const cv::Mat& GetVideoSimFrameRaw() { return videoSimFrameRaw; }
65
66 bool CanSeeTargetPose(const frc::Pose3d& camPose,
67 const VisionTargetSim& target);
68 bool CanSeeCorner(const std::vector<cv::Point2f>& points);
69 std::optional<uint64_t> ConsumeNextEntryTime();
70
71 inline void SetMinTargetAreaPercent(double areaPercent) {
72 minTargetAreaPercent = areaPercent;
73 }
74 inline void SetMinTargetAreaPixels(double areaPx) {
75 minTargetAreaPercent = areaPx / prop.GetResArea() * 100;
76 }
77 inline void SetMaxSightRange(units::meter_t range) { maxSightRange = range; }
78 inline void EnableRawStream(bool enabled) { videoSimRawEnabled = enabled; }
79 inline void EnableDrawWireframe(bool enabled) {
80 videoSimWireframeEnabled = enabled;
81 }
82 inline void SetWireframeResolution(double resolution) {
83 videoSimWireframeResolution = resolution;
84 }
85 inline void EnabledProcessedStream(double enabled) {
86 videoSimProcEnabled = enabled;
87 }
88 PhotonPipelineResult Process(units::second_t latency,
89 const frc::Pose3d& cameraPose,
90 std::vector<VisionTargetSim> targets);
91
94 uint64_t ReceiveTimestamp);
95
97
98 private:
99 PhotonCamera* cam;
100
101 NTTopicSet ts{};
102 int64_t heartbeatCounter{0};
103
104 uint64_t nextNTEntryTime{wpi::Now()};
105
106 units::meter_t maxSightRange{std::numeric_limits<double>::max()};
107 static constexpr double kDefaultMinAreaPx{100};
108 double minTargetAreaPercent;
109
110 frc::AprilTagFieldLayout tagLayout{
111 frc::AprilTagFieldLayout::LoadField(frc::AprilTagField::k2024Crescendo)};
112
113 cs::CvSource videoSimRaw;
114 cv::Mat videoSimFrameRaw{};
115 bool videoSimRawEnabled{true};
116 bool videoSimWireframeEnabled{false};
117 double videoSimWireframeResolution{0.1};
118 cs::CvSource videoSimProcessed;
119 cv::Mat videoSimFrameProcessed{};
120 bool videoSimProcEnabled{true};
121};
122} // namespace photon
Definition NTTopicSet.h:37
Represents a camera that is connected to PhotonVision.
Definition PhotonCamera.h:55
Definition PhotonCameraSim.h:50
std::optional< uint64_t > ConsumeNextEntryTime()
SimCameraProperties prop
Definition PhotonCameraSim.h:96
void SetWireframeResolution(double resolution)
Definition PhotonCameraSim.h:82
const cs::CvSource & GetVideoSimRaw()
Definition PhotonCameraSim.h:63
const cv::Mat & GetVideoSimFrameRaw()
Definition PhotonCameraSim.h:64
PhotonCamera * GetCamera()
Definition PhotonCameraSim.h:57
void EnableDrawWireframe(bool enabled)
Definition PhotonCameraSim.h:79
double GetMinTargetAreaPixels()
Definition PhotonCameraSim.h:59
PhotonCameraSim(PhotonCamera *camera, const SimCameraProperties &props, double minTargetAreaPercent, units::meter_t maxSightRange)
void EnabledProcessedStream(double enabled)
Definition PhotonCameraSim.h:85
units::meter_t GetMaxSightRange()
Definition PhotonCameraSim.h:62
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:74
void SubmitProcessedFrame(const PhotonPipelineResult &result, uint64_t ReceiveTimestamp)
void EnableRawStream(bool enabled)
Definition PhotonCameraSim.h:78
double GetMinTargetAreaPercent()
Definition PhotonCameraSim.h:58
void SetMaxSightRange(units::meter_t range)
Definition PhotonCameraSim.h:77
bool CanSeeTargetPose(const frc::Pose3d &camPose, const VisionTargetSim &target)
PhotonCameraSim(PhotonCamera *camera)
void SetMinTargetAreaPercent(double areaPercent)
Definition PhotonCameraSim.h:71
PhotonCameraSim(PhotonCamera *camera, const SimCameraProperties &props)
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