@@ -22,7 +22,7 @@ use crate::{
2222 vision:: ball_detection:: ball_tracker:: BallTracker ,
2323} ;
2424
25- use std:: time:: Duration ;
25+ use std:: time:: { Duration , Instant } ;
2626
2727const WALK_WITH_BALL_ANGLE : f32 = 0.3 ;
2828const ALIGN_WITH_BALL_DISTANCE : f32 = 0.3 ;
@@ -47,14 +47,37 @@ fn in_set_play(
4747 gamecontroller_message : Option < Res < GameControllerMessage > > ,
4848 primary_state : Res < PrimaryState > ,
4949 player_config : Res < PlayerConfig > ,
50+ mut whistle_time : Local < Option < Instant > > ,
5051) -> bool {
5152 if let Some ( message) = gamecontroller_message {
5253 return match * primary_state {
5354 // return true if there is a set play OR we are in Playing state with a secondary time (Kick-Off)
54- PrimaryState :: Playing { .. } => {
55+ PrimaryState :: Playing {
56+ whistle_in_set : false ,
57+ } => {
58+ * whistle_time = None ;
59+
5560 ( message. set_play != SetPlay :: None || message. secondary_time != 0 )
5661 && message. kicking_team != player_config. team_number
5762 }
63+ PrimaryState :: Playing {
64+ whistle_in_set : true ,
65+ } => {
66+ if message. kicking_team == player_config. team_number {
67+ false
68+ } else if let Some ( instant) = * whistle_time {
69+ if instant. elapsed ( ) > Duration :: from_secs ( 10 ) {
70+ false
71+ } else {
72+ // Await timer
73+ true
74+ }
75+ } else {
76+ * whistle_time = Some ( Instant :: now ( ) ) ;
77+ // Await timer
78+ return true ;
79+ }
80+ }
5881 _ => false ,
5982 } ;
6083 }
0 commit comments