ClearingMobileRobot.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 #ifndef __CLEARING_MOBILE_ROBOT_
00027 #define __CLEARING_MOBILE_ROBOT_
00028
00029
00030 #include <libplayerc++/playerc++.h>
00031 #include <vector>
00032 #include <list>
00033 #include <unistd.h>
00034 #include <math.h>
00035 #include <cstdlib>
00036 #include <assert.h>
00037 #include <iostream>
00038 #include <fstream>
00039
00040
00041 #include <R2.h>
00042 #include <Grid.h>
00043 #include <Scan.h>
00044 #include <MobileRob.h>
00045 #include <PlayerRob.h>
00046
00047
00048
00049
00050
00051 using namespace PlayerCc;
00052 using namespace std;
00053 using namespace boost;
00054 using namespace MipBaselib;
00055 using namespace MipResources;
00056
00058 static void _motionWork ( void* p );
00059
00061 static void _motionClean ( void* p );
00062
00063 enum BehaviorTypes
00064 {
00065 EXPAND,
00066 GUARD,
00067 FOLLOW,
00068 WANDER,
00069 NO_BEHAVIOR
00070 };
00071
00072 enum KeepColor
00073 {
00074 KEEP_UNKNOWN,
00075 KEEP_ORANGE,
00076 KEEP_PURPLE
00077 };
00078
00079 class ClearingMobileRobot;
00080
00081 typedef uint IdentityCL;
00082 typedef std::vector<Position > PathCl;
00083
00084
00085
00086 class ClearingAgent;
00087
00091 typedef std::vector<ClearingAgent> AgentVector;
00092
00093
00094
00098 class ClearingAgent{
00099 Position _pos;
00100 bool _isLeader;
00101 IdentityCL _ID;
00102 BehaviorTypes _behavior;
00103
00104
00105 public:
00106 ClearingAgent(const ClearingAgent &a){
00107 }
00108 void operator=(const ClearingAgent& a){
00109 }
00110
00111
00112
00115 void setID(IdentityCL i){
00116 _ID = i;
00117 }
00118
00121 void setPosition(Position p){
00122 _pos = p;
00123 }
00124
00126 void setIsLeader(){
00127 _isLeader = true;
00128 }
00129
00131 void unsetIsLeader(){
00132 _isLeader = false;
00133 }
00134
00136 void setBehavior(BehaviorTypes b){
00137 _behavior = b;
00138 }
00139
00140
00141
00142
00145 IdentityCL getID(){
00146 return _ID;
00147 }
00148
00151 Position getPosition(){
00152 return _pos;
00153 }
00154
00157 bool isLeader(){
00158 return _isLeader;
00159 }
00160
00162 BehaviorTypes getBehavior(){
00163 return _behavior;
00164 }
00165
00166
00167
00168
00171 void goTo(Position pos){
00173 }
00174
00175 int getNumFollowers(){
00177 return 0;
00178 }
00179
00180 bool isWaitingForAnyAgent(){
00182 return false;
00183 }
00184
00185 void setToFollow(){
00186 }
00187
00188 Position getLSRPosition(){
00189 return Position();
00190 }
00191
00192 Decimal getSensorRange(){
00193 return 0.0;
00194 }
00195
00196 Frontier getFrontier(){return Frontier();}
00197 Cell* getCell(DubInt c){return NULL;}
00198 Position getCellPosition(DubInt c){return Position();}
00199 bool isWaitingForAgent(IdentityCL id){return false;}
00200 void clearWaitingForAgent(){}
00201 void setFrontier(Frontier& f){}
00202 void setToWander(){}
00203 void setToExpand(PathCl &pth, AgentVector& agnt){}
00204 void setToNoBehavior(){}
00205 void logData(){}
00206 void addFollower(ClearingAgent& cla){}
00207 void addFollower(ClearingMobileRobot* clmr){}
00208 };
00209
00210
00214 class ClearingMobileRobot{
00215
00216 protected :
00217
00218
00219 MobileRob* _mobileRob;
00220 IdentityCL m_iID;
00221
00222 Position goal;
00223
00224 Thread _motionThread;
00225
00226 BehaviorTypes m_eBehavior;
00227 Frontier m_frontier;
00228 Frontier m_freeArcs;
00229 Frontier m_prevFrontier;
00230 Grid m_LSR;
00231 Grid m_prevLSR;
00232 bool m_bFrontierInitialized;
00233 PathCl m_path;
00234 ClearingAgent* m_pWaitForAgent;
00235 AgentVector m_followers;
00236
00237
00238 void Expand( AgentVector neighbors );
00239 void Guard( AgentVector neighbors );
00240 void processFrontier( AgentVector neighbors );
00241 void Wander( AgentVector neighbors );
00242
00243 void recordLSR();
00244
00245 bool isCellCovered( DubInt iViewPoint, DubInt iCell );
00246
00247
00248
00249
00250
00251
00252 Position pickBestViewPoint(int *iNumViewPoints, bool bDebugDisplay = false);
00253
00254
00255
00256 void updateFrontier( AgentVector neighbors, bool bDebugDisplay = false );
00257
00258
00259 public :
00262 ClearingMobileRobot( IdentityCL ID, int argc, const char* argv[]);
00263
00266 ClearingMobileRobot( IdentityCL ID, int argc, const char* argv[], MobileRob* rob);
00267
00269 ~ClearingMobileRobot( );
00270
00272 IdentityCL getID(){
00273 return m_iID;
00274 }
00275
00277 BehaviorTypes getBehavior(){
00278 return m_eBehavior;
00279 }
00280
00282 Grid getLSR(){
00283 return ((m_bFrontierInitialized) ? m_LSR : m_prevLSR);
00284 }
00285
00286 LRR getLRR(){
00287 return ((m_bFrontierInitialized) ? m_LSR._lrr : m_prevLSR._lrr);
00288 }
00289
00290 Frontier getFrontier(){
00291 return ((m_bFrontierInitialized) ? m_frontier : m_prevFrontier);
00292 }
00293
00294 void velCmd(Decimal drive, Decimal turnrate){
00295 _mobileRob->velCmd(drive,turnrate);
00296 }
00297
00298 Position getGoal(){
00299 return goal;
00300 }
00301
00302 int getNumFrontierSegments(){
00303 return ((m_bFrontierInitialized) ? m_frontier.size() : m_prevFrontier.size());
00304 }
00305
00306 int getTotalFrontierCells();
00307
00308 void setFrontier(Frontier frontier, bool bForce = false );
00309
00310 PathCl getPathCl(){
00311 return m_path;
00312 }
00313
00314 Pose getPose(){
00315 return _mobileRob->getPose();;
00316 }
00317
00318 Position getPosition(){
00319 return getPose().pos();
00320 }
00321
00322 Position getViewpoint();
00323
00324 Scan getScan();
00325
00326 ExplorationParams getExplParams();
00327
00328 double getSensorRange(){
00329
00330
00331 return (double)(_mobileRob->rangeSensPar()->linRangeMax());
00332 }
00333
00334 double getCoverRange();
00335
00336 double getWidth(){
00337 return _mobileRob->robPar()->radius();
00338 }
00339
00340 int getLSRSize(){
00341 return ((m_bFrontierInitialized) ? m_LSR.columns()*m_LSR.rows() : m_prevLSR.columns()*m_prevLSR.rows());
00342 }
00343
00344 vector<Cell* > getRaster( DubInt iCell1, DubInt iCell2 );
00345
00346 double getLSRResolution(){
00347 return ((m_bFrontierInitialized) ? m_LSR.resolution() : m_prevLSR.resolution());
00348 }
00349
00350 Position getLSRPosition();
00351
00352 LSRBound getLSRBound(){
00353 return ((m_bFrontierInitialized) ? m_LSR.lsrBound() : m_prevLSR.lsrBound());
00354 }
00355
00356 Cell* getCell( DubInt indices ){
00357 return ((m_bFrontierInitialized) ? m_LSR.getCell(indices) : m_prevLSR.getCell(indices));
00358 }
00359
00360 Cell* getCell( Position pos ){
00361 return ((m_bFrontierInitialized) ? m_LSR.getCell(pos) : m_prevLSR.getCell(pos));
00362 }
00363
00364 Cell* getCell( int i ){
00365 return ((m_bFrontierInitialized) ? m_LSR.getCell(i) : m_prevLSR.getCell(i));
00366 }
00367
00368 Position getCellPosition( DubInt indices ){
00369 return getCell(indices)->point();
00370 }
00371
00372 int getNumFollowers(){
00373 return m_followers.size();
00374 }
00375
00376 Position getFollowerPosition();
00377
00378
00379 void setToExpand( PathCl path, AgentVector neighbors, bool bDoExpand = true );
00380 void setToGuard( AgentVector neighbors );
00381 void setToFollow( );
00382 void setToWander( );
00383 void setToNoBehavior( );
00384
00385 void goTo( Position pos );
00386 void addFollower( ClearingAgent* newFollower, bool bMove = true );
00387
00388
00389 void doCurrentBehavior( AgentVector neighbors );
00390
00391 bool isLeader();
00392 bool isReady();
00393 bool isWaitingForAnyAgent();
00394 bool isWaitingForAgent(int iID);
00395 void clearWaitingForAgent();
00396 bool isTraveling();
00397
00398 void drawBoundary( Graphics2dProxy &gp );
00399 void drawFrontier( Graphics2dProxy &gp );
00400 void drawLSR( Graphics2dProxy &gp, bool bOnlyLSR );
00401
00402 bool canDetectTargetPosition( Position targetPos );
00403 };
00404
00405
00406 #endif //TEST_FRONTIER_PURSUIT_H