Skip to content
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

Check we don't start too close to the stage #190

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def missing_start_pose(self) -> None:
def no_vision(self) -> None:
self.pattern = Flash(HsvColour.ORANGE)

def too_close_to_stage(self) -> None:
self.pattern = Flash(HsvColour.MAGENTA)

def disabled(self) -> None:
self.pattern = Solid(HsvColour.OFF)

Expand Down
12 changes: 7 additions & 5 deletions robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from utilities.game import is_red
from utilities.scalers import rescale_js
from utilities.functions import clamp
from utilities.position import on_same_side_of_stage
from utilities.position import on_same_side_of_stage, y_close_to_stage


class MyRobot(magicbot.MagicRobot):
Expand Down Expand Up @@ -204,11 +204,13 @@ def disabledPeriodic(self) -> None:
selected_auto = self._automodes.chooser.getSelected()
if isinstance(selected_auto, AutoBase):
intended_start_pose = selected_auto.get_starting_pose()
current_pose = self.chassis.get_pose()
if intended_start_pose is not None:
if on_same_side_of_stage(
intended_start_pose, self.chassis.get_pose()
):
self.status_lights.rainbow()
if on_same_side_of_stage(intended_start_pose, current_pose):
if y_close_to_stage(current_pose):
self.status_lights.too_close_to_stage()
else:
self.status_lights.rainbow()
else:
self.status_lights.invalid_start()
else:
Expand Down
9 changes: 7 additions & 2 deletions utilities/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ class TeamPoses:
RED_PODIUM = field_flip_pose2d(BLUE_PODIUM)


def on_same_side_of_stage(pose1: Pose2d, pose2: Pose2d) -> bool:
def on_same_side_of_stage(intended_start_pose: Pose2d, current_pose: Pose2d) -> bool:
return not (
(pose1.y > TeamPoses.BLUE_PODIUM.y) ^ (pose2.y > TeamPoses.BLUE_PODIUM.y)
(intended_start_pose.y > TeamPoses.BLUE_PODIUM.y)
^ (current_pose.y > TeamPoses.BLUE_PODIUM.y)
)


def y_close_to_stage(pose: Pose2d) -> bool:
return abs(pose.y - TeamPoses.BLUE_PODIUM.y) < 0.9


class PathPositions:
stage_transition_N = Translation2d(11.4, 4.5)
stage_transition_S = Translation2d(11.4, 3.74)
Expand Down
Loading