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

Make south auto routines work! #196

Closed
wants to merge 4 commits into from
Closed
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
32 changes: 26 additions & 6 deletions autonomous/autonomous.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ class Centre5Centre4(AutoBase):

def __init__(self) -> None:
note_paths = [
Path([NotePositions.Centre5], face_target=False),
Path(
[
PathPositions.avoid_starting_faults,
PathPositions.avoid_stage_S,
NotePositions.Centre5,
],
face_target=False,
),
Path(
[
PathPositions.avoid_stage_S,
Expand All @@ -186,7 +193,10 @@ def __init__(self) -> None:
]

shoot_paths = [
Path([ShootingPositions.source_side], face_target=True),
Path(
[PathPositions.avoid_stage_S, ShootingPositions.source_side],
face_target=True,
),
Path(
[
PathPositions.avoid_stage_S,
Expand All @@ -195,7 +205,7 @@ def __init__(self) -> None:
face_target=True,
),
]
sim_start_pos = Translation2d(15.4, 2.94)
sim_start_pos = ShootingPositions.source_side
rotation = rotation_to_red_speaker(sim_start_pos)
sim_start_pose = Pose2d(sim_start_pos, rotation)
super().__init__(note_paths, shoot_paths, sim_start_pose)
Expand All @@ -207,7 +217,14 @@ class Centre5Centre4Centre3(AutoBase):

def __init__(self) -> None:
note_paths = [
Path([NotePositions.Centre5], face_target=False),
Path(
[
PathPositions.avoid_starting_faults,
PathPositions.avoid_stage_S,
NotePositions.Centre5,
],
face_target=False,
),
Path(
[
PathPositions.avoid_stage_S,
Expand All @@ -226,7 +243,10 @@ def __init__(self) -> None:
]

shoot_paths = [
Path([ShootingPositions.source_side], face_target=True),
Path(
[PathPositions.avoid_stage_S, ShootingPositions.source_side],
face_target=True,
),
Path(
[
PathPositions.avoid_stage_S,
Expand All @@ -243,7 +263,7 @@ def __init__(self) -> None:
face_target=True,
),
]
sim_start_pos = Translation2d(15.4, 2.94)
sim_start_pos = ShootingPositions.source_side
rotation = rotation_to_red_speaker(sim_start_pos)
sim_start_pose = Pose2d(sim_start_pos, rotation)
super().__init__(note_paths, shoot_paths, sim_start_pose)
22 changes: 14 additions & 8 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, y_close_to_stage
from utilities.position import distance_between


class MyRobot(magicbot.MagicRobot):
Expand All @@ -47,6 +47,8 @@ class MyRobot(magicbot.MagicRobot):
vision_port: VisualLocalizer
vision_starboard: VisualLocalizer

START_POS_TOLERANCE = 1

def createObjects(self) -> None:
self.data_log = wpilib.DataLogManager.getLog()

Expand All @@ -71,7 +73,7 @@ def createObjects(self) -> None:
)

def teleopInit(self) -> None:
pass
self.field.getObject("Intended start pos").setPoses([])

def teleopPeriodic(self) -> None:
if self.climber.should_lock_mechanisms():
Expand Down Expand Up @@ -204,6 +206,7 @@ def disabledPeriodic(self) -> None:
if (
not self.vision_port.sees_target()
and not self.vision_starboard.sees_target()
and not self.isSimulation()
):
self.status_lights.no_vision()
else:
Expand All @@ -213,11 +216,14 @@ def disabledPeriodic(self) -> None:
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, current_pose):
if y_close_to_stage(current_pose):
self.status_lights.too_close_to_stage()
else:
self.status_lights.rainbow()
self.field.getObject("Intended start pos").setPose(
intended_start_pose
)
if (
distance_between(intended_start_pose, current_pose)
< self.START_POS_TOLERANCE
):
self.status_lights.rainbow()
else:
self.status_lights.invalid_start()
else:
Expand All @@ -226,7 +232,7 @@ def disabledPeriodic(self) -> None:
self.status_lights.missing_start_pose()

def autonomousInit(self) -> None:
pass
self.field.getObject("Intended start pos").setPoses([])


if __name__ == "__main__":
Expand Down
14 changes: 4 additions & 10 deletions utilities/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ShootingPositions:
amp_speaker_bounce = Translation2d(
14.7, (NotePositions.amp.y + NotePositions.speaker.y) / 2
)
source_side = Translation2d(14.7, 2.8)
source_side = Translation2d(15.556, 4.034)


class TeamPoses:
Expand All @@ -76,15 +76,8 @@ class TeamPoses:
RED_PODIUM = field_flip_pose2d(BLUE_PODIUM)


def on_same_side_of_stage(intended_start_pose: Pose2d, current_pose: Pose2d) -> bool:
return not (
(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
def distance_between(intended_start_pose: Pose2d, current_pose: Pose2d) -> float:
return (intended_start_pose.translation() - current_pose.translation()).norm()


class PathPositions:
Expand All @@ -93,3 +86,4 @@ class PathPositions:
stage_transition_S_entry = Translation2d(13.0, 2.5)
avoid_wall = Translation2d(10.80, 6.55)
avoid_stage_S = Translation2d(10.66, 1.40)
avoid_starting_faults = Translation2d(14.429, 2.946)
Loading