PhotonVision C++ v2026.2.2
Loading...
Searching...
No Matches
photon::PhotonCameraSim Class Reference

#include <photon/simulation/PhotonCameraSim.h>

Public Member Functions

 PhotonCameraSim (PhotonCamera *camera)
 Constructs a handle for simulating PhotonCamera values.
 
 PhotonCameraSim (PhotonCamera *camera, const SimCameraProperties &props, const frc::AprilTagFieldLayout &tagLayout=frc::AprilTagFieldLayout::LoadField(frc::AprilTagField::kDefaultField))
 Constructs a handle for simulating PhotonCamera values.
 
 PhotonCameraSim (PhotonCamera *camera, const SimCameraProperties &props, double minTargetAreaPercent, units::meter_t maxSightRange)
 Constructs a handle for simulating PhotonCamera values.
 
PhotonCameraGetCamera ()
 Returns the camera being simulated.
 
double GetMinTargetAreaPercent ()
 Returns the minimum percentage (0 - 100) a detected target must take up of the camera's image to be processed.
 
double GetMinTargetAreaPixels ()
 Returns the minimum number of pixels a detected target must take up in the camera's image to be processed.
 
units::meter_t GetMaxSightRange ()
 Returns the maximum distance at which the target is illuminated to your camera.
 
const cs::CvSource & GetVideoSimRaw ()
 
const cv::Mat & GetVideoSimFrameRaw ()
 
bool CanSeeTargetPose (const frc::Pose3d &camPose, const VisionTargetSim &target)
 Determines if this target's pose should be visible to the camera without considering its projected image points.
 
bool CanSeeCorner (const std::vector< cv::Point2f > &points)
 Determines if all target points are inside the camera's image.
 
std::optional< uint64_t > ConsumeNextEntryTime ()
 Determine if this camera should process a new frame based on performance metrics and the time since the last update.
 
void SetMinTargetAreaPercent (double areaPercent)
 Sets the minimum percentage (0 - 100) a detected target must take up of the camera's image to be processed.
 
void SetMinTargetAreaPixels (double areaPx)
 Sets the minimum number of pixels a detected target must take up in the camera's image to be processed.
 
void SetMaxSightRange (units::meter_t range)
 Sets the maximum distance at which the target is illuminated to your camera.
 
void EnableRawStream (bool enabled)
 Sets whether the raw video stream simulation is enabled.
 
void EnableDrawWireframe (bool enabled)
 Sets whether a wireframe of the field is drawn to the raw video stream.
 
void SetWireframeResolution (double resolution)
 Sets the resolution of the drawn wireframe if enabled.
 
void EnabledProcessedStream (double enabled)
 Sets whether the processed video stream simulation is enabled.
 
PhotonPipelineResult Process (units::second_t latency, const frc::Pose3d &cameraPose, std::vector< VisionTargetSim > targets)
 
void SubmitProcessedFrame (const PhotonPipelineResult &result)
 
void SubmitProcessedFrame (const PhotonPipelineResult &result, uint64_t ReceiveTimestamp)
 

Public Attributes

SimCameraProperties prop
 

Constructor & Destructor Documentation

◆ PhotonCameraSim() [1/3]

photon::PhotonCameraSim::PhotonCameraSim ( PhotonCamera * camera)
explicit

Constructs a handle for simulating PhotonCamera values.

Processing simulated targets through this class will change the associated PhotonCamera's results.

WARNING: This constructor's camera has a 90 deg FOV with no simulated lag!

By default, the minimum target area is 100 pixels and there is no maximum sight range.

Parameters
cameraThe camera to be simulated

◆ PhotonCameraSim() [2/3]

photon::PhotonCameraSim::PhotonCameraSim ( PhotonCamera * camera,
const SimCameraProperties & props,
const frc::AprilTagFieldLayout & tagLayout = frc::AprilTagFieldLayout::LoadField(frc::AprilTagField::kDefaultField) )

Constructs a handle for simulating PhotonCamera values.

Processing simulated targets through this class will change the associated PhotonCamera's results.

By default, the minimum target area is 100 pixels and there is no maximum sight range.

Parameters
cameraThe camera to be simulated
propProperties of this camera such as FOV and FPS
tagLayoutThe AprilTagFieldLayout used to solve for tag positions.

◆ PhotonCameraSim() [3/3]

photon::PhotonCameraSim::PhotonCameraSim ( PhotonCamera * camera,
const SimCameraProperties & props,
double minTargetAreaPercent,
units::meter_t maxSightRange )

Constructs a handle for simulating PhotonCamera values.

Processing simulated targets through this class will change the associated PhotonCamera's results.

Parameters
cameraThe camera to be simulated
propProperties of this camera such as FOV and FPS
minTargetAreaPercentThe 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.
maxSightRangeMaximum distance at which the target is illuminated to your camera. Note that minimum target area of the image is separate from this.

Member Function Documentation

◆ CanSeeCorner()

bool photon::PhotonCameraSim::CanSeeCorner ( const std::vector< cv::Point2f > & points)

Determines if all target points are inside the camera's image.

Parameters
pointsThe target's 2d image points
Returns
True if all the target points are inside the camera's image, false otherwise.

◆ CanSeeTargetPose()

bool photon::PhotonCameraSim::CanSeeTargetPose ( const frc::Pose3d & camPose,
const VisionTargetSim & target )

Determines if this target's pose should be visible to the camera without considering its projected image points.

Does not account for image area.

Parameters
camPoseCamera's 3d pose
targetVision target containing pose and shape
Returns
If this vision target can be seen before image projection.

◆ ConsumeNextEntryTime()

std::optional< uint64_t > photon::PhotonCameraSim::ConsumeNextEntryTime ( )

Determine if this camera should process a new frame based on performance metrics and the time since the last update.

This returns an Optional which is either empty if no update should occur or a Long of the timestamp in microseconds of when the frame which should be received by NT. If a timestamp is returned, the last frame update time becomes that timestamp.

Returns
Optional long which is empty while blocked or the NT entry timestamp in microseconds if ready

◆ EnabledProcessedStream()

void photon::PhotonCameraSim::EnabledProcessedStream ( double enabled)
inline

Sets whether the processed video stream simulation is enabled.

Parameters
enabledWhether or not to enable the processed video stream

◆ EnableDrawWireframe()

void photon::PhotonCameraSim::EnableDrawWireframe ( bool enabled)
inline

Sets whether a wireframe of the field is drawn to the raw video stream.

Note: This will dramatically increase loop times.

Parameters
enabledWhether or not to enable the wireframe in the raw video stream

◆ EnableRawStream()

void photon::PhotonCameraSim::EnableRawStream ( bool enabled)
inline

Sets whether the raw video stream simulation is enabled.

Note: This may increase loop times.

Parameters
enabledWhether or not to enable the raw video stream

◆ GetCamera()

PhotonCamera * photon::PhotonCameraSim::GetCamera ( )
inline

Returns the camera being simulated.

Returns
The camera

◆ GetMaxSightRange()

units::meter_t photon::PhotonCameraSim::GetMaxSightRange ( )
inline

Returns the maximum distance at which the target is illuminated to your camera.

Note that minimum target area of the image is separate from this.

Returns
The distance

◆ GetMinTargetAreaPercent()

double photon::PhotonCameraSim::GetMinTargetAreaPercent ( )
inline

Returns the minimum percentage (0 - 100) a detected target must take up of the camera's image to be processed.

Returns
The percentage

◆ GetMinTargetAreaPixels()

double photon::PhotonCameraSim::GetMinTargetAreaPixels ( )
inline

Returns the minimum number of pixels a detected target must take up in the camera's image to be processed.

Returns
The number of pixels

◆ GetVideoSimFrameRaw()

const cv::Mat & photon::PhotonCameraSim::GetVideoSimFrameRaw ( )
inline

◆ GetVideoSimRaw()

const cs::CvSource & photon::PhotonCameraSim::GetVideoSimRaw ( )
inline

◆ Process()

PhotonPipelineResult photon::PhotonCameraSim::Process ( units::second_t latency,
const frc::Pose3d & cameraPose,
std::vector< VisionTargetSim > targets )

◆ SetMaxSightRange()

void photon::PhotonCameraSim::SetMaxSightRange ( units::meter_t range)
inline

Sets the maximum distance at which the target is illuminated to your camera.

Note that minimum target area of the image is separate from this.

Parameters
rangeMetersThe distance

◆ SetMinTargetAreaPercent()

void photon::PhotonCameraSim::SetMinTargetAreaPercent ( double areaPercent)
inline

Sets the minimum percentage (0 - 100) a detected target must take up of the camera's image to be processed.

Parameters
areaPercentThe percentage

◆ SetMinTargetAreaPixels()

void photon::PhotonCameraSim::SetMinTargetAreaPixels ( double areaPx)
inline

Sets the minimum number of pixels a detected target must take up in the camera's image to be processed.

Parameters
areaPxThe number of pixels

◆ SetWireframeResolution()

void photon::PhotonCameraSim::SetWireframeResolution ( double resolution)
inline

Sets the resolution of the drawn wireframe if enabled.

Drawn line segments will be subdivided into smaller segments based on a threshold set by the resolution.

Parameters
resolutionResolution as a fraction(0 - 1) of the video frame's diagonal length in pixels

◆ SubmitProcessedFrame() [1/2]

void photon::PhotonCameraSim::SubmitProcessedFrame ( const PhotonPipelineResult & result)

◆ SubmitProcessedFrame() [2/2]

void photon::PhotonCameraSim::SubmitProcessedFrame ( const PhotonPipelineResult & result,
uint64_t ReceiveTimestamp )

Member Data Documentation

◆ prop

SimCameraProperties photon::PhotonCameraSim::prop

The documentation for this class was generated from the following file: