RemoteRobTask.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
00029
00030
00034
00035
00036
00037 #ifndef __REMOTE_ROB_TASK_H_
00038 #define __REMOTE_ROB_TASK_H_
00039
00040 #include <Task.h>
00041 #include <Resource.h>
00042 #include <MobileRob.h>
00043 #include <Time.h>
00044
00045 #include <CommonOptions.h>
00046 #include <socketUDP.h>
00047 #include <SsUtils.h>
00048 #include <Thread.h>
00049 #include <Trajectory.h>
00050 #include <SharedMem.h>
00051
00052 using namespace MipResources;
00053
00054 namespace MipTasks{
00055
00057
00058
00059
00061 enum RemoteRobotCommPacketsTypes{
00062 RRB_SCAN_UP,
00063 RRB_SCAN_DOWN,
00064 RRB_SCAN_GET_ONE,
00065 RRB_SCAN_GET_N,
00066 RRB_IR_UP,
00067 RRB_IR_DOWN,
00068 RRB_IR_GET_ONE,
00069 RRB_IR_GET_N,
00070 RRB_GP_UP,
00071 RRB_GP_DOWN,
00072 RRB_GP_GET_ONE,
00073 RRB_GP_GET_N,
00074 RRB_VG_UP,
00075 RRB_VG_DOWN,
00076 RRB_VG_GET_ONE,
00077 RRB_VG_GET_N,
00078 RRB_COMM_PACKETS_TYPES_NUM
00079 };
00081 static const char* RemoteRobotCommPackets[RRB_COMM_PACKETS_TYPES_NUM] = {
00082 "scu",
00083 "scd",
00084 "scg",
00085 "scn",
00086 "iru",
00087 "ird",
00088 "irg",
00089 "irn",
00090 "gpu",
00091 "gpd",
00092 "gpg",
00093 "gpn",
00094 "gvu",
00095 "gvd",
00096 "gvg",
00097 "gvn"
00098 };
00099
00100
00104 class RemoteRobTaskOptions : public Options {
00105 public:
00106 IntOption* scanSendingRate;
00107 IntOption* raysSendingRate;
00108 IntOption* sendBearing;
00109
00110 RemoteRobTaskOptions();
00111
00112 string getObjectName() const {
00113 return "RemoteRobTaskOptions";
00114 }
00115 };
00116
00117
00121 class RemoteRobSharedMem : public SharedMem{
00122 public:
00123 void initSharedMem(){
00124 }
00125 };
00126
00127
00129 extern "C" void scanSenderWork(void* t);
00130
00132 extern "C" void scanSenderClean(void* p);
00133
00135 extern "C" void poseVeloSenderWork(void* t);
00136
00138 extern "C" void poseVeloSenderClean(void* p);
00139
00140
00144 class RemoteRobTask : public Task{
00145 protected:
00146 Thread _scanSenderThread;
00147 Thread _poseVeloSenderThread;
00148 private:
00149
00150 RemoteRobTaskOptions options;
00151
00152 static const TaskPlate _plate = RRB_TASK;
00153 static const long int _maxDurSec = 0, _maxDurUsec = 100000;
00154 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 100000;
00155 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 1000;
00156
00157 ScanTypes rangeSensorType;
00158
00159 MobileRob* _mobileRob;
00160 RemoteRobSharedMem* _sharedMem;
00161 Position robPosition;
00162 Pose robPose;
00163
00164 bool connected;
00165
00166 int myId;
00167
00168 int lastTakenScan;
00169
00170 Time lastTimeStamp;
00171 int lastTotalScans;
00172
00173 ListenerUDP* listener;
00174 SenderUDP* sender;
00175
00176 vector<string> incomingPackets;
00177 vector<string> incomingPacketsSenders;
00178 vector<string> outcomingPackets;
00179
00180 int sendPort;
00181 string senderAddr;
00182 int listPort;
00183
00184 bool _sendRangeSensParFlag;
00185
00187 bool sendRawScan;
00189 int _sendState;
00191 int _sendScan;
00193 int _sendIR;
00194
00197 int _sendPoseGoal;
00199 int _sendVeloGoal;
00200
00201 public:
00203 RemoteRobTask(ResourcePointers resources,int argc, const char* argv[]);
00204
00206 ~RemoteRobTask(){
00207 delete listener;
00208 delete sender;
00209 }
00210
00213 TaskPlate getPlate() const {
00214 return _plate;
00215 }
00218 Time getMaxDuration(){
00219 return Time(_maxDurSec,_maxDurUsec);
00220 }
00223 Time getMaxSamplPeriod(){
00224 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00225 }
00228 Time getMinSamplPeriod(){
00229 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00230 }
00232 TaskOutputs run();
00233
00235 void doScanSenderWork();
00236
00238 void doPoseVeloSenderWork();
00239
00240 private:
00241
00242
00244 bool searchConnection();
00246 void unconnect(){
00247 connected = false;
00248 delete sender;
00249 }
00251 void receiveCommands();
00253 void executeCommands();
00254
00255
00256
00258 void upState(){ _sendState = -1; }
00260 void downState(){ _sendState = 0; }
00262 void sendOneState(){ _sendState = 1; }
00265 void sendNState(stringstream &s);
00266
00267
00268
00270 void upPoseGoal(){ _sendPoseGoal = -1; }
00272 void downPoseGoal(){ _sendPoseGoal = 0; }
00274 void sendOnePoseGoal(){ _sendPoseGoal = 1; }
00277 void sendNPoseGoal(stringstream &s);
00278
00279
00281 void upVeloGoal(){ _sendVeloGoal = -1; }
00283 void downVeloGoal(){ _sendVeloGoal = 0; }
00285 void sendOneVeloGoal(){ _sendVeloGoal = 1; }
00288 void sendNVeloGoal(stringstream &s);
00289
00290
00291
00293 void upScan(){ _sendScan = -1; }
00295 void downScan(){ _sendScan = 0; }
00297 void sendOneScan(){ _sendScan = 1; }
00299 void sendNScan(stringstream &s);
00301 void _sendRangeSensPar(){ _sendRangeSensParFlag = true; }
00302
00303
00304
00306 void upIR(){ _sendIR = -1; }
00308 void downIR(){ _sendIR = 0; }
00310 void sendOneIR(){ _sendIR = 1; }
00312 void sendNIR(stringstream &s);
00313
00314
00315
00318 void setStateNoTime(stringstream &s);
00321 void setState(stringstream &s);
00324 void setVel(stringstream &s);
00327 void setPoseGoal(stringstream &s);
00330 void setVeloGoal(stringstream &s);
00331
00332
00333
00335 void sendState();
00337 void sendPoseGoal();
00339 void sendVeloGoal();
00341 void sendScan();
00343 void sendRangeSensPar();
00345 void sendRangeSensmmPar();
00347 void sendIR();
00348
00349
00350
00353 void updateScan(){
00354 Scan scan;
00355 _mobileRob->updatedScan(scan);
00356 }
00357
00359 void startScan(){
00360 _mobileRob->startScan(0);
00361 }
00362
00364 void getNScan(stringstream &s){
00365 int num;
00366 s >> num;
00367 _mobileRob->startScan(num);
00368 }
00369
00371 void stopScan(){
00372 _mobileRob->stopScan();
00373 }
00374 };
00375
00376
00377
00378 };
00379
00380
00381 #endif
00382
00383
00384
00385