@@ -19,6 +19,8 @@ use crate::{
1919 vision:: ball_detection:: ball_tracker:: BallTracker ,
2020} ;
2121
22+ use std:: time:: { Duration , Instant } ;
23+
2224const WALK_WITH_BALL_ANGLE : f32 = 0.3 ;
2325const ALIGN_WITH_BALL_DISTANCE : f32 = 0.3 ;
2426
@@ -42,14 +44,38 @@ fn in_set_play(
4244 gamecontroller_message : Option < Res < GameControllerMessage > > ,
4345 primary_state : Res < PrimaryState > ,
4446 player_config : Res < PlayerConfig > ,
47+ mut whistle_time : Local < Option < Instant > > ,
4548) -> bool {
4649 if let Some ( message) = gamecontroller_message {
4750 return match * primary_state {
4851 // return true if there is a set play OR we are in Playing state with a secondary time (Kick-Off)
49- PrimaryState :: Playing { .. } => {
52+ PrimaryState :: Playing {
53+ whistle_in_set : false ,
54+ } => {
55+ * whistle_time = None ;
56+
5057 ( message. set_play != SetPlay :: None || message. secondary_time != 0 )
5158 && message. kicking_team != player_config. team_number
5259 }
60+ PrimaryState :: Playing {
61+ whistle_in_set : true ,
62+ } => {
63+ if message. kicking_team == player_config. team_number {
64+ false
65+ } else if let Some ( instant) = * whistle_time {
66+ if instant. elapsed ( ) > Duration :: from_secs ( 10 ) {
67+ false
68+ } else {
69+ // Await timer
70+ true
71+ }
72+ } else {
73+ * whistle_time = Some ( Instant :: now ( ) ) ;
74+ // Await timer
75+ println ! ( "Setting whistle timer..." ) ;
76+ return true ;
77+ }
78+ }
5379 _ => false ,
5480 } ;
5581 }
0 commit comments