PursuingComm.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00029 
00030 
00031 
00032 
00033 #ifndef __PURSUING_COMM_H_
00034 #define __PURSUING_COMM_H_
00035 
00036 #ifdef MIP_HOST_APPLE
00037 #include <applePatch.h>
00038 #endif
00039 
00040 #include <fstream>
00041 
00042 #include <Task.h>
00043 #include <Resource.h>
00044 #include <SharedMem.h>
00045 #include <Time.h>
00046 
00047 #include <CommonOptions.h>
00048 #include <CommModule.h>
00049 #include <PursuingData.h>
00050 
00051 using namespace MipResources;
00052 
00053 namespace MipTasks{
00054  
00056  /* @{ */
00057  
00067  enum PursuingMessageTypes{
00068  PUR_MES_MY_POSE, 
00069  PUR_MES_MY_STATE,
00070  PUR_MES_GIMME_FRONTIER, 
00071  PUR_MES_MY_FRONTIER, 
00072  PUR_MES_NO_GUARD_FRONTIER, 
00073  PUR_MES_YOUR_NEW_FRONTIER, 
00074  PUR_MES_FOLLOW, 
00075  PUR_MES_EXPAND, 
00076  PUR_MES_WANDER, 
00077  PUR_MES_WANNA_BE_FOLLOWER, 
00078  PUR_MES_NO_GUARD_AFFILIATION, 
00079  PUR_MES_FOLLOW_ME, 
00080  PUR_MES_NUM 
00081  };
00082  
00084  static const char* pursuingMessageStrings[PUR_MES_NUM] = {
00085  "MY_POSE",
00086  "MY_STATE",
00087  "GIMME_FRONTIER",
00088  "MY_FRONTIER",
00089  "NO_GUARD_FRONTIER",
00090  "YOUR_NEW_FRONTIER",
00091  "FOLLOW",
00092  "EXPAND",
00093  "WANDER",
00094  "WANNA_BE_FOLLOWER",
00095  "NO_GUARD_AFFILIATION",
00096  "FOLLOW_ME",
00097  };
00098  
00099  
00103  class PursuingComm:public MIPObject{
00104   private:
00105    CommModule* _commModule;
00106    TaskPlate _taskPlate;
00107    uint _robotId;
00108    map <uint, PursuingMessageTypes> _lastSentDialogMessages;
00109    map <uint, PursuingMessageTypes> _lastReceivedDialogMessages;
00110    bool _automaticRepliesActivated;
00111    
00112    const PursuingStates* _currentStatePtr; // The Pursuing state cannot be modified by PursuingComm
00113    
00118    string _pursuingMessageTypesToString(PursuingMessageTypes messageType);
00119  
00120   
00125    PursuingMessageTypes _stringToPursuingMessageTypes(string messageType);
00126  
00127    
00132    bool _sendAPacket(uint recipientId, PursuingMessageTypes messageType,string serializedData);
00133    
00138    bool _sendAPacket(vector <uint> recipientIds, PursuingMessageTypes messageType,string serializedData);
00139    
00145    bool _checkOutgoingMessage(PursuingMessageTypes outgoingMessageType, int recipientId);
00146  
00152    bool _checkOutgoingMessage(string outgoingMessageType, int recipientId);
00153  
00159    bool _checkReceivedMessage(PursuingMessageTypes receivedMessage,int senderId);
00160  
00166    bool _checkReceivedMessage(string receivedMessageType, int senderId);
00167  
00173    void _updateLastSentDialogMessages(PursuingMessageTypes justSentMessage, uint recipientId);
00174    
00175    
00181    void _updateLastReceivedDialogMessages(PursuingMessageTypes justReceivedMessage, uint senderId);
00182  
00183    
00184    
00189    bool _outgoingPacketIsOutOfProtocol(CommPacket *packet);
00190  
00195    bool _receivedPacketIsOutOfProtocol(CommPacket * packet);
00196    
00204    bool _basicReceiveLastPacket(uint recipientId, PursuingMessageTypes messageType, string & message,bool withMessage);
00205    
00212    bool _receiveLastPacket(uint recipientId, PursuingMessageTypes messageType, string & message);
00213  
00214    
00220    bool _receiveLastPacket(uint recipientId, PursuingMessageTypes messageType);
00221    
00224    void _replyAutomatically(map<uint,PursuingMessageTypes> &asyncReqUniv);
00225    
00226   public:
00231    PursuingComm(CommModule* commModule, TaskPlate plate, PursuingStates* currentStatePtr);
00232  
00234    ~PursuingComm();
00235    
00238    void setAutomaticReplies(bool automaticRepliesActivated);
00239    
00242    bool getAutomaticReplies();
00243    
00244  
00247    string getObjectName() const {
00248     return "PursuingComm";
00249    }
00250   
00251    // Pose updating
00252    
00256    void sendCurrentPose(vector <uint> recipientIds, Pose currentPose);
00257    
00258  
00262    bool sendCurrentState(vector <uint> recipientIds, PursuingStates currentState);
00263  
00264    
00265    // Frontier updating
00266    
00269    bool sendGiveMeYourFrontier(uint recipientId);
00270    
00273    bool sendImNotAGuardAnymoreFrontier(uint recipientId);
00274    
00277    bool sendMyCurrentFrontier(uint recipientId, const vector < vector<Position> > & frontier);
00278    
00281    bool sendYourUpdatedFrontier(uint recipientId, const vector < vector<Position> > & frontier);
00282    
00283    // Follower commands
00284    
00289    bool sendCommandFollow(uint recipientId, Pose goal);
00290    
00295    bool sendCommandExpand(uint recipientId, Pose goal);
00296    
00299    bool sendCommandWander(uint recipientId);
00300    
00301    // Follower affiliation
00302    
00305    bool sendIWannaBeYourFollower(uint recipientId);
00306    
00309    bool sendFollowMe(uint recipientId);
00310    
00311    
00314    bool sendImNotAGuardAnymoreAffiliation(uint recipientId);
00315    
00316    // Receiving
00317  
00320    void receiveCurrentPoses(map<uint,TimeStampedPose> & poses);
00321    
00324    void receiveCurrentStates(map<uint,PursuingStates> & states);
00325  
00331    bool receiveCurrentFrontier(uint senderId, bool &positiveResponse, vector< vector<Position> > & frontier);
00332    
00336    bool receiveUpdatedFrontier(uint senderId,vector < vector<Position> > & frontier);
00337    
00338  
00343    bool receiveGuardAcknowledgmentAffiliation(uint supposedGuardId, bool &accepted);
00344    
00352    bool receiveFollowerCommands(uint guardId, bool &follow, bool &expand, bool &wander, Pose& goal);
00353    
00356    void receiveUniversAsyncRequests(map<uint,PursuingMessageTypes> & asyncReq);
00357  };
00358  
00359  /* @} */
00360  
00361 };// end namespace MipTasks
00362 
00363 #endif
00364 
00365 
00366 
00367 
00368 

Generated on Mon Feb 20 07:01:08 2017 for MIP by  doxygen 1.5.6