PhotonVision C++ v2027.0.0-alpha-2
Loading...
Searching...
No Matches
photon::PhotonCamera Class Reference

Represents a camera that is connected to PhotonVision. More...

#include <photon/PhotonCamera.h>

Public Types

using CameraMatrix = Eigen::Matrix<double, 3, 3>
 
using DistortionMatrix = Eigen::Matrix<double, 8, 1>
 

Public Member Functions

 PhotonCamera (wpi::nt::NetworkTableInstance instance, const std::string_view cameraName)
 Constructs a PhotonCamera from a root table.
 
 PhotonCamera (const std::string_view cameraName)
 Constructs a PhotonCamera from the name of the camera.
 
 PhotonCamera (PhotonCamera &&)=default
 
 ~PhotonCamera ()=default
 
std::vector< PhotonPipelineResultGetAllUnreadResults ()
 The list of pipeline results sent by PhotonVision since the last call to GetAllUnreadResults().
 
PhotonPipelineResult GetLatestResult ()
 
void SetDriverMode (bool driverMode)
 Toggles driver mode.
 
bool GetDriverMode () const
 Returns whether the camera is in driver mode.
 
void SetFPSLimit (int fpsLimit)
 Sets the FPS limit on the camera.
 
int GetFPSLimit () const
 
void SetEnabled (bool enabled)
 Sets whether the camera is enabled, default is true.
 
bool GetEnabled () const
 
void TakeInputSnapshot (void)
 Request the camera to save a new image file from the input camera stream with overlays.
 
void TakeOutputSnapshot (void)
 Request the camera to save a new image file from the output stream with overlays.
 
void SetPipelineIndex (int index)
 Allows the user to select the active pipeline index.
 
int GetPipelineIndex () const
 Returns the active pipeline index.
 
LEDMode GetLEDMode () const
 Returns the current LED mode.
 
void SetLEDMode (LEDMode led)
 Sets the LED mode.
 
const std::string_view GetCameraName () const
 Returns the name of the camera.
 
bool IsConnected ()
 Returns whether the camera is connected and actively returning new data.
 
std::optional< CameraMatrixGetCameraMatrix ()
 Get the camera calibration matrix, in standard OpenCV form.
 
std::optional< DistortionMatrixGetDistCoeffs ()
 Returns the camera calibration's distortion coefficients, in OPENCV8 form.
 
std::shared_ptr< wpi::nt::NetworkTable > GetCameraTable () const
 

Static Public Member Functions

static void SetVersionCheckEnabled (bool enabled)
 Sets whether or not coprocessor version checks will occur.
 

Public Attributes

bool test = false
 
std::vector< PhotonPipelineResulttestResult
 

Protected Attributes

std::shared_ptr< wpi::nt::NetworkTable > mainTable
 
std::shared_ptr< wpi::nt::NetworkTable > rootTable
 
wpi::nt::RawSubscriber rawBytesEntry
 
wpi::nt::IntegerPublisher inputSaveImgEntry
 
wpi::nt::IntegerSubscriber inputSaveImgSubscriber
 
wpi::nt::IntegerPublisher outputSaveImgEntry
 
wpi::nt::IntegerSubscriber outputSaveImgSubscriber
 
wpi::nt::IntegerPublisher pipelineIndexPub
 
wpi::nt::IntegerSubscriber pipelineIndexSub
 
wpi::nt::IntegerPublisher ledModePub
 
wpi::nt::IntegerSubscriber ledModeSub
 
wpi::nt::StringSubscriber versionEntry
 
wpi::nt::DoubleArraySubscriber cameraIntrinsicsSubscriber
 
wpi::nt::DoubleArraySubscriber cameraDistortionSubscriber
 
wpi::nt::BooleanSubscriber driverModeSubscriber
 
wpi::nt::BooleanPublisher driverModePublisher
 
wpi::nt::IntegerSubscriber fpsLimitSubscriber
 
wpi::nt::IntegerPublisher fpsLimitPublisher
 
wpi::nt::BooleanSubscriber enabledSubscriber
 
wpi::nt::BooleanPublisher enabledPublisher
 
wpi::nt::IntegerSubscriber ledModeSubscriber
 
wpi::nt::IntegerSubscriber heartbeatSubscriber
 
wpi::nt::MultiSubscriber topicNameSubscriber
 
std::string path
 
std::string cameraName
 
wpi::Alert disconnectAlert
 
wpi::Alert timesyncAlert
 

Detailed Description

Represents a camera that is connected to PhotonVision.

ß

Member Typedef Documentation

◆ CameraMatrix

using photon::PhotonCamera::CameraMatrix = Eigen::Matrix<double, 3, 3>

◆ DistortionMatrix

using photon::PhotonCamera::DistortionMatrix = Eigen::Matrix<double, 8, 1>

Constructor & Destructor Documentation

◆ PhotonCamera() [1/3]

photon::PhotonCamera::PhotonCamera ( wpi::nt::NetworkTableInstance instance,
const std::string_view cameraName )
explicit

Constructs a PhotonCamera from a root table.

Parameters
instanceThe NetworkTableInstance to pull data from. This can be a custom instance in simulation, but should usually be the default NTInstance from NetworkTableInstance::getDefault
cameraNameThe name of the camera, as seen in the UI. over.

◆ PhotonCamera() [2/3]

photon::PhotonCamera::PhotonCamera ( const std::string_view cameraName)
explicit

Constructs a PhotonCamera from the name of the camera.

Parameters
cameraNameThe nickname of the camera (found in the PhotonVision UI).

◆ PhotonCamera() [3/3]

photon::PhotonCamera::PhotonCamera ( PhotonCamera && )
default

◆ ~PhotonCamera()

photon::PhotonCamera::~PhotonCamera ( )
default

Member Function Documentation

◆ GetAllUnreadResults()

std::vector< PhotonPipelineResult > photon::PhotonCamera::GetAllUnreadResults ( )

The list of pipeline results sent by PhotonVision since the last call to GetAllUnreadResults().

Calling this function clears the internal FIFO queue, and multiple calls to GetAllUnreadResults() will return different (potentially empty) result arrays. Be careful to call this exactly ONCE per loop of your robot code! FIFO depth is limited to 20 changes, so make sure to call this frequently enough to avoid old results being discarded, too!

◆ GetCameraMatrix()

std::optional< CameraMatrix > photon::PhotonCamera::GetCameraMatrix ( )

Get the camera calibration matrix, in standard OpenCV form.

Returns
std::optional<cv::Mat>

◆ GetCameraName()

const std::string_view photon::PhotonCamera::GetCameraName ( ) const

Returns the name of the camera.

This will return the same value that was given to the constructor as cameraName.

Returns
The name of the camera.

◆ GetCameraTable()

std::shared_ptr< wpi::nt::NetworkTable > photon::PhotonCamera::GetCameraTable ( ) const
inline

◆ GetDistCoeffs()

std::optional< DistortionMatrix > photon::PhotonCamera::GetDistCoeffs ( )

Returns the camera calibration's distortion coefficients, in OPENCV8 form.

Higher-order terms are set to 0

Returns
The distortion coefficients in a 8x1 matrix, if they are published by the camera. Empty otherwise.

◆ GetDriverMode()

bool photon::PhotonCamera::GetDriverMode ( ) const

Returns whether the camera is in driver mode.

Returns
Whether the camera is in driver mode.

◆ GetEnabled()

bool photon::PhotonCamera::GetEnabled ( ) const
Returns
Whether the camera is enabled.

◆ GetFPSLimit()

int photon::PhotonCamera::GetFPSLimit ( ) const
Returns
The FPS limit set on the camera, or -1 if no limit is set.

◆ GetLatestResult()

PhotonPipelineResult photon::PhotonCamera::GetLatestResult ( )

◆ GetLEDMode()

LEDMode photon::PhotonCamera::GetLEDMode ( ) const

Returns the current LED mode.

Returns
The current LED mode.

◆ GetPipelineIndex()

int photon::PhotonCamera::GetPipelineIndex ( ) const

Returns the active pipeline index.

Returns
The active pipeline index.

◆ IsConnected()

bool photon::PhotonCamera::IsConnected ( )

Returns whether the camera is connected and actively returning new data.

Connection status is debounced.

Returns
True if the camera is actively sending frame data, false otherwise.

◆ SetDriverMode()

void photon::PhotonCamera::SetDriverMode ( bool driverMode)

Toggles driver mode.

Parameters
driverModeWhether to set driver mode.

◆ SetEnabled()

void photon::PhotonCamera::SetEnabled ( bool enabled)

Sets whether the camera is enabled, default is true.

Parameters
enabledWhether to enable the camera.

◆ SetFPSLimit()

void photon::PhotonCamera::SetFPSLimit ( int fpsLimit)

Sets the FPS limit on the camera.

An FPS of 0 means to pause processing until a FPS limit greater than 0 is set.

A negative FPS limit is treated as no FPS limit, and will run as fast as possible.

Otherwise, will limit processing to at most the provided FPS limit

Parameters
fpsThe FPS limit to set.

◆ SetLEDMode()

void photon::PhotonCamera::SetLEDMode ( LEDMode led)

Sets the LED mode.

Parameters
ledThe mode to set to.

◆ SetPipelineIndex()

void photon::PhotonCamera::SetPipelineIndex ( int index)

Allows the user to select the active pipeline index.

Parameters
indexThe active pipeline index.

◆ SetVersionCheckEnabled()

static void photon::PhotonCamera::SetVersionCheckEnabled ( bool enabled)
static

Sets whether or not coprocessor version checks will occur.

Setting this to true will silence all console warnings about coproccessor connection, so be careful when enabling this and ensure all your coprocessors are communicating to the robot properly and everything has matching versions.

Parameters
enabledWhether or not to enable coprocessor version checks

◆ TakeInputSnapshot()

void photon::PhotonCamera::TakeInputSnapshot ( void )

Request the camera to save a new image file from the input camera stream with overlays.

Images take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk space and eventually cause the system to stop working. Clear out images in /opt/photonvision/photonvision_config/imgSaves frequently to prevent issues.

◆ TakeOutputSnapshot()

void photon::PhotonCamera::TakeOutputSnapshot ( void )

Request the camera to save a new image file from the output stream with overlays.

Images take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk space and eventually cause the system to stop working. Clear out images in /opt/photonvision/photonvision_config/imgSaves frequently to prevent issues.

Member Data Documentation

◆ cameraDistortionSubscriber

wpi::nt::DoubleArraySubscriber photon::PhotonCamera::cameraDistortionSubscriber
protected

◆ cameraIntrinsicsSubscriber

wpi::nt::DoubleArraySubscriber photon::PhotonCamera::cameraIntrinsicsSubscriber
protected

◆ cameraName

std::string photon::PhotonCamera::cameraName
protected

◆ disconnectAlert

wpi::Alert photon::PhotonCamera::disconnectAlert
protected

◆ driverModePublisher

wpi::nt::BooleanPublisher photon::PhotonCamera::driverModePublisher
protected

◆ driverModeSubscriber

wpi::nt::BooleanSubscriber photon::PhotonCamera::driverModeSubscriber
protected

◆ enabledPublisher

wpi::nt::BooleanPublisher photon::PhotonCamera::enabledPublisher
protected

◆ enabledSubscriber

wpi::nt::BooleanSubscriber photon::PhotonCamera::enabledSubscriber
protected

◆ fpsLimitPublisher

wpi::nt::IntegerPublisher photon::PhotonCamera::fpsLimitPublisher
protected

◆ fpsLimitSubscriber

wpi::nt::IntegerSubscriber photon::PhotonCamera::fpsLimitSubscriber
protected

◆ heartbeatSubscriber

wpi::nt::IntegerSubscriber photon::PhotonCamera::heartbeatSubscriber
protected

◆ inputSaveImgEntry

wpi::nt::IntegerPublisher photon::PhotonCamera::inputSaveImgEntry
protected

◆ inputSaveImgSubscriber

wpi::nt::IntegerSubscriber photon::PhotonCamera::inputSaveImgSubscriber
protected

◆ ledModePub

wpi::nt::IntegerPublisher photon::PhotonCamera::ledModePub
protected

◆ ledModeSub

wpi::nt::IntegerSubscriber photon::PhotonCamera::ledModeSub
protected

◆ ledModeSubscriber

wpi::nt::IntegerSubscriber photon::PhotonCamera::ledModeSubscriber
protected

◆ mainTable

std::shared_ptr<wpi::nt::NetworkTable> photon::PhotonCamera::mainTable
protected

◆ outputSaveImgEntry

wpi::nt::IntegerPublisher photon::PhotonCamera::outputSaveImgEntry
protected

◆ outputSaveImgSubscriber

wpi::nt::IntegerSubscriber photon::PhotonCamera::outputSaveImgSubscriber
protected

◆ path

std::string photon::PhotonCamera::path
protected

◆ pipelineIndexPub

wpi::nt::IntegerPublisher photon::PhotonCamera::pipelineIndexPub
protected

◆ pipelineIndexSub

wpi::nt::IntegerSubscriber photon::PhotonCamera::pipelineIndexSub
protected

◆ rawBytesEntry

wpi::nt::RawSubscriber photon::PhotonCamera::rawBytesEntry
protected

◆ rootTable

std::shared_ptr<wpi::nt::NetworkTable> photon::PhotonCamera::rootTable
protected

◆ test

bool photon::PhotonCamera::test = false

◆ testResult

std::vector<PhotonPipelineResult> photon::PhotonCamera::testResult

◆ timesyncAlert

wpi::Alert photon::PhotonCamera::timesyncAlert
protected

◆ topicNameSubscriber

wpi::nt::MultiSubscriber photon::PhotonCamera::topicNameSubscriber
protected

◆ versionEntry

wpi::nt::StringSubscriber photon::PhotonCamera::versionEntry
protected

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