generated from Programming-TRIGON/RobotTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Turret Camera #13
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
levyishai
wants to merge
12
commits into
main
Choose a base branch
from
turret-camera
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
Turret Camera #13
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d4aec9b
Implemented DynamicCameraTransform, need to change and add Jdocs
levyishai b7b3ba7
Added JDocs
levyishai 7a719f1
Correct transform logic
levyishai b86a05a
Merge branch 'main' into turret-camera
levyishai c41abfb
Merge branch 'main' into turret-camera
ShmayaR 2d65347
Update lib
ShmayaR 7731075
added calculation for turret camera pose
ShmayaR 7c5afae
No need to update lib, thread the signal
levyishai 0e0fb69
Merge branch 'main' into turret-camera
levyishai 12e6170
Implement cleanly
levyishai 8783fac
Null checks and correction
levyishai ca38c57
added if
levyishai 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
7 changes: 3 additions & 4 deletions
7
src/main/java/frc/trigon/robot/poseestimation/apriltagcamera/AprilTagCameraIO.java
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
110 changes: 110 additions & 0 deletions
110
src/main/java/frc/trigon/robot/poseestimation/apriltagcamera/DynamicCameraTransform.java
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,110 @@ | ||
| package frc.trigon.robot.poseestimation.apriltagcamera; | ||
|
|
||
| import edu.wpi.first.math.geometry.*; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * Handles transformations between camera and robot coordinate frames. | ||
| * Supports both static and time-dependent camera positions, useful for cameras on moving mechanisms. | ||
| */ | ||
| public class DynamicCameraTransform { | ||
| private final Function<Double, Transform3d> robotCenterToCameraFunction; | ||
|
|
||
| /** | ||
| * Constructs a DynamicCameraTransform with a static camera position. | ||
| * | ||
| * @param robotCenterToCamera the fixed transform from robot center to camera | ||
| */ | ||
| public DynamicCameraTransform(Transform3d robotCenterToCamera) { | ||
| this(timestamp -> robotCenterToCamera); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a DynamicCameraTransform with a time-dependent camera position. | ||
| * | ||
| * @param robotCenterToCameraFunction function that returns the transform from robot center to camera at a given timestamp | ||
| */ | ||
| public DynamicCameraTransform(Function<Double, Transform3d> robotCenterToCameraFunction) { | ||
| this.robotCenterToCameraFunction = robotCenterToCameraFunction; | ||
| } | ||
|
|
||
| /** | ||
| * Transforms a camera pose to a robot pose in 2D. | ||
| * | ||
| * @param cameraPose the camera's pose on the field | ||
| * @param timestampSeconds the timestamp for the camera transform | ||
| * @return the robot's pose on the field | ||
| */ | ||
| public Pose2d calculate2dRobotPose(Pose2d cameraPose, double timestampSeconds) { | ||
| final Transform2d cameraToRobotCenter = get2dCameraToRobotCenter(timestampSeconds); | ||
| return cameraPose.transformBy(cameraToRobotCenter); | ||
| } | ||
|
|
||
| /** | ||
| * Transforms a camera pose to a robot pose in 3D. | ||
| * | ||
| * @param cameraPose the camera's pose in 3D space | ||
| * @param timestampSeconds the timestamp for the camera transform | ||
| * @return the robot's pose in 3D space | ||
| */ | ||
| public Pose3d calculate3dRobotPose(Pose3d cameraPose, double timestampSeconds) { | ||
| final Transform3d cameraToRobotCenter = get3dCameraToRobotCenter(timestampSeconds); | ||
| return cameraPose.transformBy(cameraToRobotCenter); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the 2D transform from robot center to camera. | ||
| * Only x, y, and yaw components are preserved to avoid pitch and roll inaccuracies. | ||
| * | ||
| * @param timestampSeconds the timestamp for the transform | ||
| * @return the 2D transform from robot center to camera | ||
| */ | ||
| public Transform2d get2dRobotCenterToCamera(double timestampSeconds) { | ||
| return toTransform2d(get3dRobotCenterToCamera(timestampSeconds)); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the 2D transform from camera to robot center. | ||
| * Only x, y, and yaw components are preserved to avoid pitch and roll inaccuracies. | ||
| * | ||
| * @param timestampSeconds the timestamp for the transform | ||
| * @return the 2D transform from camera to robot center | ||
| */ | ||
| public Transform2d get2dCameraToRobotCenter(double timestampSeconds) { | ||
| return toTransform2d(get3dCameraToRobotCenter(timestampSeconds)); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the 3D transform from robot center to camera. | ||
| * | ||
| * @param timestampSeconds the timestamp for the transform | ||
| * @return the 3D transform from robot center to camera | ||
| */ | ||
| public Transform3d get3dRobotCenterToCamera(double timestampSeconds) { | ||
| return robotCenterToCameraFunction.apply(timestampSeconds); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the 3D transform from camera to robot center. | ||
| * | ||
| * @param timestampSeconds the timestamp for the transform | ||
| * @return the 3D transform from camera to robot center | ||
| */ | ||
| public Transform3d get3dCameraToRobotCenter(double timestampSeconds) { | ||
| return get3dRobotCenterToCamera(timestampSeconds).inverse(); | ||
| } | ||
|
|
||
| /** | ||
| * Converts a 3D transform to a 2D transform using only x, y, and yaw components. | ||
| * | ||
| * @param transform3d the 3D transform to convert | ||
| * @return the 2D transform | ||
| */ | ||
| private Transform2d toTransform2d(Transform3d transform3d) { | ||
| final Translation2d robotCenterToCameraTranslation = transform3d.getTranslation().toTranslation2d(); | ||
| final Rotation2d robotCenterToCameraRotation = transform3d.getRotation().toRotation2d(); | ||
|
|
||
| return new Transform2d(robotCenterToCameraTranslation, robotCenterToCameraRotation); | ||
| } | ||
| } | ||
6 changes: 3 additions & 3 deletions
6
src/main/java/frc/trigon/robot/poseestimation/apriltagcamera/io/AprilTagLimelightIO.java
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.
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.