1- from typing import Optional
2-
31from bitbots_utils .utils import get_parameters_from_other_node
4- from game_controller_hl_interfaces .msg import GameState
2+ from builtin_interfaces .msg import Time as TimeMsg
3+ from game_controller_hsl_interfaces .msg import GameState
4+ from rclpy .time import Time
5+ from std_msgs .msg import Bool
56
67from bitbots_blackboard .capsules import AbstractBlackboardCapsule
78
@@ -12,33 +13,45 @@ class GameStatusCapsule(AbstractBlackboardCapsule):
1213 def __init__ (self , node , blackboard = None ):
1314 super ().__init__ (node , blackboard )
1415 self .team_id : int = get_parameters_from_other_node (self ._node , "parameter_blackboard" , ["team_id" ])["team_id" ]
16+ self .own_id : int = get_parameters_from_other_node (self ._node , "parameter_blackboard" , ["bot_id" ])["bot_id" ]
1517 self .gamestate = GameState ()
1618 self .last_update : float = 0.0
1719 self .unpenalized_time : float = 0.0
1820 self .last_goal_from_us_time = - 86400.0
1921 self .last_goal_time = - 86400.0
20- self .free_kick_kickoff_team : Optional [bool ] = None
22+ self .free_kick_kickoff_team : bool | None = None
23+ self .game_controller_stop : bool = False
24+ self .last_timestep_whistle_detected : Time | None = None
25+ # publish stopped msg for hcm
26+ self .stop_pub = node .create_publisher (Bool , "game_controller/stop_msg" , 1 )
2127
22- def get_gamestate (self ) -> int :
23- return self .gamestate .game_state
28+ def get_game_state (self ) -> int :
29+ # Init, ready, set, playing, finished
30+ return self .gamestate .main_state
2431
25- def get_secondary_state (self ) -> int :
26- return self .gamestate .secondary_state
32+ def get_game_phase (self ) -> int :
33+ # Timeout, Normal, Extratime, Penaltyshoot
34+ return self .gamestate .game_phase
2735
28- def get_secondary_state_mode (self ) -> int :
29- return self .gamestate .secondary_state_mode
36+ def get_set_play (self ) -> int :
37+ # None, Direct Freekick, Indirect Freekick, Penalty, Throw in, Goalkick, Cornerkick,
38+ return self .gamestate .set_play
3039
3140 def get_secondary_team (self ) -> int :
32- return self .gamestate .secondary_state_team
41+ # Team ID, wer in set Play den Ball hat
42+ return self .gamestate .kicking_team
3343
3444 def has_kickoff (self ) -> bool :
35- return self .gamestate .has_kick_off
45+ # vegelcih mit eigener Teamnummer
46+ return self .gamestate .kicking_team == self .team_id
47+
48+ def is_stopped (self ) -> bool :
49+ return self .gamestate .stopped
3650
3751 def has_penalty_kick (self ) -> bool :
3852 return (
39- self .gamestate .secondary_state == GameState .STATE_PENALTYKICK
40- or self .gamestate .secondary_state == GameState .STATE_PENALTYSHOOT
41- ) and self .gamestate ._secondary_state_team == self .team_id
53+ self .gamestate .set_play == GameState .SET_PLAY_PENALTY_KICK and self .gamestate .kicking_team == self .team_id
54+ )
4255
4356 def get_our_goals (self ) -> int :
4457 return self .gamestate .own_score
@@ -55,26 +68,17 @@ def get_seconds_since_any_goal(self) -> float:
5568 def get_seconds_remaining (self ) -> float :
5669 # Time from the message minus time passed since receiving it
5770 return max (
58- self .gamestate .seconds_remaining - (self ._node .get_clock ().now ().nanoseconds / 1e9 - self .last_update ), 0.0
71+ self .gamestate .secs_remaining - (self ._node .get_clock ().now ().nanoseconds / 1e9 - self .last_update ), 0.0
5972 )
6073
6174 def get_secondary_seconds_remaining (self ) -> float :
6275 """Seconds remaining for things like kickoff"""
6376 # Time from the message minus time passed since receiving it
6477 return max (
65- self .gamestate .secondary_seconds_remaining
66- - (self ._node .get_clock ().now ().nanoseconds / 1e9 - self .last_update ),
78+ self .gamestate .secondary_time - (self ._node .get_clock ().now ().nanoseconds / 1e9 - self .last_update ),
6779 0.0 ,
6880 )
6981
70- def get_seconds_since_last_drop_ball (self ) -> Optional [float ]:
71- """Returns the seconds since the last drop in"""
72- if self .gamestate .drop_in_time == - 1 :
73- return None
74- else :
75- # Time from the message plus seconds passed since receiving it
76- return self .gamestate .drop_in_time + (self ._node .get_clock ().now ().nanoseconds / 1e9 - self .last_update )
77-
7882 def get_seconds_since_unpenalized (self ) -> float :
7983 return self ._node .get_clock ().now ().nanoseconds / 1e9 - self .unpenalized_time
8084
@@ -87,9 +91,6 @@ def received_gamestate(self) -> bool:
8791 def get_team_id (self ) -> int :
8892 return self .team_id
8993
90- def get_red_cards (self ) -> int :
91- return self .gamestate .team_mates_with_red_card
92-
9394 def gamestate_callback (self , gamestate_msg : GameState ) -> None :
9495 if self .gamestate .penalized and not gamestate_msg .penalized :
9596 self .unpenalized_time = self ._node .get_clock ().now ().nanoseconds / 1e9
@@ -101,21 +102,32 @@ def gamestate_callback(self, gamestate_msg: GameState) -> None:
101102 if gamestate_msg .rival_score > self .gamestate .rival_score :
102103 self .last_goal_time = self ._node .get_clock ().now ().nanoseconds / 1e9
103104
105+ self .game_controller_stop = gamestate_msg .stopped
106+
107+ self .stop_pub .publish (Bool (data = self .game_controller_stop ))
108+
109+ """Anstoß im Falle von Overtime jetzt erstmal nicht genauer geregelt
104110 if (
105- gamestate_msg .secondary_state_mode == 2
106- and self .gamestate .secondary_state_mode != 2
107- and gamestate_msg .game_state == GameState .GAMESTATE_PLAYING
111+ gamestate_msg.main_state == GameState.STATE_SET
112+ and self.gamestate.setPlay != 2
113+ and gamestate_msg.state == GameState.STATE_PLAYING
108114 ):
109115 # secondary action is now executed but we will not see this in the new messages.
110116 # it will look like a normal kick off, but we need to remember that this is some sort of free kick
111117 # we set the kickoff value accordingly, then we will not be allowed to move if it is a kick for the others
112- self .free_kick_kickoff_team = gamestate_msg .secondary_state_team
118+ self.free_kick_kickoff_team = gamestate_msg.kicking_team
119+
120+ if gamestate_msg.set_play != 2 and gamestate_msg.secondary_time == 0:
121+ self.free_kick_kickoff_team = gamestate_msg.kicking_team
113122
114- if gamestate_msg .secondary_state_mode != 2 and gamestate_msg .secondary_seconds_remaining == 0 :
123+ if gamestate_msg.set_play != 2 and gamestate_msg.secondary_time == 0:
115124 self.free_kick_kickoff_team = None
116125
117126 if self.free_kick_kickoff_team is not None:
118127 gamestate_msg.has_kick_off = self.free_kick_kickoff_team == self.team_id
119-
128+ """
120129 self .last_update = self ._node .get_clock ().now ().nanoseconds / 1e9
121130 self .gamestate = gamestate_msg
131+
132+ def whistle_detection_callback (self , msg : TimeMsg ) -> None :
133+ self .last_timestep_whistle_detected = Time .from_msg (msg )
0 commit comments