NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_common.h
1 // Walk and kick: Common include file
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4  // Ensure header is only included once
5 #ifndef WAK_COMMON_H
6 #define WAK_COMMON_H
7 
8 // Includes
9 #include <walk_and_kick/wak_plot.h>
10 #include <ros/console.h>
11 #include <Eigen/Core>
12 #include <Eigen/StdVector>
13 #include <vector>
14 #include <string>
15 
16 // Defines
17 #define TINC 0.040f // System iteration time (relevant for instance for velocities and accelerations)
18 #define LED_PERIOD 1.0f // Time period for the regular updates to the LED state
19 #define INVALID_DIST 100000.0f // Used to signify an invalid distance
20 
21 // Macros
22 #define TO_COUNT(time) ((int)((time)/(TINC) + 0.5f)) // This assumes for the rounding that time is always positive!
23 
24 // Walk and kick namespace
25 namespace walk_and_kick
26 {
27  // Kickoff type enumeration
28  enum KickoffType
29  {
30  KT_UNKNOWN = 0, // Unknown kickoff type
31  KT_DEFENDING, // We are defending a kickoff
32  KT_ATTACKING, // We are taking a kickoff
33  KT_DROPBALL, // We are playing a drop ball
34  KT_MANUAL, // Not a kickoff (manual start of the robot)
35  KT_COUNT,
36  KT_DEFAULT = KT_MANUAL
37  };
38  const std::string KickoffTypeName[KT_COUNT] = {
39  "Unknown",
40  "Defending",
41  "Attacking",
42  "DropBall",
43  "Manual"
44  };
45  inline bool kickoffTypeValid(int type) { return (type > KT_UNKNOWN && type < KT_COUNT); }
46  inline bool kickoffTypeValid(KickoffType type) { return kickoffTypeValid((int) type); }
47  inline const std::string& kickoffTypeName(KickoffType type) { if(kickoffTypeValid(type)) return KickoffTypeName[type]; else return KickoffTypeName[KT_UNKNOWN]; }
48 
49  // Button state enumeration
50  enum ButtonState
51  {
52  BTN_UNKNOWN = 0, // Unknown button state
53  BTN_STOP, // Stopped
54  BTN_PLAY, // Play soccer
55  BTN_GOALIE, // Play soccer and force being a goalie
56  BTN_POS, // Perform auto-positioning
57  BTN_COUNT
58  };
59  const std::string ButtonStateName[BTN_COUNT] = {
60  "Unknown Mode",
61  "Halt Mode",
62  "Play Mode",
63  "Goalie Mode",
64  "Positioning Mode"
65  };
66  inline bool buttonStateValid(int state) { return (state > BTN_UNKNOWN && state < BTN_COUNT); }
67  inline bool buttonStateValid(ButtonState state) { return buttonStateValid((int) state); }
68  inline const std::string& buttonStateName(ButtonState state) { if(buttonStateValid(state)) return ButtonStateName[state]; else return ButtonStateName[BTN_UNKNOWN]; }
69 
70  // Game command enumeration
71  enum GameCommand
72  {
73  CMD_UNKNOWN = 0, // Unknown game command
74  CMD_STOP, // The robot should be stopped no matter what
75  CMD_POS, // The robot should perform positioning no matter what
76  CMD_PLAY, // The robot should play soccer in the appropriate mode, role and state
77  CMD_COUNT
78  };
79  const std::string GameCommandName[CMD_COUNT] = {
80  "UnknownCmd",
81  "Stop",
82  "Positioning",
83  "Play"
84  };
85  inline bool gameCommandValid(int command) { return (command > CMD_UNKNOWN && command < CMD_COUNT); }
86  inline bool gameCommandValid(GameCommand command) { return gameCommandValid((int) command); }
87  inline const std::string& gameCommandName(GameCommand command) { if(gameCommandValid(command)) return GameCommandName[command]; else return GameCommandName[CMD_UNKNOWN]; }
88 
89  // Game role enumeration
90  enum GameRole
91  {
92  ROLE_UNKNOWN = 0, // Unknown game role
93  ROLE_FIELDPLAYER, // Field player for normal soccer gameplay
94  ROLE_GOALIE, // Goalie for normal soccer gameplay
95  ROLE_COUNT,
96  ROLE_DEFAULT = ROLE_FIELDPLAYER
97  };
98  const std::string GameRoleName[ROLE_COUNT] = {
99  "UnknownRole",
100  "FieldPlayer",
101  "Goalie",
102  };
103  inline bool gameRoleValid(int role) { return (role > ROLE_UNKNOWN && role < ROLE_COUNT); }
104  inline bool gameRoleValid(GameRole role) { return gameRoleValid((int) role); }
105  inline const std::string& gameRoleName(GameRole role) { if(gameRoleValid(role)) return GameRoleName[role]; else return GameRoleName[ROLE_UNKNOWN]; }
106  inline bool gameRoleIsGoalie(GameRole role) { return (role == ROLE_GOALIE); }
107  inline bool gameRoleIsFieldPlayer(GameRole role) { return (gameRoleValid(role) && !gameRoleIsGoalie(role)); }
108 
109  // Play state enumeration
110  enum PlayState
111  {
112  PS_UNKNOWN = 0, // Unknown play state
113  PS_STOP, // Generic stopped state
114  PS_TIMEOUT, // State during a timeout
115  PS_READY, // Getting ready for the kickoff (e.g. by auto-positioning)
116  PS_SET, // Stand in place and wait for the signal to begin play
117  PS_BEGIN_PLAY, // Game play has started but you are not allowed to move yet
118  PS_PLAY, // Normal game play
119  PS_COUNT
120  };
121  const std::string PlayStateName[PS_COUNT] = {
122  "UnknownPlayState",
123  "Stop",
124  "Timeout",
125  "Ready",
126  "Set",
127  "BeginPlay",
128  "Play"
129  };
130  inline bool playStateValid(int state) { return (state > PS_UNKNOWN && state < PS_COUNT); }
131  inline bool playStateValid(PlayState state) { return playStateValid((int) state); }
132  inline const std::string& playStateName(PlayState state) { if(playStateValid(state)) return PlayStateName[state]; else return PlayStateName[PS_UNKNOWN]; }
133 
134  // Dive direction enumeration
135  enum DiveDirection
136  {
137  DD_NONE = 0,
138  DD_LEFT,
139  DD_RIGHT,
140  DD_SIT,
141  DD_COUNT
142  };
143  const std::string DiveDirectionName[DD_COUNT] = {
144  "No Dive",
145  "Left Dive",
146  "Right Dive",
147  "Sit Dive"
148  };
149  inline bool diveDirectionValid(int dirn) { return (dirn >= DD_NONE && dirn < DD_COUNT); }
150  inline bool diveDirectionValid(DiveDirection dirn) { return diveDirectionValid((int) dirn); }
151  inline const std::string& diveDirectionName(DiveDirection dirn) { if(diveDirectionValid(dirn)) return DiveDirectionName[dirn]; else return DiveDirectionName[DD_NONE]; }
152 
153  // Typedefs
154  typedef Eigen::Vector2f Vec2f;
155  typedef Eigen::Vector3f Vec3f;
156  typedef std::vector<Vec2f, Eigen::aligned_allocator<Vec2f> > Vec2fArray;
157  typedef std::vector<Vec3f, Eigen::aligned_allocator<Vec3f> > Vec3fArray;
158  typedef long long int cycle_t; // Note: This should be signed and not unsigned!
159 
160  // Goal post struct
161  struct GoalPost
162  {
163  GoalPost() : vec(0.0f, 0.0f), conf(0.0f) {}
164  Vec2f vec;
165  float conf;
166  };
167  typedef std::vector<GoalPost> GoalPostList;
168 
169  // Obstacle struct
170  struct Obstacle
171  {
172  Obstacle() { reset(); }
173  void reset() { vec.setZero(); dist = 0.0f; conf = 0.0f; id = -1; }
174  bool valid() const { return (conf > 0.0f && id >= 0); }
175  void setVec(float x, float y) { vec << x, y; dist = vec.norm(); }
176  Vec2f vec;
177  float dist;
178  float conf;
179  int id;
180  };
181  typedef std::vector<Obstacle> ObstacleList;
182 }
183 
184 #endif
185 // EOF
unsigned int cycle_t
Used to count the number of executed state controller cycles.
Definition: state_controller.h:415