NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_gc_vars.h
1 // Walk and kick: Game controller variables
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4  // Ensure header is only included once
5 #ifndef WAK_GC_VARS_H
6 #define WAK_GC_VARS_H
7 
8 // Includes
9 #include <walk_and_kick/wak_common.h>
10 #include <walk_and_kick/wak_config.h>
11 #include <rcup_game_controller/GCData.h>
12 
13 // Defines
14 #define DEFAULT_GCFRESH_TIME 5.0f
15 #define DEFAULT_SMOOTHING_TIME 1.0f
16 #define DEFAULT_TIMEOUT_KICKOFF_TYPE 11.0f
17 
18 // Walk and kick namespace
19 namespace walk_and_kick
20 {
21  // Class declarations
22  class WAKMarkerMan;
23 
29  class GCVars
30  {
31  public:
32  //
33  // General
34  //
35 
36  // Constructor
37  GCVars(WAKConfig* config, plot_msgs::PlotManagerFS* PM, WAKMarkerMan* MM);
38 
39  // Config parameters
40  WAKConfig* const config;
41 
42  // Update function
43  bool update(const rcup_game_controller::GCData& data, const ros::Time& now); // Returns whether the game controller base data is fresh
44 
45  //
46  // Enumerations
47  //
48 
49  // Game state enumeration
50  enum GameState
51  {
52  GS_INITIAL = rcup_game_controller::GCData::STATE_INITIAL, // Initial state of undetermined duration, active at all times prior to the start of the game
53  GS_READY = rcup_game_controller::GCData::STATE_READY, // Ready state of nominal duration 30 seconds (counted down by the secondary time), during which the robots should position themselves to be ready for the start of play
54  GS_SET = rcup_game_controller::GCData::STATE_SET, // Set state of undetermined duration, at which point the robots should stop where they are and wait for the signal to start playing
55  GS_PLAYING = rcup_game_controller::GCData::STATE_PLAYING, // Playing state of certain nominal duration (counted down by the time remaining, with the first 10 seconds until the ball is definitely in play being counted down by the secondary time), during which the robots should play soccer and try to score as many goals as possible
56  GS_FINISHED = rcup_game_controller::GCData::STATE_FINISHED // Final state of undetermined duration, active at all times after the end of the game
57  };
58 
59  // Game phase enumeration
60  enum GamePhase
61  {
62  GP_NORMAL = rcup_game_controller::GCData::SECSTATE_NORMAL, // Normal soccer gameplay, playing state has nominal duration 10 minutes
63  GP_PENALTY = rcup_game_controller::GCData::SECSTATE_PENALTYSHOOT, // Playing state has nominal duration 1 minute, the ready state is skipped and initial passes directly to set, no secondary time countdown of 10 seconds until the ball is in play as the ball is always immediately in play
64  GP_OVERTIME = rcup_game_controller::GCData::SECSTATE_OVERTIME, // Playing state has nominal duration 5 minutes, the same as SECSTATE_NORMAL in all other aspects
65  GP_TIMEOUT = rcup_game_controller::GCData::SECSTATE_TIMEOUT // Should only happen in conjunction with a game state of STATE_INITIAL, and involves no gameplay
66  };
67 
68  // Penalty state enumeration
69  enum PenaltyState
70  {
71  PS_NONE = rcup_game_controller::GCRobotInfo::PENALTY_NONE, // Normal unpenalised robot state
72  PS_BALL_MANIPULATION = rcup_game_controller::GCRobotInfo::PENALTY_BALL_MANIPULATION, // Ball manipulation penalty
73  PS_PHYSICAL_CONTACT = rcup_game_controller::GCRobotInfo::PENALTY_PHYSICAL_CONTACT, // Physical contact penalty
74  PS_ILLEGAL_ATTACK = rcup_game_controller::GCRobotInfo::PENALTY_ILLEGAL_ATTACK, // Illegal attack penalty
75  PS_ILLEGAL_DEFENSE = rcup_game_controller::GCRobotInfo::PENALTY_ILLEGAL_DEFENSE, // Illegal defense penalty
76  PS_REQ_PICKUP = rcup_game_controller::GCRobotInfo::PENALTY_REQUEST_FOR_PICKUP, // Robot has been picked up
77  PS_REQ_SERVICE = rcup_game_controller::GCRobotInfo::PENALTY_REQUEST_FOR_SERVICE, // Robot is being serviced
78  PS_REQ_PICKUP_SERVICE = rcup_game_controller::GCRobotInfo::PENALTY_REQUEST_FOR_PICKUP_2_SERVICE, // Robot was picked up and is now additionally being serviced
79  PS_ON_THE_BENCH = rcup_game_controller::GCRobotInfo::PENALTY_SUBSTITUTE, // The robot is a substitute and not an active member of the game
80  PS_MANUAL = rcup_game_controller::GCRobotInfo::PENALTY_MANUAL // The robot itself manually requested a penalisation
81  };
82 
83  //
84  // Classes
85  //
86 
87  // Team state class
88  class TeamState
89  {
90  public:
91  int teamNumber; // Team number
92  bool isCyan; // Team colour
93  unsigned int score; // Number of goals scored
94  unsigned int numNotOnBench; // Number of players not on the bench
95  unsigned int numPenalised; // Number of players not on the bench that are penalised
96  unsigned int numPlaying; // Number of players without any penalisation
97  };
98 
99  // Smooth time class (Note: This class assumes that the raw time is ticking down, *not* up)
100  class SmoothTime
101  {
102  public:
103  // Constructor
104  explicit SmoothTime(WAKConfig* config) : config(config) { reset(ros::Time()); }
105 
106  // Reset function
107  void reset(const ros::Time& now);
108 
109  // Set functions (needs to be called in every cycle or the smoothed time estimate is not updated)
110  void setValue(int timeRemaining, const ros::Time& timestamp, const ros::Time& now);
111 
112  // Config parameters
113  WAKConfig* const config;
114 
115  // Time data variables
116  int raw; // The last set raw time data value
117  float smooth; // The last calculated smoothed time data value
118  ros::Time timestamp; // The timestamp used in the last update of the time data (i.e. the value of timestamp in the last call to setValue(), which is *not* necessarily the ros::Time::now() of the last update at all!)
119  ros::Time elapseTime; // The absolute time at which the raw/smooth values are expected to hit zero (can be in the future or the past)
120 
121  private:
122  // Internal variables
123  ros::Time m_rawTimestamp;
124  };
125 
126  //
127  // Data variables
128  //
129 
130  // Message information
131  unsigned int seqID;
132  ros::Time stampBase;
133  ros::Time stampExtra;
134  bool extraOutOfDate;
135 
136  // Game state
137  unsigned int playersPerTeam;
138  GameState gameState;
139  GamePhase gamePhase;
140  KickoffType kickoffType;
141  bool isPenaltyTaker;
142  SmoothTime timeRemaining;
143  SmoothTime secondaryTime; // Extra: This variable has timestamp stampExtra
144  SmoothTime timeToBallInPlay; // Extra: This variable has timestamp stampExtra
145 
146  // Robot state
147  PenaltyState ownPenaltyState;
148  SmoothTime ownPenaltyTimeRemaining;
149  bool ownIsPenalised;
150  bool ownIsOnBench;
151  bool ownIsPlaying;
152 
153  // Team states
154  TeamState ownTeam;
155  TeamState oppTeam;
156 
157  //
158  // Helper functions
159  //
160 
161  // Data is fresh function
162  bool baseDataIsFresh(const ros::Time& now) const { return (!stampBase.isZero() && (now - stampBase).toSec() <= (config ? config->gcFreshTime() : DEFAULT_GCFRESH_TIME)); }
163  bool extraDataIsFresh(const ros::Time& now) const { return (!extraOutOfDate && !stampExtra.isZero() && (now - stampExtra).toSec() <= (config ? config->gcFreshTime() : DEFAULT_GCFRESH_TIME)); }
164 
165  private:
166  // Plot manager
167  plot_msgs::PlotManagerFS* PM;
168 
169  // Marker manager
170  WAKMarkerMan* MM;
171 
172  // Update team state function
173  static void updateTeamState(TeamState& team, const rcup_game_controller::GCTeamInfo& data);
174 
175  // Internal variables
176  ros::Time m_stampStartPlaying;
177  };
178 }
179 
180 #endif
181 // EOF
Configuration struct for the walk and kick node.
Definition: wak_config.h:20
Visualisation marker manager for the walk and kick node.
Definition: wak_vis.h:21
A class that encapsulates all of the game controller input data to the walk and kick node...
Definition: wak_gc_vars.h:29