Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FFPlanner.cc

Go to the documentation of this file.
00001 #include "Shared/RobotInfo.h"
00002 #if !defined(PLATFORM_APERIOS) && !defined(TGT_IS_AIBO)
00003 #include <stdio.h>
00004 #include <unistd.h>
00005 
00006 #include "Events/EventRouter.h"
00007 #include "FFPlanner.h"
00008 
00009 void FFPlanner::plan(const std::string &problemFileName, const std::string &_planFileName) {
00010   planFileName = _planFileName;
00011   launchFF(problemFileName);
00012   erouter->addTimer(this, 9999, 100, true);
00013 }
00014 
00015 void FFPlanner::launchFF(const std::string &problemFileName) {
00016   pid_t child_id = fork();
00017   if ( child_id == 0 ) {
00018     char* tekrootval = getenv("TEKKOTSU_ROOT");
00019     std::string const tekkotsuRoot = tekrootval==NULL ? "/usr/local/Tekkotsu" : std::string(tekrootval);
00020     std::string const ffScriptName = "invoke-ff";
00021     std::string const ffScriptPath = tekkotsuRoot + "/Planners/FF/bin/" + ffScriptName;
00022     std::string const PlanFile = "/tmp/tekkotsu-PlannerOutput.txt";
00023     execlp(ffScriptPath.c_str(), ffScriptName.c_str(), domainFileName.c_str(), problemFileName.c_str(), planFileName.c_str(), NULL);
00024     // If we get here, the execlp() failed
00025     std::cerr << "ERROR: failed to launch invoke-ff script from " << ffScriptPath << std::endl
00026         << "Check that TEKKOTSU_ROOT is set properly." << std::endl;
00027     _exit(0);
00028   }
00029 }
00030 
00031 void FFPlanner::doEvent() {
00032   if ( event->getGeneratorID() == EventBase::timerEGID && event->getSourceID() == 9999) {
00033     FILE *in = fopen(planFileName.c_str(), "r");
00034     if ( in != NULL ) {
00035       erouter->removeTimer(this,9999);
00036       size_t BUFFSIZE = 32768;
00037       char buffer[BUFFSIZE];
00038       size_t res = fread(&buffer, 1, BUFFSIZE-1, in);
00039       if ( feof(in) == 0 ) {
00040         std::cout << "Error reading file " << planFileName << " in FFPlanner::doEvent()" << std::endl;
00041       } else {
00042         buffer[res] = 0;
00043         result = std::string(buffer);
00044       }
00045       //erouter->postEvent(EventBase(EventBase::aiEGID, (size_t)this, EventBase::statusETID));
00046     }
00047   }
00048 }
00049 
00050 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:38 2016 by Doxygen 1.6.3