tibi_dabo_hideandseek_alg.cpp
Go to the documentation of this file.
00001 #include "tibi_dabo_hideandseek_alg.h"
00002 
00003 TibiDaboHideandseekAlgorithm::TibiDaboHideandseekAlgorithm(void)
00004 {
00005   ROS_INFO("TibiDaboHideandseekAlgorithm::constructor!");
00006   //this->mySeekerHS = new SeekerHS();
00007   this->path="nopath";
00008   this->pathOut="nopathout";
00009   this->map="nomap";
00010   this->experiment ="experiment1";
00011   this->solver=1;
00012   this->windist=1;
00013   this->cellsize=1;
00014 }
00015 
00016 TibiDaboHideandseekAlgorithm::~TibiDaboHideandseekAlgorithm(void)
00017 {
00018 }
00019 
00020 void TibiDaboHideandseekAlgorithm::config_update(Config& new_cfg, uint32_t level)
00021 {
00022   this->lock();
00023   ROS_DEBUG("TibiDaboHideandseekAlgorithm::config_update!");
00024 
00025   // save the current configuration
00026   this->config_=new_cfg;
00027   this->path       = new_cfg.path;
00028   this->pathOut    = new_cfg.pathOut;
00029   this->map        = new_cfg.map;
00030   this->experiment = new_cfg.experiment;
00031   this->solver     = new_cfg.solver;
00032   this->windist    = new_cfg.windist;
00033   this->setWinDistToHider(this->windist);
00034   this->cellsize   = new_cfg.cellsize;
00035   this->setCellSizeM(this->cellsize);
00036 
00037   this->unlock();
00038 }
00039 
00040 // TibiDaboHideandseekAlgorithm Public API
00041 
00042 void TibiDaboHideandseekAlgorithm::initialize(std::string path, std::string pathOut, std::string map, std::string experiment, int solver)
00043 {
00044   ROS_INFO("TibiDaboHideandseekAlgorithm::initialize!");
00045   this->path       = path;
00046   this->pathOut    = pathOut;
00047   this->map        = map;
00048   this->experiment = experiment;
00049   this->solver     = solver;
00050 
00051   std::string mapFile     = this->path + "/maps/"  + this->map + ".txt";
00052   std::string pomdpFile   = this->path + "/pomdpx/simplerew/"+ this->map + ".pomdpx";
00053   std::string policyFile  = this->path + "/policy/simplerew/"+ this->map + ".pol";
00054 
00055   std::string logFile     = this->pathOut + "/" + this->experiment+"_log.txt";
00056   std::string timeLogFile = this->pathOut + "/" + this->experiment+"_timeLog.txt";
00057   std::string gameLogFile = this->pathOut + "/" + this->experiment+"_gameLog.txt";
00058 
00059   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: experiment: %s", this->experiment.c_str());
00060   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: solver: %i", this->solver);
00061   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: INPUT FILES");
00062   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: map   : %s", mapFile.c_str());
00063   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: pomdp : %s", pomdpFile.c_str());
00064   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: policy: %s", policyFile.c_str());
00065   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: OUTPUT FILES");
00066   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: log    : %s", logFile.c_str());
00067   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: timelog: %s", timeLogFile.c_str());
00068   ROS_INFO(" TibiDaboHideandseekAlgorithm::initialize: gamelog: %s", gameLogFile.c_str());
00069   
00070   SeekerHSParams* params = new SeekerHSParams();
00071 
00072   //parameters for seeker
00073   params->mapFile     = mapFile;
00074   params->expName     = this->experiment;
00075   params->solverType  = this->solver; //use SeekerHSParams::SOLVER_*
00076   //in case of pomdp
00077   params->pomdpFile   = pomdpFile;
00078   //for offline pomdp
00079   params->policyFile  = policyFile;
00080   //log files
00081   params->logFile     = logFile;
00082   params->timeLogFile = timeLogFile;
00083   params->gameLogFile = gameLogFile;
00084   //online pomdp params
00085   params->segmenterType = SeekerHSParams::SEGMENTER_ROBOT_CENTERED;
00086   params->rcSegmDist    = 10;
00087   params->rcAngDist     = 45;
00088   params->rcBaseRad     = 0;
00089   params->rcHighResR    = 0;
00090   //on-line params, set top reward and final state
00091   params->setFinalStateOnTop = true;
00092   params->setFinalTopRewards = true;
00093 
00094   //to make faster (but worse results)
00095   params->ubInitType = SeekerHSParams::UPPERBOUND_INIT_MDP;
00096   params->timeoutSeconds = 10;
00097 
00098   params->allowInconsistObs=true;  
00099 
00100   this->mySeekerHS = new SeekerHS(params);
00101 
00102   //this->mySeekerHS = new SeekerHS(mapFile, this->experiment, this->solver, pomdpFile, policyFile, logFile, timeLogFile, gameLogFile);
00103   ROS_INFO("TibiDaboHideandseekAlgorithm::initialize done!");
00104 }
00105 
00106 bool TibiDaboHideandseekAlgorithm::initGame(const geometry_msgs::PoseStamped seekerPose, 
00107                                                const std::vector < geometry_msgs::Point > hiderPoses)
00108 {
00109   std::vector<double> seekerPosVector;
00110 
00111   seekerPosVector.push_back(seekerPose.pose.position.x);
00112   seekerPosVector.push_back(seekerPose.pose.position.y);
00113 
00114   std::vector < std::vector<double> > hiderPositionsVector;
00115   std::vector<double> hiderPosition;
00116   for(unsigned int i=0; i<hiderPoses.size(); i++)
00117   {
00118     hiderPosition.clear();
00119     hiderPosition.push_back(hiderPoses[i].x);
00120     hiderPosition.push_back(hiderPoses[i].y);
00121     hiderPosition.push_back(hiderPoses[i].z);
00122     hiderPositionsVector.push_back(hiderPosition);
00123   }
00124 
00125   try
00126   {
00127     this->mySeekerHS->initMultipleObs(seekerPosVector, hiderPositionsVector);
00128     return true;
00129   }
00130   catch (CException & e)
00131   {
00132     ROS_ERROR("Exception: %s", e.what().c_str());
00133     ROS_DEBUG("TibiDaboHideAndSeekAlgorithm::initGame: exception!");
00134     return false;
00135   }
00136 }
00137 
00138 bool TibiDaboHideandseekAlgorithm::iteration(const geometry_msgs::PoseStamped seekerPose, 
00139                                               const std::vector < geometry_msgs::Point > hiderPoses, 
00140                                               geometry_msgs::PoseStamped & seekerGoal, 
00141                                               int & gameStatus)
00142 {
00143   std::vector<double> newSeekerPosVector;  
00144   int winState;
00145 
00146   std::vector<double> seekerPosVector;
00147   seekerPosVector.push_back(seekerPose.pose.position.x);
00148   seekerPosVector.push_back(seekerPose.pose.position.y);
00149 
00150   std::vector < std::vector<double> > hiderPositionsVector;
00151   std::vector<double> hiderPosition;
00152 
00153   for(unsigned int i=0; i<hiderPoses.size(); i++)
00154   {
00155     hiderPosition.clear();
00156     hiderPosition.push_back(hiderPoses[i].x);
00157     hiderPosition.push_back(hiderPoses[i].y);
00158     hiderPosition.push_back(hiderPoses[i].z);
00159     hiderPositionsVector.push_back(hiderPosition);
00160   }
00161 
00162   try
00163   {
00164     this->mySeekerHS->getNextMultiplePosesForMultipleObs(seekerPosVector, hiderPositionsVector, 1, newSeekerPosVector, &winState);
00165     seekerGoal.pose.position.x = newSeekerPosVector[0];
00166     seekerGoal.pose.position.y = newSeekerPosVector[1];
00167     double yaw = newSeekerPosVector[2];
00168     tf::quaternionTFToMsg (tf::createQuaternionFromRPY(0.0,0.0,yaw),  seekerGoal.pose.orientation);
00169     gameStatus=winState;
00170     return true;
00171   }
00172   catch (CException & e)
00173   {
00174     ROS_ERROR("Exception: %s", e.what().c_str());
00175     ROS_DEBUG("TibiDaboHideandseekAlgorithm::iteration: done!");
00176     return false;
00177   }
00178 
00179 }
00180 
00181 void TibiDaboHideandseekAlgorithm::setWinDistToHider(int winDist)
00182 {
00183   this->mySeekerHS->setWinDistToHider(winDist);
00184 }
00185 
00186 void TibiDaboHideandseekAlgorithm::setCellSizeM(double cellSizeM)
00187 {
00188   this->mySeekerHS->setCellSizeM(cellSizeM);
00189 }
00190 
00191 void TibiDaboHideandseekAlgorithm::stopGame(int winState)
00192 {
00193   this->mySeekerHS->stopGame(winState);
00194 }


tibi_dabo_hideandseek
Author(s): fherrero
autogenerated on Fri Dec 6 2013 22:12:38