RemoteKhepera.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00031
00032 #ifndef __REMOTE_KHEPERA_H_
00033 #define __REMOTE_KHEPERA_H_
00034
00035 #include <socketUDP.h>
00036 #include <CommonOptions.h>
00037
00038 #include "remKhepComm.h"
00039 #include "URG04LX.h"
00040 #include "MobileRob.h"
00041 #include "RemoteRangeSens.h"
00042 #include <SsUtils.h>
00043 #include <deque>
00044
00045
00046
00047 #ifdef LINK_ROS
00048 #define CONNECTTOROS
00049 #endif
00050
00051
00052
00053
00054
00055
00056 #ifdef CONNECTTOROS
00057 #include <ROSNode.h>
00058 #endif
00059
00060 namespace MipResources{
00062
00063
00065 extern "C" void RKWork(void* p);
00066
00068 extern "C" void RKClean(void* p);
00069
00073 class RemoteKheperaPar : public MobileRobPar{
00074 private:
00075 public:
00077 RemoteKheperaPar(){};
00079 ~RemoteKheperaPar();
00080 };
00081
00082
00086 class RemoteKheperaVar : public MobileRobVar{
00087
00088 private:
00089 bool _lastScan1IsLast;
00090
00091 pthread_mutex_t _tStateLogMutex;
00092
00093 MotionModuleTStateLog _tStateLog;
00094
00095 public:
00096
00097 Scan* _lastScan1;
00098 Scan* _lastScan2;
00099
00100 Time _lastScanTime;
00101 Timer _scanTimer;
00102 int _lastScanNum;
00103 int _lastStateNumber;
00104
00105
00106 #ifdef CONNECTTOROS
00107 bool _alreadyArrivedLaser;
00108
00109 #endif
00110
00113 bool setLastScan(Scan& newScan);
00114
00118 bool getLastScan(Scan& scan, Time timeout);
00119
00120
00124 bool getOldScan(Scan& scan, Time timeout);
00125
00126
00128 RemoteKheperaVar();
00129
00131 ~RemoteKheperaVar(){};
00132
00133 pthread_mutex_t* ptStateLogMutex(){
00134 return &_tStateLogMutex;
00135 }
00136
00138 void lockTStateLog(){
00139 pthread_mutex_lock(&_tStateLogMutex);
00140 }
00141
00143 void unlockTStateLog(){
00144 pthread_mutex_unlock(&_tStateLogMutex);
00145 }
00146
00149 MotionModuleTStateLog* ptrTStateLog(){
00150 return &_tStateLog;
00151 }
00152 };
00153
00157 class RemoteKheperaOptions : public MobileRobOptions{
00158 public:
00159 StringOption* baseName;
00160 StringOption* topicName;
00161 StringOption* nodeName;
00163 RemoteKheperaOptions();
00164
00167 string getObjectName() const {
00168 return "RemoteKheperaOptions";
00169 }
00170
00171 OptionGroupsType getGroup();
00172 };
00173
00174
00178 class RemoteKhepera : public MobileRob{
00179 private:
00180 static const ResourcePlate _plate = MR_REM_KHP_RES;
00181
00182 URG04LXPar _urg04lxPar;
00183
00184 RemoteKheperaVar *_remoteVar;
00185
00186 RemoteRangeSens *_remoteRangeSens;
00187
00188 bool _correctLandingStates;
00189 Pose _stateToCorrect;
00190 Pose _correctedState;
00191
00192 stringstream _ssWarning;
00193 stringstream _ssDebug;
00194
00195 Timer _timer;
00196 int _receivedScan ;
00197
00198 Thread _RRThread;
00199 SenderUDP* _sender;
00200 ListenerUDP* _listener;
00201 int _sendPort;
00202 int _listPort;
00203 string _addr;
00204 bool _unconnected;
00205
00207 void _startConnection();
00208
00210 void _startConnectionROS();
00211
00213 void _closeConnection();
00214
00218 void _parse(string &msg,deque<MotionModuleTState>* itListTState=NULL);
00219
00220 void _sendString(string s);
00221 void _getRangeSensPar();
00222
00223 EnhancedMutEx count_mutex;
00224
00225
00226
00227 #ifdef CONNECTTOROS
00228 ROSNode* _rosNode;
00229 int _topicSpecifier;
00230 RemoteKheperaOptions* _options;
00231 bool _firstOdomMsg;
00232 Decimal _lasTimeTStateIn;
00233 Decimal _tempTimeTStateIn;
00234 int _numOdoMsgAdded;
00235 list<MotionModuleTState>::iterator _itPTrTStateLog;
00236 Decimal _lasTimeLaser;
00237 #endif
00238 public:
00240 RemoteKhepera(int argc, const char* argv[]);
00241
00243 ~RemoteKhepera();
00244
00246 ResourcePlate getPlate() const {
00247 return _plate;
00248 }
00249
00252 Scan scan(){
00253 Scan s;
00254 return s;
00255 };
00256
00257
00259 void startScan(unsigned int num);
00260
00262 void stopScan();
00263
00264
00266 UnicyclePar* unicyclePar();
00267
00269 void velCmd(Decimal drive, Decimal turnrate);
00270
00274 void getVel(Decimal& drive, Decimal& turnrate);
00275
00277 Pose getPose(void);
00278
00280 MotionModuleTState getMotionState();
00281
00283 void setPose(Pose p);
00284
00286 bool setMotionState(MotionModuleState state, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00287
00289 bool storedScan(Scan& s,Time timeout);
00291 bool updatedScan(Scan& s);
00293 bool updatedScan(Scan& s, MotionModuleTState& state);
00294
00298 bool updatedState(MotionModuleTState& state, Time &timeStamp);
00299
00302 bool updatedState(MotionModuleTState& state);
00303
00310 bool updatedLastState(MotionModuleTState& state, Time& timeStamp, const Decimal &delta);
00311
00318 bool updatedLastState(MotionModuleTState& state, const Decimal &delta);
00319
00322 void receive();
00323
00325 void receiveUDP();
00326
00328 void receiveROS();
00329
00334 void _syncroTime();
00335
00338 RangeSensPar* rangeSensPar();
00339 };
00340
00341
00342
00343 };
00344
00345 #endif
00346
00347
00348
00349
00350