PhotonVision C++ dev-v2025.0.0-beta-8-2-gbd1c5c03
Loading...
Searching...
No Matches
photon::PhotonUtils Class Reference

#include <photon/PhotonUtils.h>

Static Public Member Functions

static units::meter_t CalculateDistanceToTarget (units::meter_t cameraHeight, units::meter_t targetHeight, units::radian_t cameraPitch, units::radian_t targetPitch)
 Algorithm from https://docs.limelightvision.io/en/latest/cs_estimating_distance.html Estimates range to a target using the target's elevation.
 
static frc::Translation2d EstimateCameraToTargetTranslation (units::meter_t targetDistance, const frc::Rotation2d &yaw)
 Estimate the Translation2d of the target relative to the camera.
 
static frc::Pose2d EstimateFieldToRobot (units::meter_t cameraHeight, units::meter_t targetHeight, units::radian_t cameraPitch, units::radian_t targetPitch, const frc::Rotation2d &targetYaw, const frc::Rotation2d &gyroAngle, const frc::Pose2d &fieldToTarget, const frc::Transform2d &cameraToRobot)
 Estimate the position of the robot in the field.
 
static frc::Transform2d EstimateCameraToTarget (const frc::Translation2d &cameraToTargetTranslation, const frc::Pose2d &fieldToTarget, const frc::Rotation2d &gyroAngle)
 Estimates a frc::Transform2d that maps the camera position to the target position, using the robot's gyro.
 
static frc::Pose2d EstimateFieldToRobot (const frc::Transform2d &cameraToTarget, const frc::Pose2d &fieldToTarget, const frc::Transform2d &cameraToRobot)
 Estimates the pose of the robot in the field coordinate system, given the position of the target relative to the camera, the target relative to the field, and the robot relative to the camera.
 
static frc::Pose2d EstimateFieldToCamera (const frc::Transform2d &cameraToTarget, const frc::Pose2d &fieldToTarget)
 Estimates the pose of the camera in the field coordinate system, given the position of the target relative to the camera, and the target relative to the field.
 

Member Function Documentation

◆ CalculateDistanceToTarget()

static units::meter_t photon::PhotonUtils::CalculateDistanceToTarget ( units::meter_t cameraHeight,
units::meter_t targetHeight,
units::radian_t cameraPitch,
units::radian_t targetPitch )
inlinestatic

Algorithm from https://docs.limelightvision.io/en/latest/cs_estimating_distance.html Estimates range to a target using the target's elevation.

This method can produce more stable results than SolvePNP when well tuned, if the full 6d robot pose is not required.

Parameters
cameraHeightThe height of the camera off the floor.
targetHeightThe height of the target off the floor.
cameraPitchThe pitch of the camera from the horizontal plane. Positive valueBytes up.
targetPitchThe pitch of the target in the camera's lens. Positive values up.
Returns
The estimated distance to the target.

◆ EstimateCameraToTarget()

static frc::Transform2d photon::PhotonUtils::EstimateCameraToTarget ( const frc::Translation2d & cameraToTargetTranslation,
const frc::Pose2d & fieldToTarget,
const frc::Rotation2d & gyroAngle )
inlinestatic

Estimates a frc::Transform2d that maps the camera position to the target position, using the robot's gyro.

Note that the gyro angle provided must line up with the field coordinate system – that is, it should read zero degrees when pointed towards the opposing alliance station, and increase as the robot rotates CCW.

Parameters
cameraToTargetTranslationA Translation2d that encodes the x/y position of the target relative to the camera.
fieldToTargetA frc::Pose2d representing the target position in the field coordinate system.
gyroAngleThe current robot gyro angle, likely from odometry.
Returns
A frc::Transform2d that takes us from the camera to the target.

◆ EstimateCameraToTargetTranslation()

static frc::Translation2d photon::PhotonUtils::EstimateCameraToTargetTranslation ( units::meter_t targetDistance,
const frc::Rotation2d & yaw )
inlinestatic

Estimate the Translation2d of the target relative to the camera.

Parameters
targetDistanceThe distance to the target.
yawThe observed yaw of the target.
Returns
The target's camera-relative translation.

◆ EstimateFieldToCamera()

static frc::Pose2d photon::PhotonUtils::EstimateFieldToCamera ( const frc::Transform2d & cameraToTarget,
const frc::Pose2d & fieldToTarget )
inlinestatic

Estimates the pose of the camera in the field coordinate system, given the position of the target relative to the camera, and the target relative to the field.

This only tracks the position of the camera, not the position of the robot itself.

Parameters
cameraToTargetThe position of the target relative to the camera.
fieldToTargetThe position of the target in the field.
Returns
The position of the camera in the field.

◆ EstimateFieldToRobot() [1/2]

static frc::Pose2d photon::PhotonUtils::EstimateFieldToRobot ( const frc::Transform2d & cameraToTarget,
const frc::Pose2d & fieldToTarget,
const frc::Transform2d & cameraToRobot )
inlinestatic

Estimates the pose of the robot in the field coordinate system, given the position of the target relative to the camera, the target relative to the field, and the robot relative to the camera.

Parameters
cameraToTargetThe position of the target relative to the camera.
fieldToTargetThe position of the target in the field.
cameraToRobotThe position of the robot relative to the camera. If the camera was mounted 3 inches behind the "origin" (usually physical center) of the robot, this would be frc::Transform2d(3 inches, 0 inches, 0 degrees).
Returns
The position of the robot in the field.

◆ EstimateFieldToRobot() [2/2]

static frc::Pose2d photon::PhotonUtils::EstimateFieldToRobot ( units::meter_t cameraHeight,
units::meter_t targetHeight,
units::radian_t cameraPitch,
units::radian_t targetPitch,
const frc::Rotation2d & targetYaw,
const frc::Rotation2d & gyroAngle,
const frc::Pose2d & fieldToTarget,
const frc::Transform2d & cameraToRobot )
inlinestatic

Estimate the position of the robot in the field.

Parameters
cameraHeightMetersThe physical height of the camera off the floor in meters.
targetHeightMetersThe physical height of the target off the floor in meters. This should be the height of whatever is being targeted (i.e. if the targeting region is set to top, this should be the height of the top of the target).
cameraPitchRadiansThe pitch of the camera from the horizontal plane in radians. Positive values up.
targetPitchRadiansThe pitch of the target in the camera's lens in radians. Positive values up.
targetYawThe observed yaw of the target. Note that this must be CCW-positive, and Photon returns CW-positive.
gyroAngleThe current robot gyro angle, likely from odometry.
fieldToTargetA frc::Pose2d representing the target position in the field coordinate system.
cameraToRobotThe position of the robot relative to the camera. If the camera was mounted 3 inches behind the "origin" (usually physical center) of the robot, this would be frc::Transform2d(3 inches, 0 inches, 0 degrees).
Returns
The position of the robot in the field.

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