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

Add shot logging for tuning at comp #194

Merged
merged 1 commit into from
Mar 14, 2024
Merged
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
22 changes: 20 additions & 2 deletions controllers/shooter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import math

from wpimath.geometry import Translation2d
from wpiutil.log import DataLog, FloatArrayLogEntry, FloatLogEntry
from wpilib import DriverStation

from magicbot import StateMachine, state, timed_state, feedback, tunable

Expand All @@ -18,6 +20,8 @@ class Shooter(StateMachine):
intake_component: IntakeComponent
status_lights: LightStrip

data_log: DataLog

SPEED_LIMIT = tunable(1)
SPINNING_SPEED_LIMIT = tunable(1)

Expand All @@ -26,6 +30,13 @@ def __init__(self):
self.bearing_tolerance = 0.0
self.bearing_to_speaker = 0.0

def setup(self):
self.shot_time_entry = FloatLogEntry(self.data_log, "Shooter: Shot match times")
self.shot_range_entry = FloatLogEntry(self.data_log, "Shooter: Shot ranges")
self.shot_pos_entry = FloatArrayLogEntry(
self.data_log, "Shooter: Field translation from target"
)

def translation_to_goal(self) -> Translation2d:
return (
get_goal_speaker_position().toTranslation2d()
Expand All @@ -48,11 +59,17 @@ def update_range(self) -> None:
self.range = self.translation_to_goal().norm()
self.shooter_component.set_range(self.range)

def try_jettison(self):
def try_jettison(self) -> None:
self.engage(self.preparing_to_jettison)

def log_shot(self) -> None:
translation = self.translation_to_goal()
self.shot_time_entry.append(DriverStation.getMatchTime())
self.shot_range_entry.append(self.range)
self.shot_pos_entry.append([translation.x, translation.y])

@feedback
def in_range(self):
def in_range(self) -> bool:
return self.shooter_component.is_range_in_bounds(self.range)

@state(first=True)
Expand All @@ -67,6 +84,7 @@ def aiming(self, initial_call) -> None:
and self.is_below_speed_limit()
and self.is_below_spinning_limit()
):
self.log_shot()
self.next_state(self.firing)
else:
self.aim()
Expand Down
Loading