NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_sensor_vars.h
1 // Walk and kick: Sensor variables
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4  // Ensure header is only included once
5 #ifndef WAK_SENSOR_VARS_H
6 #define WAK_SENSOR_VARS_H
7 
8 // Includes
9 #include <walk_and_kick/wak_common.h>
10 #include <walk_and_kick/wak_config.h>
11 #include <walk_and_kick/wak_ros_interface.h>
12 #include <walk_and_kick/wak_gc_vars.h>
13 #include <walk_and_kick/wak_tc_vars.h>
14 #include <walk_and_kick/wak_utils.h>
15 #include <rc_utils/math_funcs.h>
16 #include <rc_utils/ros_time.h>
17 
18 // Walk and kick namespace
19 namespace walk_and_kick
20 {
29  class SensorVars
30  {
31  public:
32  //
33  // General
34  //
35 
36  // Constructor
37  SensorVars(WAKConfig& config, WAKRosInterface& RI);
38 
39  // Config parameters
40  WAKConfig& config;
41 
42  // Field dimensions
43  const FieldDimensions field;
44 
45  // Update function
46  void update(const ros::Time& now);
47 
48  //
49  // Sensor variables
50  //
51 
52  // Current cycle ROS time
53  ros::Time now;
54 
55  // Robot state variables
56  float timeStanding; // The duration for which the robot has been in the standing state (zero if not standing right now)
57 
58  // Game controller variables
59  GCVars GC; // Note: All uses of this variable should be preceded by checking listenToGC
60  bool GCDataFresh; // Boolean flag whether the game controller base data is fresh
61  bool GCExtraDataFresh; // Boolean flag whether the game controller extra data is fresh
62  bool listenToGC; // Boolean flag whether the robot should listen to the game controller
63 
64  // Configuration variables
65  bool isPenaltyShoot; // Boolean flag whether the game is currently a penalty shootout, as opposed to normal soccer gameplay
66  bool isPenaltyTaker; // Boolean flag whether, assuming the game is a penalty shootout, we are the attacker
67  KickoffType kickoffType; // Kickoff type (e.g. KT_ATTACK, KT_DEFEND, KT_DROPBALL, KT_MANUAL)
68  bool playOnYellow; // Boolean flag whether the robot should play on the positive yellow goal
69  int goalSign; // Sign of the goal the robot should play on (+1 = Positive yellow goal, -1 = Negative blue goal)
70  bool playAsCyan; // Boolean flag whether the robot is playing as the cyan team
71 
72  // Play state variables
73  GameCommand gameCommand; // Game command (e.g. CMD_PLAY, CMD_STOP, CMD_POSE)
74  bool gameCommandIsNew; // Boolean flag whether the game command is new in this cycle
75  GameRole gameRole; // Game role (e.g. ROLE_FIELDPLAYER, ROLE_GOALIE)
76  PlayState playState; // Play state (e.g. PS_STOP, PS_READY, PS_SET, PS_BEGIN_PLAY, PS_PLAY)
77  bool playStateIsNew; // Boolean flag whether the play state is new in this cycle (true also for example if the play state didn't change, but the game command is new)
78  float timePlaying; // Time since the play state was last *not* PS_BEGIN_PLAY or PS_PLAY
79 
80  // Localisation variables
81  float compassHeading; // Heading of the robot measured by the compass in the range (-pi,pi] (0 is towards the positive yellow goal and CCW from there is positive)
82  float robotPoseConf; // Current confidence of the robot's estimated position on the field (always current)
83  bool haveRobotPose; // Boolean flag whether we are currently localised (always current)
84  bool robotPoseIsNew; // Boolean flag whether haveRobotPose turned from false to true in this cycle (always current)
85  float robotPoseTimeAgo; // Time since the robot pose was last valid (last valid)
86  float robotPoseDur; // Duration for which the robot has been/was localised the current/last time the robot was localised (last valid)
87  Vec3f robotPose; // Global position and orientation of the robot on the field, where x points to the positive yellow goal, y to the left, and z is a CCW rotation relative to the direction of the positive goal (last valid)
88  Vec2f robotPose2D; // Global position of the robot on the field, where x points to the positive yellow goal, and y to the left (last valid)
89 
90  // Ball variables
91  float ballConf; // Current confidence of the ball (always current)
92  bool haveBall; // Boolean flag whether we currently have a ball (always current)
93  bool ballIsNew; // Boolean flag whether haveBall turned from false to true in this cycle (always current)
94  float ballTimeAgo; // Time since the ball was last valid (last valid)
95  float ballDur; // Duration for which the ball has been/was valid the current/last time it was valid (last valid)
96  Vec2f ballDir; // Egocentric vector from the robot to the ball (last valid)
97  float ballAngle; // Egocentric angle to the ball, measured CCW from straight ahead (last valid)
98  float ballDist; // Distance from the robot to the ball (last valid)
99  bool ballStable; // Boolean flag whether the ball is currently close and valid, and has been valid for long enough that it is considered to be stable (always current)
100  bool haveBallPose; // Boolean flag whether we currently have a ball pose (always current)
101  bool ballPoseIsNew; // Boolean flag whether haveBallPose turned from false to true in this cycle (always current)
102  float ballPoseTimeAgo; // Time since the ball pose was last valid (last valid)
103  float ballPoseDur; // Duration for which the ball pose has been/was valid the current/last time it was valid (last valid)
104  Vec2f ballPose; // Global position of the ball on the field (last valid)
105  bool ballPoseStable; // Boolean flag whether the ball pose is currently close and valid, and has been valid for long enough that it is considered to be stable (always current)
106 
107  // Goal variables
108  GoalPostList goalPosts; // List of currently detected goal posts, exactly as published by the vision
109 
110  // Obstacle variables
111  ObstacleList obstacles; // List of currently detected obstacles, exactly as published by the vision
112  Obstacle obstClosest; // The closest detected obstacle to the robot
113 
114  // Extended play state variables
115  bool ballHasMoved; // Boolean flag whether the ball has moved away from the field centre since the kickoff
116  bool ballInPlay; // Boolean flag whether the ball is in play
117  bool directGoalAllowed; // Boolean flag whether a direct kick of the ball into the goals is allowed and will result in a score
118 
119  // Team communication variables
120  TCVars TC; // Note: All uses of this variable should be preceded by checking listenToTC
121  bool TCDataAvailable; // Boolean flag whether fresh team communications data is available from at least one robot
122  bool listenToTC; // Boolean flag whether the robot should listen to the team communications
123 
124  // Miscellaneous variables
125  DiveDirection diveDecision;
126 
127  //
128  // Helper functions
129  //
130 
131  // Functions to check the role of the robot
132  bool isInvalidRole() const { return !gameRoleValid(gameRole); }
133  bool isFieldPlayer() const { return gameRoleIsFieldPlayer(gameRole); }
134  bool isGoalie() const { return gameRoleIsGoalie(gameRole); }
135 
136  // Robot state functions
137  bool isRelaxed() const { return RI.stateRelaxed(); }
138  bool isIniting() const { return RI.stateIniting(); }
139  bool isStanding() const { return RI.stateStanding(); }
140  bool isWalking() const { return RI.stateWalking(); }
141  bool isKicking() const { return RI.stateKicking(); }
142  bool isFallen() const { return RI.stateFallen(); }
143 
144  private:
145  // ROS interface
146  WAKRosInterface& RI;
147 
148  // Play state set function
149  void setPlayState(PlayState state, const ros::Time& toldTime = ros::Time());
150 
151  // Play state timeout management functions
152  void clearPlayStateTimeout() { rc_utils::zeroRosTime(m_playStateTimeout); }
153  void setPlayStateTimeout(const ros::Time& timeout) { m_playStateTimeout = timeout; }
154  bool havePlayStateTimeout() const { return !m_playStateTimeout.isZero(); }
155  bool playStateWouldTimeOut(const ros::Time& timeout) const { return (!timeout.isZero() && now >= timeout); }
156  bool playStateTimedOut() const { return playStateWouldTimeOut(m_playStateTimeout); }
157 
158  // Play state timeout condition functions
159  bool timeoutTimeout(float timeSinceLastTold) const { return (timeSinceLastTold >= config.gcTimeoutTimeoutLast()); }
160  bool timeoutReady() const { return (kickoffType == KT_MANUAL || !havePlayStateTimeout() || playStateTimedOut()); }
161  bool timeoutSet(float timeSinceFirstIn, float timeSinceFirstTold, float timeSinceLastTold) const;
162  bool timeoutBeginPlay(float timeSinceFirstTold) const { return (listenToGC || kickoffType == KT_MANUAL || timeSinceFirstTold >= rc_utils::coerceMin(config.sWaitTime() - config.waitTimeReduction(), 0.0f)); }
163 
164  // Play state variables
165  ros::Time m_playStateFirstIn;
166  ros::Time m_playStateFirstTold;
167  ros::Time m_playStateLastTold;
168  ros::Time m_playStateTimeout;
169  ros::Time m_lastTimeNotPlaying;
170 
171  // Internal localisation variables
172  ros::Time m_robotPoseTimeFirst;
173  ros::Time m_robotPoseTimeLast;
174 
175  // Internal ball variables
176  ros::Time m_ballTimeFirst;
177  ros::Time m_ballTimeLast;
178  ros::Time m_ballPoseTimeFirst;
179  ros::Time m_ballPoseTimeLast;
180 
181  // Robot state variables
182  int m_standingCount;
183 
184  // Ball has moved detection variables
185  TheWorm m_ballHasMovedWorm;
186 
187  // Miscellaneous variables
188  cycle_t m_updateCycle;
189  };
190 }
191 
192 #endif
193 // EOF
Configuration struct for the walk and kick node.
Definition: wak_config.h:20
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 encapsulates all of the game controller input data to the walk and kick node...
Definition: wak_gc_vars.h:29
A class that encapsulates all of the team communication input data to the walk and kick node...
Definition: wak_tc_vars.h:37
A simple class for abstracting away the source of the field dimensions.
Definition: wak_utils.h:216
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