Skip to content

Commit 42f9e80

Browse files
committed
Precompute 2D pose fiducial flattening
1 parent 476f897 commit 42f9e80

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

components/vision.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from components.chassis import ChassisComponent
2323
from utilities.caching import HasPerLoopCache, cache_per_loop
2424
from utilities.functions import clamp
25-
from utilities.game import APRILTAGS, apriltag_layout
25+
from utilities.game import APRILTAGS_2D, apriltag_layout
2626
from utilities.rev import configure_through_bore_encoder
2727

2828

@@ -212,8 +212,8 @@ def visible_tags(self) -> list[VisibleTag]:
212212
robot_pose = self.chassis.get_pose()
213213
turret_pose = robot_pose.transformBy(self.robot_to_turret_2d)
214214

215-
for tag in APRILTAGS:
216-
tag_pose = tag.pose.toPose2d()
215+
for tag in APRILTAGS_2D:
216+
tag_pose = tag.pose
217217
turret_to_tag = tag_pose.translation() - turret_pose.translation()
218218
turret_angle_to_tag = turret_to_tag.angle()
219219
relative_bearing = turret_angle_to_tag - turret_pose.rotation()
@@ -241,7 +241,7 @@ def visible_tags(self) -> list[VisibleTag]:
241241
):
242242
# Test for relative facing is more than 90 degrees because we don't want to be too
243243
# close to parallel to the tag
244-
tags_in_view.append(VisibleTag(tag.ID, relative_bearing_rad, distance))
244+
tags_in_view.append(VisibleTag(tag.id, relative_bearing_rad, distance))
245245

246246
return tags_in_view
247247

utilities/game.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Descriptions of the field and match state."""
22

3+
import dataclasses
34
import math
45
import typing
56

@@ -27,6 +28,18 @@
2728

2829
APRILTAGS = apriltag_layout.getTags()
2930

31+
32+
@dataclasses.dataclass(slots=True)
33+
class Tag2d:
34+
id: TagId
35+
pose: Pose2d
36+
37+
38+
APRILTAGS_2D = [
39+
Tag2d(typing.cast(TagId, tag.ID), tag.pose.toPose2d()) for tag in APRILTAGS
40+
]
41+
42+
3043
L3_TAGS = [7, 9, 11, 18, 20, 22]
3144
L2_TAGS = [6, 8, 10, 17, 19, 21]
3245

0 commit comments

Comments
 (0)