mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
Added constructor overload to PhotonCameraSim for AprilTagFieldLayout (#1692)
This commit is contained in:
@@ -36,6 +36,9 @@ class PhotonCameraSim:
|
||||
self,
|
||||
camera: PhotonCamera,
|
||||
props: SimCameraProperties = SimCameraProperties.PERFECT_90DEG(),
|
||||
tagLayout: AprilTagFieldLayout = AprilTagFieldLayout.loadField(
|
||||
AprilTagField.kDefaultField
|
||||
),
|
||||
minTargetAreaPercent: float | None = None,
|
||||
maxSightRange: meters | None = None,
|
||||
):
|
||||
@@ -64,7 +67,7 @@ class PhotonCameraSim:
|
||||
self.videoSimProcEnabled: bool = False
|
||||
self.heartbeatCounter: int = 0
|
||||
self.nextNtEntryTime = wpilib.Timer.getFPGATimestamp()
|
||||
self.tagLayout = AprilTagFieldLayout.loadField(AprilTagField.kDefaultField)
|
||||
self.tagLayout = tagLayout
|
||||
|
||||
self.cam = camera
|
||||
self.prop = props
|
||||
|
||||
@@ -81,8 +81,7 @@ public class PhotonCameraSim implements AutoCloseable {
|
||||
private double minTargetAreaPercent;
|
||||
private PhotonTargetSortMode sortMode = PhotonTargetSortMode.Largest;
|
||||
|
||||
private final AprilTagFieldLayout tagLayout =
|
||||
AprilTagFieldLayout.loadField(AprilTagFields.kDefaultField);
|
||||
private final AprilTagFieldLayout tagLayout;
|
||||
|
||||
// video stream simulation
|
||||
private final CvSource videoSimRaw;
|
||||
@@ -130,8 +129,24 @@ public class PhotonCameraSim implements AutoCloseable {
|
||||
* @param prop Properties of this camera such as FOV and FPS
|
||||
*/
|
||||
public PhotonCameraSim(PhotonCamera camera, SimCameraProperties prop) {
|
||||
this(camera, prop, AprilTagFieldLayout.loadField(AprilTagFields.kDefaultField));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a handle for simulating {@link PhotonCamera} values. Processing simulated targets
|
||||
* through this class will change the associated PhotonCamera's results.
|
||||
*
|
||||
* <p>By default, the minimum target area is 100 pixels and there is no maximum sight range.
|
||||
*
|
||||
* @param camera The camera to be simulated
|
||||
* @param prop Properties of this camera such as FOV and FPS
|
||||
* @param tagLayout The {@link AprilTagFieldLayout} used to solve for tag positions.
|
||||
*/
|
||||
public PhotonCameraSim(
|
||||
PhotonCamera camera, SimCameraProperties prop, AprilTagFieldLayout tagLayout) {
|
||||
this.cam = camera;
|
||||
this.prop = prop;
|
||||
this.tagLayout = tagLayout;
|
||||
setMinTargetAreaPixels(kDefaultMinAreaPx);
|
||||
|
||||
videoSimRaw =
|
||||
@@ -163,6 +178,30 @@ public class PhotonCameraSim implements AutoCloseable {
|
||||
SimCameraProperties prop,
|
||||
double minTargetAreaPercent,
|
||||
double maxSightRangeMeters) {
|
||||
this(camera, prop, AprilTagFieldLayout.loadField(AprilTagFields.kDefaultField));
|
||||
this.minTargetAreaPercent = minTargetAreaPercent;
|
||||
this.maxSightRangeMeters = maxSightRangeMeters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a handle for simulating {@link PhotonCamera} values. Processing simulated targets
|
||||
* through this class will change the associated PhotonCamera's results.
|
||||
*
|
||||
* @param camera The camera to be simulated
|
||||
* @param prop Properties of this camera such as FOV and FPS
|
||||
* @param minTargetAreaPercent The minimum percentage(0 - 100) a detected target must take up of
|
||||
* the camera's image to be processed. Match this with your contour filtering settings in the
|
||||
* PhotonVision GUI.
|
||||
* @param maxSightRangeMeters Maximum distance at which the target is illuminated to your camera.
|
||||
* Note that minimum target area of the image is separate from this.
|
||||
* @param tagLayout AprilTag field layout to use for multi-tag estimation
|
||||
*/
|
||||
public PhotonCameraSim(
|
||||
PhotonCamera camera,
|
||||
SimCameraProperties prop,
|
||||
double minTargetAreaPercent,
|
||||
double maxSightRangeMeters,
|
||||
AprilTagFieldLayout tagLayout) {
|
||||
this(camera, prop);
|
||||
this.minTargetAreaPercent = minTargetAreaPercent;
|
||||
this.maxSightRangeMeters = maxSightRangeMeters;
|
||||
|
||||
@@ -29,12 +29,19 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <frc/apriltag/AprilTagFieldLayout.h>
|
||||
#include <frc/apriltag/AprilTagFields.h>
|
||||
|
||||
namespace photon {
|
||||
PhotonCameraSim::PhotonCameraSim(PhotonCamera* camera)
|
||||
: PhotonCameraSim(camera, photon::SimCameraProperties::PERFECT_90DEG()) {}
|
||||
: PhotonCameraSim(camera, photon::SimCameraProperties::PERFECT_90DEG(),
|
||||
frc::AprilTagFieldLayout::LoadField(
|
||||
frc::AprilTagField::kDefaultField)) {}
|
||||
|
||||
PhotonCameraSim::PhotonCameraSim(PhotonCamera* camera,
|
||||
const SimCameraProperties& props)
|
||||
: prop(props), cam(camera) {
|
||||
const SimCameraProperties& props,
|
||||
const frc::AprilTagFieldLayout& tagLayout)
|
||||
: prop{props}, cam{camera}, tagLayout{tagLayout} {
|
||||
SetMinTargetAreaPixels(kDefaultMinAreaPx);
|
||||
videoSimRaw =
|
||||
frc::CameraServer::PutVideo(std::string{camera->GetCameraName()} + "-raw",
|
||||
@@ -46,6 +53,7 @@ PhotonCameraSim::PhotonCameraSim(PhotonCamera* camera,
|
||||
ts.subTable = cam->GetCameraTable();
|
||||
ts.UpdateEntries();
|
||||
}
|
||||
|
||||
PhotonCameraSim::PhotonCameraSim(PhotonCamera* camera,
|
||||
const SimCameraProperties& props,
|
||||
double minTargetAreaPercent,
|
||||
|
||||
@@ -50,7 +50,10 @@ namespace photon {
|
||||
class PhotonCameraSim {
|
||||
public:
|
||||
explicit PhotonCameraSim(PhotonCamera* camera);
|
||||
PhotonCameraSim(PhotonCamera* camera, const SimCameraProperties& props);
|
||||
PhotonCameraSim(PhotonCamera* camera, const SimCameraProperties& props,
|
||||
const frc::AprilTagFieldLayout& tagLayout =
|
||||
frc::AprilTagFieldLayout::LoadField(
|
||||
frc::AprilTagField::kDefaultField));
|
||||
PhotonCameraSim(PhotonCamera* camera, const SimCameraProperties& props,
|
||||
double minTargetAreaPercent, units::meter_t maxSightRange);
|
||||
|
||||
@@ -107,8 +110,7 @@ class PhotonCameraSim {
|
||||
static constexpr double kDefaultMinAreaPx{100};
|
||||
double minTargetAreaPercent;
|
||||
|
||||
frc::AprilTagFieldLayout tagLayout{
|
||||
frc::AprilTagFieldLayout::LoadField(frc::AprilTagField::kDefaultField)};
|
||||
frc::AprilTagFieldLayout tagLayout;
|
||||
|
||||
cs::CvSource videoSimRaw;
|
||||
cv::Mat videoSimFrameRaw{};
|
||||
|
||||
Reference in New Issue
Block a user