NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_beh_manager.h
1 // Walk and kick: Class for management of the behaviour states
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4  // Ensure header is only included once
5 #ifndef WAK_BEH_MANAGER_H
6 #define WAK_BEH_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_beh_shared.h>
17 #include <walk_and_kick/wak_beh_state.h>
18 #include <walk_and_kick/wak_beh_state_combined.h>
19 
20 // Includes - Behaviour states
21 #include <walk_and_kick/beh_states/beh_unknown_state.h>
22 #include <walk_and_kick/beh_states/beh_stopped.h>
23 #include <walk_and_kick/beh_states/beh_panic_attack.h>
24 #include <walk_and_kick/beh_states/beh_search_for_ball.h>
25 #include <walk_and_kick/beh_states/beh_go_behind_ball.h>
26 #include <walk_and_kick/beh_states/beh_dribble_ball.h>
27 #include <walk_and_kick/beh_states/beh_kick_ball.h>
28 #include <walk_and_kick/beh_states/beh_dive_for_ball.h>
29 #include <walk_and_kick/beh_states/gaze_beh_look_around.h>
30 #include <walk_and_kick/beh_states/gaze_beh_look_at_ball.h>
31 #include <walk_and_kick/beh_states/gaze_beh_look_down.h>
32 #include <walk_and_kick/beh_states/gaze_beh_look_for_ball.h>
33 #include <walk_and_kick/beh_states/gaze_beh_look_left_right.h>
34 #include <walk_and_kick/beh_states/walk_beh_walk_to_pose.h>
35 
36 // Walk and kick namespace
37 namespace walk_and_kick
38 {
39  // Combined behaviour states
40  typedef WAKBehStateCombined<WalkBehWalkToPose, GazeBehLookAround> BehWalkToPoseLookAround;
41  typedef WAKBehStateCombined<WalkBehWalkToPose, GazeBehLookAtBall> BehWalkToPoseLookAtBall;
42  typedef WAKBehStateCombined<WalkBehWalkToPose, GazeBehLookForBall> BehWalkToPoseLookForBall;
43  typedef WAKBehStateCombined<WalkBehWalkToPose, GazeBehLookLeftRight> BehWalkToPoseLookLeftRight;
44 
51  {
52  public:
53  // Behaviour state ID enumeration
54  enum BehStateID
55  {
56  BS_UNKNOWN = 0,
57  BS_STOPPED, // Abbreviation: STP
58  BS_PANIC_ATTACK, // Abbreviation: PA
59  BS_SEARCH_FOR_BALL, // Abbreviation: SFB
60  BS_GO_BEHIND_BALL, // Abbreviation: GBB
61  BS_DRIBBLE_BALL, // Abbreviation: DB
62  BS_KICK_BALL, // Abbreviation: KB
63  BS_DIVE_FOR_BALL, // Abbreviation: DFB
64  BS_LOOK_AROUND, // Abbreviation: LA
65  BS_LOOK_AT_BALL, // Abbreviation: LAB
66  BS_LOOK_DOWN, // Abbreviation: LD
67  BS_LOOK_FOR_BALL, // Abbreviation: LFB
68  BS_LOOK_LEFT_RIGHT, // Abbreviation: LLR
69  BS_WALK_TO_POSE, // Abbreviation: WTP
70  BS_WALK_TO_POSE_LOOK_AROUND, // Abbreviation: WTPLA
71  BS_WALK_TO_POSE_LOOK_AT_BALL, // Abbreviation: WTPLAB
72  BS_WALK_TO_POSE_LOOK_FOR_BALL, // Abbreviation: WTPLFB
73  BS_WALK_TO_POSE_LOOK_LEFT_RIGHT, // Abbreviation: WTPLLR
74  BS_COUNT
75  };
76  static bool behStateValid(int BSI) { return (BSI > BS_UNKNOWN && BSI < BS_COUNT); }
77  static bool behStateValid(BehStateID BSI) { return behStateValid((int) BSI); }
78  static const std::string& behStateName(BehStateID BSI) { return behStateName((int) BSI); }
79  static const std::string& behStateName(int BSI) { if(behStateValid(BSI)) return BehStateName[BSI]; else return BehStateName[BS_UNKNOWN]; }
80  private:
81  static const std::string BehStateName[BS_COUNT];
82 
83  public:
84  // Constructor/destructor
85  WAKBehManager(WAKConfig& config, const SensorVars& SV, const WAKRosInterface& RI, const WAKGameShared& WGS);
86  virtual ~WAKBehManager();
87 
88  // Reset functions
89  void reset(); // Resets all normal variables, the state machine and all updated variables
90  void resetVars(); // Resets all normal variables
91  void resetStateMachine(); // Resets all normal variables and the state machine
92 
93  // Behaviour state registration function
94  void registerState(WAKBehState* state, int ID, const std::string& name);
95 
96  // Constant access to behaviour states
97  const WAKBehState* currentState() const { return m_curState; }
98  const BehStopped* stoppedState() const { return Stopped; }
99 
100  // Get functions
101  const WAKBehShared& getWBS() const { return WBS; }
102  const ActuatorVars& AV() const { return m_AV; }
103  const ActuatorVars& lastAV() const { return m_lastAV; }
104  cycle_t wakCycle() const { return m_wakCycle; }
105  cycle_t stateCycle() const { return m_stateCycle; }
106  BAType ballAction() const { return m_ballAction; }
107 
108  // Update function
109  void updateManager(const GameVars& GV, cycle_t wakCycle);
110 
111  // Execute function
112  void execute();
113 
114  private:
115  // State decision function
116  WAKBehState* decideState();
117 
118  // Config parameters
119  WAKConfig& config;
120 
121  // Sensor variables
122  const SensorVars& SV;
123 
124  // ROS interface
125  const WAKRosInterface& RI;
126 
127  // Shared game variables
128  const WAKGameShared& WGS;
129 
130  // Shared behaviour variables
131  WAKBehShared WBS;
132 
133  // Behaviour states
134  BehUnknownState* UnknownState;
135  BehStopped* Stopped;
136  BehPanicAttack* PanicAttack;
137  BehSearchForBall* SearchForBall;
138  BehGoBehindBall* GoBehindBall;
139  BehDribbleBall* DribbleBall;
140  BehKickBall* KickBall;
141  BehDiveForBall* DiveForBall;
142  GazeBehLookAround* LookAround;
143  GazeBehLookAtBall* LookAtBall;
144  GazeBehLookDown* LookDown;
145  GazeBehLookForBall* LookForBall;
146  GazeBehLookLeftRight* LookLeftRight;
147  WalkBehWalkToPose* WalkToPose;
148  BehWalkToPoseLookAround* WalkToPoseLookAround;
149  BehWalkToPoseLookAtBall* WalkToPoseLookAtBall;
150  BehWalkToPoseLookForBall* WalkToPoseLookForBall;
151  BehWalkToPoseLookLeftRight* WalkToPoseLookLeftRight;
152 
153  // Current behaviour state
154  WAKBehState* m_curState;
155 
156  // Behaviour state retrieval
157  WAKBehState* stateForID(int ID);
158  std::string stateNameForID(int ID);
159  std::map<int, WAKBehState*> m_stateMap;
160  std::map<int, std::string> m_stateNameMap;
161 
162  // Game variable inputs
163  GameVars m_GV;
164 
165  // Actuator variable outputs
166  ActuatorVars m_AV;
167  ActuatorVars m_lastAV;
168 
169  // Decide state variables
170  BAType m_ballAction;
171  TheWorm m_kickWorm;
172  TheWorm m_dribbleWorm;
173  TheWorm m_stillDribbleWorm;
174  bool m_allowBreakDribble;
175 
176  // Walking target variables
177  bool haveWalkingTarget() const { return m_walkingTargetValid; }
178  Vec2f getWalkingTarget() const { return m_walkingTarget; }
179  float getWalkingTargetTol() const { return m_walkingTargetTol; }
180  void setWalkingTarget(const Vec2f& target, float tol = -1.0f) { m_walkingTarget = target; m_walkingTargetTol = tol; m_walkingTargetValid = true; }
181  void setWalkingTargetTol(float tol) { m_walkingTargetTol = tol; }
182  void invalidateWalkingTarget() { m_walkingTargetValid = false; RI.MM->WalkingTarget.setColor(1.0, 0.0, 0.0); RI.MM->WalkingTargetTol.setColor(1.0, 0.0, 0.0); }
183  Vec2f m_walkingTarget;
184  float m_walkingTargetTol;
185  bool m_walkingTargetValid;
186 
187  // Cycle numbers
188  cycle_t m_wakCycle;
189  cycle_t m_stateCycle;
190 
191  // Friend classes
192  friend class WalkAndKick;
193  friend class WAKBehShared;
194  };
195 }
196 
197 #endif
198 // EOF
Configuration struct for the walk and kick node.
Definition: wak_config.h:20
A walk and kick walk behaviour state that makes the robot walk to a desired target pose on the field...
Definition: walk_beh_walk_to_pose.h:19
A walk and kick behaviour state that kicks the ball towards a target.
Definition: beh_kick_ball.h:20
A walk and kick gaze behaviour state that looks at the ball (and does not move the head from the last...
Definition: gaze_beh_look_at_ball.h:19
A walk and kick gaze behaviour state that looks left and right.
Definition: gaze_beh_look_left_right.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 class that shares the required walk and kick variables amongst the game state classes.
Definition: wak_game_shared.h:31
A walk and kick behaviour state that lines up the robot with the ball and a target.
Definition: beh_go_behind_ball.h:20
A class that manages and executes the walk and kick behaviour states.
Definition: wak_beh_manager.h:50
A walk and kick behaviour state that simply tells the robot to stop in place.
Definition: beh_stopped.h:19
The main walk and kick behaviour class.
Definition: walk_and_kick.h:34
A walk and kick behaviour state that induces a panic attack and stops the robot still.
Definition: beh_panic_attack.h:19
A walk and kick behaviour state that combines two others (which are assumed to operate independently)...
Definition: wak_beh_state_combined.h:22
A walk and kick behaviour state that stands in for an unknown state or ID.
Definition: beh_unknown_state.h:19
A walk and kick behaviour state that dribbles the ball towards a target.
Definition: beh_dribble_ball.h:20
A walk and kick gaze behaviour state that looks around.
Definition: gaze_beh_look_around.h:19
The base class for all walk and kick behaviour states.
Definition: wak_beh_state.h:27
A walk and kick gaze behaviour state that looks down.
Definition: gaze_beh_look_down.h:19
A walk and kick gaze behaviour state that looks for the ball.
Definition: gaze_beh_look_for_ball.h:20
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 class that shares the required walk and kick variables amongst the behaviour state classes...
Definition: wak_beh_shared.h:48
A walk and kick behaviour state that searches for the ball.
Definition: beh_search_for_ball.h:21
A walk and kick behaviour state that dives for the ball.
Definition: beh_dive_for_ball.h:20
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
An interface class for encapsulating all of the data that the walk and kick behaviour states should c...
Definition: wak_actuator_vars.h:22