Skip to content

Commit

Permalink
Merge pull request #32 from thedropbears/add_game_utils
Browse files Browse the repository at this point in the history
add game utility to return team speaker position
  • Loading branch information
LucienMorey authored Jan 15, 2024
2 parents 9d1f0bf + c97a76d commit c15a198
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions utilities/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import typing

import robotpy_apriltag
import wpilib
from wpimath.geometry import Pose3d, Translation3d

apriltag_layout = robotpy_apriltag.loadAprilTagLayoutField(
robotpy_apriltag.AprilTagField.k2024Crescendo
)

TagId = typing.Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]

get_fiducial_pose = typing.cast(
typing.Callable[[TagId], Pose3d],
apriltag_layout.getTagPose,
)

RED_SPEAKER_POSE = get_fiducial_pose(4)
BLUE_SPEAKER_POSE = get_fiducial_pose(7)


# This will default to the blue alliance if a proper link to the driver station has not yet been established
def is_red() -> bool:
return wpilib.DriverStation.getAlliance() == wpilib.DriverStation.Alliance.kRed


def get_goal_speaker_position() -> Translation3d:
if is_red():
return RED_SPEAKER_POSE.translation()

return BLUE_SPEAKER_POSE.translation()

0 comments on commit c15a198

Please sign in to comment.