Skip to content

Commit

Permalink
Fix coordinate scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
mlists committed Mar 11, 2024
1 parent 6cf315b commit 9237c0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
11 changes: 9 additions & 2 deletions autonomous/autonomous.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import math

from utilities.position import (
NotePositions,
Path,
ShootingPositions,
PathPositions,
rotation_to_red_speaker,
)
from utilities import game
from autonomous.base import AutoBase
from wpimath.geometry import Pose2d, Translation2d
from wpimath.geometry import Pose2d, Translation2d, Rotation2d


def rotation_to_red_speaker(position: Translation2d) -> Rotation2d:
t = game.RED_SPEAKER_POSE.toPose2d().translation() - position
return t.angle() + Rotation2d(math.pi)


class PodiumSpeakerAmpTopcentre(AutoBase):
Expand Down
2 changes: 2 additions & 0 deletions autonomous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def calculate_trajectory(self, path: Path) -> Trajectory:
# second last pose might be our our current pose
second_last = waypoints[-2] if len(waypoints) > 1 else pose.translation()
disp = endpoint - second_last
if not game.is_red():
disp = game.field_flip_translation2d(disp)
heading_target = math.atan2(disp.y, disp.x)
self.goal_heading = heading_target

Expand Down
2 changes: 1 addition & 1 deletion utilities/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def field_flip_rotation2d(r: Rotation2d):


def field_flip_angle(r: float):
return math.atan2(math.sin(r + math.pi), math.cos(r + math.pi))
return math.atan2(math.sin(math.pi - r), math.cos(math.pi - r))


def field_flip_translation2d(t: Translation2d):
Expand Down
22 changes: 15 additions & 7 deletions utilities/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from wpimath.geometry import Rotation2d, Translation2d, Pose2d

from utilities.game import RED_SPEAKER_POSE, field_flip_pose2d, translation_to_goal


def rotation_to_red_speaker(position: Translation2d) -> Rotation2d:
t = translation_to_goal(position)
return t.angle() + Rotation2d(math.pi)
from utilities.game import (
RED_SPEAKER_POSE,
field_flip_pose2d,
field_flip_translation2d,
get_goal_speaker_position,
field_flip_angle,
)


class Path:
Expand All @@ -19,9 +20,16 @@ def __init__(self, waypoints: list[Translation2d], face_target: bool):
self.waypoints = waypoints
self.face_target = face_target
if face_target:
last_waypoint = waypoints[-1]
self.final_heading = (
rotation_to_red_speaker(waypoints[-1]).radians() + math.pi
(
get_goal_speaker_position().toTranslation2d()
- field_flip_translation2d(last_waypoint)
)
.angle()
.radians()
)
self.final_heading = field_flip_angle(self.final_heading) + math.pi
else:
self.final_heading = 0

Expand Down

0 comments on commit 9237c0b

Please sign in to comment.