-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from thedropbears/add_shooter_state_machine
Add shooter state machine
- Loading branch information
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from magicbot import StateMachine, state | ||
from components.chassis import Chassis | ||
|
||
from utilities.game import get_goal_speaker_position | ||
|
||
from math import atan2 | ||
|
||
|
||
class Shooter(StateMachine): | ||
chassis: Chassis | ||
|
||
def setup(self) -> None: | ||
pass | ||
|
||
@state(first=True) | ||
def acquiring(self) -> None: | ||
# determine heading required for goal | ||
translation_to_goal = ( | ||
get_goal_speaker_position().toTranslation2d() | ||
- self.chassis.get_pose().translation() | ||
) | ||
bearing_to_speaker = atan2(translation_to_goal.y, translation_to_goal.x) | ||
# set to appropriate heading | ||
self.chassis.snap_to_heading(bearing_to_speaker) | ||
|
||
# progress state machine if within tolerance | ||
if self.chassis.at_desired_heading(): | ||
self.next_state("shooting") | ||
|
||
@state(must_finish=True) | ||
def shooting(self) -> None: | ||
# commence shooting action | ||
self.done() | ||
|
||
def shoot(self) -> None: | ||
self.engage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters