RemoteRob.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 
00026 
00033 
00034 
00035 #ifndef __REMOTE_ROB_H_
00036 #define __REMOTE_ROB_H_
00037 
00038 #include <socketUDP.h>
00039 #include <CommonOptions.h>
00040 
00041 #include "MobileRob.h"
00042 #include "RemoteRangeSens.h"
00043 #include <SsUtils.h>
00044 
00045 namespace MipResources{
00047  /* @{ */
00048 
00049 
00051 extern "C" void RRWork(void* p);
00052 
00054 extern "C" void RRClean(void* p);
00055 
00059 class RemoteRobPar : public MobileRobPar{
00060  private:
00061  public:
00063   RemoteRobPar(){};
00065   ~RemoteRobPar();
00066 };
00067 
00071 class RemoteRobVar : public MobileRobVar{
00072  private:
00073  public:
00074   Pose   _lastPose;
00075   Position _lastVelo;
00076   Pose   _lastPoseGoal; //TODO c'è già in MobileRobVar
00077   Position _lastVeloGoal; //TODO c'è già in MobileRobVar
00078 
00079   Time _lastPoseTime;
00080   Time _lastVeloTime;
00081   Time _lastPoseGoalTime;
00082   Time _lastVeloGoalTime;
00083   
00084   Scan lastScan;
00085   MotionModuleTState lastScanTState;
00086 /*  
00087   Pose lastScanPose;
00088   Decimal lastScanLinVel;
00089   Decimal lastScanAngVel;
00090   Time lastScanTime;*/
00091   
00093   RemoteRobVar(){};
00095   ~RemoteRobVar(){};
00096 };
00097 
00101 class RemoteRob : public MobileRob{
00102  private:
00103   static const ResourcePlate _plate = MR_REM_RES;
00104   
00105   RemoteRobVar *_remoteVar; 
00107   // onboard sensors
00108   RemoteRangeSens  *_remoteRangeSens;   
00109 //  Korebot   *_korebotMot;  ///< abstract Robot motion module
00110 
00111 //  RemoteRangeSens  *_tcrt5000;   ///< abstract Robot IR range sensor
00112 
00113   
00114   Timer timer;
00115   int receivedScan ;
00116   
00117   Thread _RRThread;
00118   int myId;
00119   SenderUDP*  sender;
00120   ListenerUDP* listener;
00121   int   sendPort;
00122   int   listPort;
00123   string addr;
00124   bool  unconnected;
00125   
00126   // TODO: devo fare un thread che aggiorna questi campi, poi le getVel e simili che sono viste dall'esterno
00127   // riportano all'esterno questi campi
00128   
00129 
00130   void startConnection();
00131   void closeConnection();
00133   void RRParse(string &msg);
00134   
00136   virtual void sendString(string s){
00137    sender->send(s);
00138   }
00139   
00140   void upPose();
00141   void downPose();
00142   void sendOnePose();
00143   void sendNPose(int num);
00144   
00145   void upVelo();
00146   void downVelo();
00147   void sendOneVelo();
00148   void sendNVelo(int num);
00149   void setVelo(Position &vel);
00150 
00151   void upPoseGoal();
00152   void downPoseGoal();
00153   void sendOnePoseGoal();
00154   void sendNPoseGoal(int num);
00155   void setPoseGoal(Pose &pose);
00156   
00157   void upVeloGoal();
00158   void downVeloGoal();
00159   void sendOneVeloGoal();
00160   void sendNVeloGoal(int num);
00161   void setVeloGoal(Position vel);
00162   
00163   void getRangeSensPar();
00164 
00165  public:
00167   RemoteRob(int argc, const char* argv[]);
00168   
00170   ~RemoteRob();
00171 
00173   ResourcePlate getPlate() const {
00174    return _plate;
00175   }
00176   
00179   Scan scan(){
00180    Scan s;
00181    return s;
00182   };
00183   
00184   /* Scan */
00186   void startScan(unsigned int num);
00188   void stopScan();
00190   void startIR(unsigned int num);
00192   void stopIR();
00193 
00194   /* Motion Module */
00196   UnicyclePar* unicyclePar();
00197   
00199   void velCmd(Decimal drive, Decimal turnrate);
00200   
00204   void getVel(Decimal& drive, Decimal& turnrate);
00205   
00207   Pose getPose(void);
00208   
00210   MotionModuleTState getMotionState();
00211   
00213   void setPose(Pose p);
00214   
00216   bool setMotionState(MotionModuleState state, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00217   
00219   bool storedScan(Scan& s,Time timeout);
00221   bool updatedScan(Scan& s);
00223   bool updatedScan(Scan& s, MotionModuleTState& state);
00224   
00225   
00228   void RRReceive(){
00229   //    cout << "entro in ricezione" << endl;
00230    string sender_addr;
00231    bool emptysocket = listener->lSelect();
00232    while(emptysocket == 1){
00233     string s;
00234     listener->receive(s, sender_addr);
00235   //     cout << "# receiving one packet " << s << "|   ";
00236     RRParse(s);
00237     emptysocket = listener->lSelect();
00238    }
00239   }
00240 };
00241 
00242  /* @} */
00243  
00244 };// end namespace MipResources{
00245 
00246 #endif
00247 
00248 
00249 
00250 
00251 
00252 

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