-
Notifications
You must be signed in to change notification settings - Fork 246
Ported PhotonUtils into Python #1739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Connor-Long0
wants to merge
18
commits into
PhotonVision:main
Choose a base branch
from
Raptacon:feat/1738_cdl_photonUtils2025
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
30e9259
ported photonutils to python
Connor-Long0 ecc77a6
enabled photonutils test in simulation test file
Connor-Long0 258cb04
fixed calculate distance unit tests
Connor-Long0 5e5d13c
replaced dunder methods with operators
822f105
replaced dunder methods
CollinSwierkosz 8d977df
Merge branch 'main' of https://github.com/Raptacon/photonvision into …
2e0e352
Merge branch 'feat/1738_cdl_photonUtils2025' of https://github.com/Ra…
CollinSwierkosz d1cbd2d
formatting back to python3
c8818fa
fromatting back to python3
CollinSwierkosz 08df4c1
formatting changed back to python3
Connor-Long0 81522ff
Merge branch 'feat/1738_cdl_photonUtils2025' of https://github.com/Ra…
902a89d
change back to python3
GannonCodes fde2d73
Merge branch 'feat/1738_cdl_photonUtils2025' of https://github.com/Ra…
GannonCodes 1e6245c
fixed formatting in photonUtils.py
Connor-Long0 1b510fe
Merge branch 'feat/1738_cdl_photonUtils2025' of https://github.com/Ra…
Connor-Long0 73a2189
formatted utils to work with linter
Connor-Long0 d9f96c6
linter issues fixed
Connor-Long0 ff6a4e3
Merge branch 'main' into feat/1738_cdl_photonUtils2025
Connor-Long0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import photonlibpy | ||
from wpimath.geometry import Translation2d, Rotation2d, Pose2d, Transform2d, Pose3d, Transform3d | ||
import math | ||
|
||
class PhotonUtils: | ||
def __init__(): | ||
pass | ||
|
||
@staticmethod | ||
def calculateDistanceToTargetMeters(cameraHeightMeters: float, | ||
targetHeightMeters: float, | ||
cameraPitchRadians: float, | ||
targetPitchRadians: float) -> float: | ||
return (targetHeightMeters - cameraHeightMeters) / math.tan(cameraPitchRadians + targetPitchRadians) | ||
|
||
@staticmethod | ||
def estimateCameraToTargetTranslation(targetDistanceMeters: float, | ||
yaw: Rotation2d): | ||
return Translation2d(yaw.cos() * targetDistanceMeters, yaw.sin() * targetDistanceMeters) | ||
|
||
@staticmethod | ||
def estimateCameraToTarget(cameraToTargetTranslation: Translation2d, | ||
fieldToTarget : Pose2d, | ||
gyroAngle: Rotation2d): | ||
return Transform2d(cameraToTargetTranslation, gyroAngle * (-1) - fieldToTarget.rotation()) | ||
|
||
@staticmethod | ||
def estimateFieldToCamera(cameraToTarget: Transform2d, | ||
fieldToTarget: Pose2d): | ||
targetToCamera = cameraToTarget.inverse() | ||
return fieldToTarget.transformBy(targetToCamera) | ||
|
||
@staticmethod | ||
def estimateFieldToRobot(cameraToTarget: Transform2d, | ||
fieldToTarget: Pose2d, | ||
cameraToRobot: Transform2d): | ||
return PhotonUtils.estimateFieldToCamera(cameraToTarget, fieldToTarget).transformBy(cameraToRobot) | ||
|
||
@staticmethod | ||
def estimateFieldToRobotAprilTag(cameraToTarget: Transform3d, | ||
fieldRelativeTagPose: Pose3d, | ||
cameraToRobot: Transform3d): | ||
return fieldRelativeTagPose + cameraToTarget.inverse() + cameraToRobot | ||
|
||
@staticmethod | ||
def getYawToPose(robotPose: Pose2d, | ||
targetPose: Pose2d): | ||
relativeTr1 = targetPose.relativeTo(robotPose).translation() | ||
return Rotation2d(relativeTr1.X(), relativeTr1.Y()) | ||
|
||
@staticmethod | ||
def getDistanceToPose(robotPose: Pose2d, | ||
targetPose: Pose2d): | ||
return robotPose.translation().distance(targetPose.translation()) | ||
|
||
@staticmethod | ||
def estimateFieldToRobot(cameraHeightMeters: float, | ||
targetHeightMeters: float, | ||
cameraPitchRadians: float, | ||
targetPitchRadians: float, | ||
targetYaw: Rotation2d, | ||
gyroAngle: Rotation2d, | ||
fieldToTarget: Pose2d, | ||
cameraToRobot: Transform2d): | ||
return PhotonUtils.estimateFieldToRobot(PhotonUtils.estimateCameraToTarget(PhotonUtils.estimateCameraToTargetTranslation(PhotonUtils.calculateDistanceToTargetMeters(cameraHeightMeters, targetHeightMeters, cameraPitchRadians, targetPitchRadians), targetYaw), fieldToTarget, gyroAngle), fieldToTarget, cameraToRobot) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.