Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FFPlanNode.cc

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

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