00001 /** 00002 * @file Representations/WLan/TeamMessageCollection.h 00003 * 00004 * Declaration of class TeamMessageCollection 00005 * 00006 * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A> 00007 * @author <A href=mailto:sebastian.schmidt@udo.edu>Sebastian Schmidt</A> 00008 * @author <A href=mailto:m_wachter@gmx.de>Michael Wachter</A> 00009 */ 00010 00011 #ifndef __TeamMessageCollection_h_ 00012 #define __TeamMessageCollection_h_ 00013 00014 #include "TeamMessage.h" 00015 00016 #include "Tools/RingBuffer.h" 00017 00018 /** 00019 * @class TeamMessageCollection 00020 * 00021 * Represents a collection of all actual team messages received from other robots 00022 * and has the ability to send to them too. 00023 * 00024 */ 00025 00026 class TeamMessageCollection 00027 { 00028 public: 00029 00030 /** 00031 * Timeout-constants for the processMasterSync method 00032 */ 00033 enum {robotTimeoutTime = 4000, masterTimeoutTime = 2000, masterClaimTimeoutTime = 1500}; 00034 /** 00035 * the maximum number of team-messages 00036 */ 00037 enum {maxNumberOfTeamMessages = Player::numOfPlayerNumbers-1}; 00038 00039 int numberOfTeamMessages; /**< count of actual TeamMessages */ 00040 00041 00042 /** 00043 * Constructor. 00044 */ 00045 TeamMessageCollection() ; 00046 00047 /** 00048 * Constant access operator to a certain team message. Only 00049 * actual team-messages are given back. (TeamMessage.isActual() == true) 00050 * @param index The index of the team message. 00051 * @return The team message with the requested index. 00052 */ 00053 const TeamMessage& operator[](int index) const 00054 { 00055 return *teamMessages[teamMessagesForActualTeamMessages[index]]; 00056 } 00057 00058 /** 00059 * This method processes the incomming messages to calculate time-offsets for 00060 * the time syncronisation, to find out which Robot is Master and to find out 00061 * if one robot is missing. 00062 */ 00063 void processMessages(); 00064 00065 /** 00066 * The function sets the internal references to the outgoing TeamMessages 00067 * @param tm the outgoing teamMessage to add 00068 */ 00069 void setOutTeamMessages(TeamMessage& tm); 00070 00071 /** 00072 * The function sets the internal references to the incoming TeamMessages 00073 * @param tm the incoming teamMessage to add 00074 */ 00075 void setInTeamMessages(TeamMessage& tm); 00076 00077 /** 00078 * This function sets the robotPose field in the outgoing TeamMessage 00079 * @param robotPose The RobotPose to be sent 00080 * @param sendNow bool to indicate that the message needs to be sent now (default = false) 00081 */ 00082 void send(const RobotPose& robotPose, bool sendNow = false) const; 00083 00084 /** 00085 * This function sets the BehaviorTeamMessage field in the outgoing TeamMessage 00086 * @param behaviorTeamMessage The BehaviorTeamMessage to be sent 00087 * @param sendNow bool to indicate that the message needs to be sent now 00088 */ 00089 void send(const BehaviorTeamMessage& behaviorTeamMessage, bool sendNow = false) const; 00090 00091 /** 00092 * This function sets the BehaviorTeamMessage field in the outgoing TeamMessage 00093 * @param seenBallPosition The SeenBallPosition to be sent 00094 * @param sendNow bool to indicate that the message needs to be sent now 00095 */ 00096 void send(const SeenBallPosition& seenBallPosition, bool sendNow = false) const; 00097 00098 /** 00099 * This function processes the outgoing messages. 00100 * @return A bool that is true when the messages should be send. 00101 */ 00102 bool processOutMessages(); 00103 00104 /** 00105 * get the delay between two subsequent sends 00106 */ 00107 int getDelay() const ; 00108 00109 /** 00110 * set the delay between two subsequent sends 00111 */ 00112 void setDelay(int delay); 00113 00114 private: 00115 int delay; /**< the delay between two subsequent sends */ 00116 const TeamMessage* teamMessages[maxNumberOfTeamMessages]; /**< pointer to the incomming teamMessages */ 00117 TeamMessage* outTeamMessages[maxNumberOfTeamMessages]; /**< pointer to outgoing teamMessages */ 00118 int teamMessagesForActualTeamMessages[maxNumberOfTeamMessages]; /**< Array to translate teamMessage number for backwards compability */ 00119 00120 unsigned lastSendingTimeStamp; /**< TimeStamp when sending the last TeamMessage */ 00121 unsigned teamMessageTimeStamp[maxNumberOfTeamMessages]; /**< TimeStamps of the latest incoming TeamMessages */ 00122 unsigned incomingTimeStamp[maxNumberOfTeamMessages]; /**< Local TimeStamp of the latest incoming TeamMessages */ 00123 00124 // Attrributes for time sync 00125 RingBuffer<signed long,100> offsets[maxNumberOfTeamMessages] ; /**< Ringbuffer to save the last 100 time offsets for the 3 TeamMessages */ 00126 signed long timeOffsetSum[maxNumberOfTeamMessages]; /**< Sum of all the values in the ringBuffers */ 00127 00128 // Attribute for better streaming of TeamMessage 00129 bool messagesSent; /**< set true if the messages have been sent */ 00130 mutable bool sendNow; /**< pointer to a bool which shows that the robot has to send the messages */ 00131 long lastSendTime; /**< time when *sendNow was last true. Used to send after a delay */ 00132 00133 // Count of TeamMessages for initializing 00134 00135 int numberOfInTeamMessages; 00136 int numberOfOutTeamMessages; 00137 00138 /** 00139 * This method is called by processMessages() to find out the time-offsets between the robots. 00140 * It saves the time-difference in the corresponding TeamMessage accesed by operator[] 00141 */ 00142 void processTimeStamps(); 00143 00144 /** 00145 * This method is calls by processMessages() to set the fields of the teamMessageForTarget[] array. 00146 * This array is used by the send-methods to find out which teamMessages send to a target. 00147 */ 00148 void processMessagePlayerRole(); 00149 }; 00150 00151 #endif //__TeamMessageCollection_h_ 00152 00153 /* 00154 * Change log : 00155 * 00156 * $Log: TeamMessageCollection.h,v $ 00157 * Revision 1.2 2004/09/08 14:39:03 wachter 00158 * - Fixed some doxygen-errors 00159 * 00160 * Revision 1.1.1.1 2004/05/22 17:26:05 cvsadm 00161 * created new repository GT2004_WM 00162 * 00163 * Revision 1.3 2004/05/15 14:31:55 nistico 00164 * Didn't compile on VS6. 00165 * 00166 * Revision 1.2 2004/05/14 14:12:08 wachter 00167 * - Added communication support for 5 robots 00168 * - rewrote parts of team-communication to be faster and more stable 00169 * 00170 * Revision 1.1 2003/10/07 10:09:36 cvsadm 00171 * Created GT2004 (M.J.) 00172 * 00173 * Revision 1.3 2003/09/26 15:27:28 juengel 00174 * Renamed DataTypes to representations. 00175 * 00176 * Revision 1.2 2003/07/02 19:14:23 loetzsch 00177 * bug fixes, removed unused functions 00178 * 00179 * Revision 1.1.1.1 2003/07/02 09:40:23 cvsadm 00180 * created new repository for the competitions in Padova from the 00181 * tamara CVS (Tuesday 2:00 pm) 00182 * 00183 * removed unused solutions 00184 * 00185 * Revision 1.5 2003/05/02 12:57:13 loetzsch 00186 * TeamMessage now contains a SeenBallPosition instead of a BallPercept 00187 * 00188 * Revision 1.4 2003/02/28 17:02:55 wachter 00189 * Reenabled trainer-syncronisation for RuhrpottHellhound-Behavior 00190 * 00191 * Revision 1.3 2003/02/25 12:55:40 wachter 00192 * made some attributes muteable 00193 * 00194 * Revision 1.2 2003/02/18 13:24:36 wachter 00195 * added new TeamMessageCollection and TeamMessage 00196 * 00197 * Revision 1.1 2002/09/10 15:26:41 cvsadm 00198 * Created new project GT2003 (M.L.) 00199 * - Cleaned up the /Src/DataTypes directory 00200 * - Removed Challenge Code 00201 * - Removed processing of incoming audio data 00202 * - Renamed AcousticMessage to SoundRequest 00203 * 00204 * Revision 1.1 2002/06/03 15:28:06 roefer 00205 * BallLocator gets TeamMessageCollection 00206 * 00207 * 00208 */