NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_game_manager.h
1 // Walk and kick: Class for management of the game states
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4  // Ensure header is only included once
5 #ifndef WAK_GAME_MANAGER_H
6 #define WAK_GAME_MANAGER_H
7 
8 // Includes - General
9 #include <walk_and_kick/wak_common.h>
10 #include <walk_and_kick/wak_config.h>
11 #include <walk_and_kick/wak_game_vars.h>
12 #include <walk_and_kick/wak_sensor_vars.h>
13 #include <walk_and_kick/wak_actuator_vars.h>
14 #include <walk_and_kick/wak_ros_interface.h>
15 #include <walk_and_kick/wak_game_shared.h>
16 #include <walk_and_kick/wak_game_state.h>
17 
18 // Includes - Game states
19 #include <walk_and_kick/game_states/game_unknown_state.h>
20 #include <walk_and_kick/game_states/game_stopped.h>
21 #include <walk_and_kick/game_states/game_panic_attack.h>
22 #include <walk_and_kick/game_states/game_positioning.h>
23 #include <walk_and_kick/game_states/game_gaze_for_ball.h>
24 #include <walk_and_kick/game_states/game_wait_for_ball_in_play.h>
25 #include <walk_and_kick/game_states/game_default_ball_handling.h>
26 #include <walk_and_kick/game_states/game_penalty_ball_handling.h>
27 #include <walk_and_kick/game_states/game_default_goalie.h>
28 #include <walk_and_kick/game_states/game_penalty_goalie.h>
29 
30 // Walk and kick namespace
31 namespace walk_and_kick
32 {
39  {
40  public:
41  // Game state ID enumeration
42  enum GameStateID
43  {
44  GS_UNKNOWN = 0,
45  GS_STOPPED, // Abbreviation: STP
46  GS_PANIC_ATTACK, // Abbreviation: PA
47  GS_POSITIONING, // Abbreviation: POS
48  GS_GAZE_FOR_BALL, // Abbreviation: GFB
49  GS_WAIT_FOR_BALL_IN_PLAY, // Abbreviation: WFBIP
50  GS_DEFAULT_BALL_HANDLING, // Abbreviation: DBH
51  GS_PENALTY_BALL_HANDLING, // Abbreviation: PBH
52  GS_DEFAULT_GOALIE, // Abbreviation: DG
53  GS_PENALTY_GOALIE, // Abbreviation: PG
54  GS_COUNT
55  };
56  static bool gameStateValid(int GSI) { return (GSI > GS_UNKNOWN && GSI < GS_COUNT); }
57  static bool gameStateValid(GameStateID GSI) { return gameStateValid((int) GSI); }
58  static const std::string& gameStateName(GameStateID GSI) { return gameStateName((int) GSI); }
59  static const std::string& gameStateName(int GSI) { if(gameStateValid(GSI)) return GameStateName[GSI]; else return GameStateName[GS_UNKNOWN]; }
60  private:
61  static const std::string GameStateName[GS_COUNT];
62 
63  public:
64  // Constructor
65  WAKGameManager(WAKConfig& config, const SensorVars& SV, const WAKRosInterface& RI);
66  virtual ~WAKGameManager();
67 
68  // Reset functions
69  void reset(); // Resets all normal variables, the state machine and all updated variables
70  void resetVars(); // Resets all normal variables
71  void resetStateMachine(); // Resets all normal variables and the state machine
72 
73  // Game state registration function
74  void registerState(WAKGameState* state, int ID, const std::string& name);
75 
76  // Constant access to game states
77  const WAKGameState* currentState() const { return m_curState; }
78  const GameStopped* stoppedState() const { return Stopped; }
79 
80  // Get functions
81  const WAKGameShared& getWGS() const { return WGS; }
82  const GameVars& GV() const { return m_GV; }
83  const GameVars& lastGV() const { return m_lastGV; }
84  cycle_t wakCycle() const { return m_wakCycle; }
85  cycle_t stateCycle() const { return m_stateCycle; }
86 
87  // Update function
88  void updateManager(cycle_t wakCycle);
89 
90  // Execute function
91  void execute();
92 
93  private:
94  // State decision function
95  WAKGameState* decideState();
96 
97  // Config parameters
98  WAKConfig& config;
99 
100  // Sensor variables
101  const SensorVars& SV;
102 
103  // ROS interface
104  const WAKRosInterface& RI;
105 
106  // Shared game variables
107  WAKGameShared WGS;
108 
109  // Game states
110  GameUnknownState* UnknownState;
111  GameStopped* Stopped;
112  GamePanicAttack* PanicAttack;
113  GamePositioning* Positioning;
114  GameGazeForBall* GazeForBall;
115  GameWaitForBallInPlay* WaitForBallInPlay;
116  GameDefaultBallHandling* DefaultBallHandling;
117  GamePenaltyBallHandling* PenaltyBallHandling;
118  GameDefaultGoalie* DefaultGoalie;
119  GamePenaltyGoalie* PenaltyGoalie;
120 
121  // Current game state
122  WAKGameState* m_curState;
123 
124  // Game state retrieval
125  WAKGameState* stateForID(int ID);
126  std::string stateNameForID(int ID);
127  std::map<int, WAKGameState*> m_stateMap;
128  std::map<int, std::string> m_stateNameMap;
129 
130  // Game variable outputs
131  GameVars m_GV;
132  GameVars m_lastGV;
133 
134  // Decide state variables
135  TheWorm m_poseLegalWorm;
136  bool m_poseLegal;
137 
138  // Cycle numbers
139  cycle_t m_wakCycle;
140  cycle_t m_stateCycle;
141 
142  // Miscellaneous variables
143  PlayState m_lastPlayState;
144  bool m_stateIsNew;
145 
146  // Friend classes
147  friend class WalkAndKick;
148  friend class WAKGameShared;
149  };
150 }
151 
152 #endif
153 // EOF
Configuration struct for the walk and kick node.
Definition: wak_config.h:20
A walk and kick game state that forces the robot to the stopped behaviour state.
Definition: game_stopped.h:19
A walk and kick game state that implements default goalie behaviours for playing soccer.
Definition: game_default_goalie.h:20
A walk and kick game state that waits for the ball to be in play.
Definition: game_wait_for_ball_in_play.h:19
A walk and kick game state that implements goalie behaviours for defending a penalty kick...
Definition: game_penalty_goalie.h:19
An interface class for encapsulating all of the ROS input data to the walk and kick node...
Definition: wak_sensor_vars.h:29
A walk and kick game state that implements ball handling for taking a penalty kick.
Definition: game_penalty_ball_handling.h:19
A class that shares the required walk and kick variables amongst the game state classes.
Definition: wak_game_shared.h:31
A walk and kick game state that implements default ball handling for playing soccer.
Definition: game_default_ball_handling.h:19
The main walk and kick behaviour class.
Definition: walk_and_kick.h:34
The base class for all walk and kick game states.
Definition: wak_game_state.h:26
A walk and kick game state that forces the robot to the positioning behaviour state.
Definition: game_positioning.h:20
A walk and kick game state that induces a panic attack.
Definition: game_panic_attack.h:19
A class that manages and executes the walk and kick game states.
Definition: wak_game_manager.h:38
A walk and kick game state that stands in for an unknown state or ID.
Definition: game_unknown_state.h:19
An interface class for encapsulating all of the data that the walk and kick game states should comman...
Definition: wak_game_vars.h:21
A walk and kick game state that makes the robot look for the ball by gaze only.
Definition: game_gaze_for_ball.h:19
An interface class between the walk and kick and ROS worlds.
Definition: wak_ros_interface.h:54
A class that implements the worm, for making a live decision between two opposites.
Definition: wak_utils.h:83