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 class TeamMessageMessage; 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 00068 */ 00069 void setOutTeamMessages(TeamMessage& tm); 00070 00071 /** 00072 * The function sets an internal reference to an incoming TeamMessage 00073 * @param tm The TeamMessage 00074 */ 00075 void setInTeamMessages(TeamMessage& tm); 00076 00077 /** 00078 * This function sets the robotPose field in the outgoing TeamMessage 00079 * that is represented by the target 00080 * @param robotPose The RobotPose to be sent 00081 * @param sendNow bool o indicate that the message needs to be sent now (default = false) 00082 */ 00083 void send(const RobotPose& robotPose, bool sendNow = false) const; 00084 00085 /** 00086 * This function sets the BehaviorTeamMessage field in the outgoing TeamMessage 00087 * that is represented by the target 00088 * @param behaviorTeamMessage The BehaviorTeamMessage to be sent 00089 * @param sendNow bool o indicate that the message needs to be sent now 00090 */ 00091 void send(const BehaviorTeamMessage& behaviorTeamMessage, bool sendNow = false) const; 00092 00093 /** 00094 * This function sets the BehaviorTeamMessage field in the outgoing TeamMessage 00095 * that is represented by the target 00096 * @param seenBallPosition The SeenBallPosition to be sent 00097 * @param sendNow bool o indicate that the message needs to be sent now 00098 */ 00099 void send(const PlayersPercept& playersPercept, bool sendNow = false) const; 00100 00101 /** 00102 * This function sets the PlayersPercept in the outgoing TeamMessage 00103 * @param playersPercept The PlayersPercept to be sent 00104 * @param sendNow bool o indicate that the message needs to be sent now 00105 */ 00106 void send(const SeenBallState& seenBallState, bool sendNow = false) const; 00107 00108 /** 00109 * This function sets the SensorBehaviorTeamMessage in the outgoing TeamMessage 00110 * @param sensorBehaviorTeamMessage The SensorBehaviorTeamMessage to be sent 00111 * @param sendNow bool to indicate that the message needs to be sent now 00112 */ 00113 void send(const SensorBehaviorTeamMessage& sensorBehaviorTeamMessage, bool sendNow = false) const; 00114 00115 /** 00116 * This function sets the SensorBehaviorTeamMessage in the outgoing TeamMessage 00117 * @param odometryData The OdometryData to be sent 00118 * @param sendNow bool to indicate that the message needs to be sent now 00119 */ 00120 void send(const OdometryData& odometryData, bool sendNow = false) const; 00121 00122 /** 00123 * This function sets the SensorBehaviorTeamMessage in the outgoing TeamMessage 00124 * @param multipleBallPerceptList The MultipleBallPerceptList to be sent 00125 * @param sendNow bool to indicate that the message needs to be sent now 00126 */ 00127 void send(const MultipleBallPerceptList& multipleBallPerceptList, bool sendNow = false) const; 00128 00129 /** 00130 * This function sets the SensorBehaviorTeamMessage in the outgoing TeamMessage 00131 * @param gt2005ParticleContainerSend The GT2005ParticleContainerSend to be sent 00132 * @param sendNow bool to indicate that the message needs to be sent now 00133 */ 00134 void send(const GT2005ParticleContainerSend& gt2005ParticleContainerSend, bool sendNow = false) const; 00135 00136 /** 00137 * This function sets the SensorBehaviorTeamMessage in the outgoing TeamMessage 00138 * @param robotPoseCollection The RobotPoseCollection to be sent 00139 * @param sendNow bool to indicate that the message needs to be sent now 00140 */ 00141 void send(const RobotPoseCollection& robotPoseCollection, bool sendNow = false) const; 00142 00143 /** 00144 * This function sets the ObstaclesModel in the outgoing TeamMessage 00145 * @param obstaclesModel The obstaclesModel to be sent 00146 * @param sendNow bool to indicate that the message needs to be sent now 00147 */ 00148 void send(const ObstaclesModel& obstaclesModel, bool sendNow = false) const; 00149 00150 /** 00151 * This function processes the outgoing messages. 00152 * @return A bool that is true when the messages should be send. 00153 */ 00154 bool processOutMessages(); 00155 00156 /** 00157 * get the delay between two subsequent sends 00158 */ 00159 int getDelay() const ; 00160 00161 /** 00162 * set the delay between two subsequent sends 00163 */ 00164 void setDelay(int delay); 00165 00166 // void send(TeamMessageMessage*) const; 00167 // void stop(TeamMessageMessage*) const; 00168 void set(TeamMessageMessageCollection*); 00169 00170 protected: 00171 int delay; /**< the delay between two subsequent sends */ 00172 const TeamMessage* teamMessages[maxNumberOfTeamMessages]; /**< pointer to the incomming teamMessages */ 00173 TeamMessage* outTeamMessages[maxNumberOfTeamMessages]; /**< pointer to outgoing teamMessages */ 00174 int teamMessagesForActualTeamMessages[maxNumberOfTeamMessages]; /**< Array to translate teamMessage number for backwards compability */ 00175 00176 unsigned lastSendingTimeStamp; /**< TimeStamp when sending the last TeamMessage */ 00177 unsigned teamMessageTimeStamp[maxNumberOfTeamMessages]; /**< TimeStamps of the latest incoming TeamMessages */ 00178 unsigned incomingTimeStamp[maxNumberOfTeamMessages]; /**< Local TimeStamp of the latest incoming TeamMessages */ 00179 00180 // Attrributes for time sync 00181 RingBuffer<signed long,100> offsets[maxNumberOfTeamMessages] ; /**< Ringbuffer to save the last 100 time offsets for the 3 TeamMessages */ 00182 signed long timeOffsetSum[maxNumberOfTeamMessages]; /**< Sum of all the values in the ringBuffers */ 00183 00184 // Attribute for better streaming of TeamMessage 00185 bool messagesSent; /**< set true if the messages have been sent */ 00186 mutable bool sendNow; /**< pointer to a bool which shows that the robot has to send the messages */ 00187 long lastSendTime; /**< time when *sendNow was last true. Used to send after a delay */ 00188 00189 // Count of TeamMessages for initializing 00190 00191 int numberOfInTeamMessages; 00192 int numberOfOutTeamMessages; 00193 00194 /** 00195 * This method is called by processMessages() to find out the time-offsets between the robots. 00196 * It saves the time-difference in the corresponding TeamMessage accesed by operator[] 00197 */ 00198 void processTimeStamps(); 00199 00200 /** 00201 * This method is calls by processMessages() to set the fields of the teamMessageForTarget[] array. 00202 * This array is used by the send-methods to find out which teamMessages send to a target. 00203 */ 00204 void processMessagePlayerRole(); 00205 }; 00206 00207 #endif //__TeamMessageCollection_h_
1.3.6