Beispiel #1
0
bool PortMonitor::configureFromProperty(yarp::os::Property& options) {
    if(binder) delete binder;
    binder = nullptr;

    std::string script = options.check("type", Value("lua")).asString();
    std::string filename = options.check("file", Value("modifier")).asString();
    std::string constraint = options.check("constraint", Value("")).asString();
    // context is used to find the script files
    std::string context = options.check("context", Value("")).asString();

    // check which monitor should be used
    if((binder = MonitorBinding::create(script.c_str())) == nullptr)
    {
         yError(R"(Currently only 'lua' script and 'dll' object is supported by portmonitor)");
         return false;
    }

    // set the acceptance constraint
    binder->setAcceptConstraint(constraint.c_str());

    std::string strFile = filename;

    if(script != "dll")
    {
        yarp::os::ResourceFinder rf;
        rf.setDefaultContext(context.c_str());
        rf.configure(0, nullptr);
        strFile = rf.findFile(filename);
        if(strFile == "")
            strFile = rf.findFile(filename+".lua");
    }
Beispiel #2
0
bool CameraTest::setup(yarp::os::Property& property) {

    if(property.check("name"))
        setName(property.find("name").asString());

    // updating parameters
    RTF_ASSERT_ERROR_IF(property.check("portname"),
                        "The portname must be given as the test paramter!");
    cameraPortName = property.find("portname").asString();
    measure_time = property.check("measure_time") ? property.find("measure_time").asInt() : TIMES;
    expected_frequency = property.check("expected_frequency") ? property.find("expected_frequency").asInt() : FREQUENCY;
    tolerance = property.check("tolerance") ? property.find("tolerance").asInt() : TOLERANCE;

    // opening port
    RTF_ASSERT_ERROR_IF(port.open("/CameraTest/image:i"),
                        "opening port, is YARP network available?");

    RTF_TEST_REPORT(Asserter::format("Listening to camera for %d seconds",
                                       measure_time));

    // connecting
    RTF_TEST_REPORT(Asserter::format("connecting from %s to %s",
                                       port.getName().c_str(), cameraPortName.c_str()));
    RTF_ASSERT_ERROR_IF(Network::connect(cameraPortName, port.getName()),
                     "could not connect to remote port, camera unavailable");
    return true;
}
bool OpenLoopConsistency::setup(yarp::os::Property& property) {

    // updating parameters
    RTF_ASSERT_ERROR_IF(property.check("robot"), "The robot name must be given as the test parameter!");
    RTF_ASSERT_ERROR_IF(property.check("part"), "The part name must be given as the test parameter!");
    RTF_ASSERT_ERROR_IF(property.check("joints"), "The joints list must be given as the test parameter!");
    RTF_ASSERT_ERROR_IF(property.check("zero"),    "The zero position must be given as the test parameter!");

    robotName = property.find("robot").asString();
    partName = property.find("part").asString();

    zero = property.find("zero").asDouble();

    Bottle* jointsBottle = property.find("joints").asList();
    RTF_ASSERT_ERROR_IF(jointsBottle!=0,"unable to parse joints parameter");
    n_cmd_joints = jointsBottle->size();
    RTF_ASSERT_ERROR_IF(n_cmd_joints>0,"invalid number of joints, it must be >0");

    Property options;
    options.put("device", "remote_controlboard");
    options.put("remote", "/"+robotName+"/"+partName);
    options.put("local", "/OpenLoopConsistencyTest/"+robotName+"/"+partName);

    dd = new PolyDriver(options);
    RTF_ASSERT_ERROR_IF(dd->isValid(),"Unable to open device driver");
    RTF_ASSERT_ERROR_IF(dd->view(iopl),"Unable to open openloop interface");
    RTF_ASSERT_ERROR_IF(dd->view(ienc),"Unable to open encoders interface");
    RTF_ASSERT_ERROR_IF(dd->view(iamp),"Unable to open ampliefier interface");
    RTF_ASSERT_ERROR_IF(dd->view(ipos),"Unable to open position interface");
    RTF_ASSERT_ERROR_IF(dd->view(icmd),"Unable to open control mode interface");
    RTF_ASSERT_ERROR_IF(dd->view(iimd),"Unable to open interaction mode interface");

    if (!ienc->getAxes(&n_part_joints))
    {
        RTF_ASSERT_ERROR("unable to get the number of joints of the part");
    }

    if      (n_part_joints<=0)
        RTF_ASSERT_ERROR("Error this part has in invalid (<=0) number of jonits");
    else if (jointsBottle->size() == 1)
        cmd_mode=single_joint;
    else if (jointsBottle->size() < n_part_joints)
        cmd_mode=some_joints;
    else if (jointsBottle->size() == n_part_joints)
        cmd_mode=all_joints;
    else
        RTF_ASSERT_ERROR("invalid joint selection?");

    cmd_tot = new double[n_part_joints];
    pos_tot=new double[n_part_joints];
    jointsList=new int[n_cmd_joints];
    cmd_some=new double[n_cmd_joints];
    prevcurr_tot=new double[n_part_joints];
    prevcurr_some=new double[n_cmd_joints];
    for (int i=0; i <n_cmd_joints; i++) jointsList[i]=jointsBottle->get(i).asInt();

    return true;
}
bool ExampleTest::setup(yarp::os::Property &property) {

    // initialization goes here ...
    //updating the test name
    if(property.check("name"))
        setName(property.find("name").asString());

    string example = property.check("example", Value("default value")).asString();

    RTF_TEST_REPORT(Asserter::format("Use '%s' for the example param!",
                                       example.c_str()));
    return true;
}
Beispiel #5
0
bool PortMonitor::configureFromProperty(yarp::os::Property& options) {
    if(binder) delete binder;
    binder = NULL;

    ConstString script = options.check("type", Value("lua")).asString();
    ConstString filename = options.check("file", Value("modifier")).asString();
    ConstString constraint = options.check("constraint", Value("")).asString();
    // context is used to find the script files
    ConstString context = options.check("context", Value("")).asString();

    // check which monitor should be used
    if((binder = MonitorBinding::create(script.c_str())) == NULL)
    {
         yError("Currently only \'lua\' script and \'dll\' object is supported by portmonitor");
         return false;
    }

    // set the acceptance constraint
    binder->setAcceptConstraint(constraint.c_str());

    ConstString strFile = filename;

    if(script != "dll")
    {
        yarp::os::ResourceFinder rf;
        rf.setDefaultContext(context.c_str());
        rf.configure(0, NULL);
        strFile = rf.findFile(filename.c_str());
        if(strFile == "")
            strFile = rf.findFile(filename+".lua");
    }

    // provide some useful information for the monitor object
    // which can be accessed in the create() callback.
    Property info;
    info.clear();
    info.put("filename", strFile);
    info.put("type", script);
    info.put("source", options.find("source").asString());
    info.put("destination", options.find("destination").asString());
    info.put("sender_side",  options.find("sender_side").asInt());
    info.put("receiver_side",options.find("receiver_side").asInt());
    info.put("carrier", options.find("carrier").asString());

    PortMonitor::lock();
    bReady =  binder->load(info);
    PortMonitor::unlock();
    return bReady;
    return false;
}
bool GazeboYarpJointSensorsDriver::setJointSensorsType(yarp::os::Property & pluginParameters)  //WORKS
{
    std::cout << ".ini file found, using joint names in ini file" << std::endl;
    
    std::string parameter_name = "gazeboJointSensorsType";
    
    if(!pluginParameters.check(parameter_name.c_str())) {
        std::cout << "GazeboYarpJointSensorsDriver::setJointSensorsType() error: cannot find " << parameter_name << " parameter." << std::endl;
        return false;
    }
    
    std::string sensors_type = pluginParameters.find(parameter_name.c_str()).asString().c_str();
    
    if( sensors_type == "position" ) {
        jointsensors_type = Position;
    } else if ( sensors_type == "speed" ) {
        jointsensors_type = Speed;
    } else if ( sensors_type == "torque" ) {
        jointsensors_type = Torque;
    } else {
        std::cerr << "GazeboYarpJointSensorsDriver::setJointSensorsType() error: sensor type " << sensors_type << " not recognized." << std::endl
                  << "\t\tThe available types are position, speed and torque." << std::endl;
        return false;
    }
    
    return true;
}
Beispiel #7
0
void SkinGroup::initOutport(yarp::os::Property &config)
{
  std::string outPortName = config.check("out_port", yarp::os::Value("/outport"), "").asString().c_str();
  
  std::cout << "Out Port name ==>" << outPortName << std::endl;
  classificationOutport.open(outPortName.c_str());
}
// *********************************************************************************************************************
// *********************************************************************************************************************
//                                          ICUB WHOLE BODY DYNAMICS ESTIMATOR
// *********************************************************************************************************************
// *********************************************************************************************************************
ExternalWrenchesAndTorquesEstimator::ExternalWrenchesAndTorquesEstimator(int _period,
                                                               yarpWholeBodySensors *_sensors,
                                                               yarp::os::BufferedPort<iCub::skinDynLib::skinContactList> * _port_skin_contacts,
                                                               yarp::os::Property & _wbi_yarp_conf
                                                              )
:  periodInMilliSeconds(_period),
   sensors(_sensors),
   port_skin_contacts(_port_skin_contacts),
   enable_omega_domega_IMU(false),
   min_taxel(0),
   wbi_yarp_conf(_wbi_yarp_conf),
   assume_fixed_base_from_odometry(false)
{

    resizeAll(sensors->getSensorNumber(SENSOR_ENCODER));
    resizeFTs(sensors->getSensorNumber(SENSOR_FORCE_TORQUE));
    resizeIMUs(sensors->getSensorNumber(SENSOR_IMU));


    ///< Skin timestamp
    last_reading_skin_contact_list_Stamp = -1000.0;

    if( _wbi_yarp_conf.check("fixed_base") )
    {
        assume_fixed_base = true;
        fixed_link = _wbi_yarp_conf.find("fixed_base").asString();
    }
    else
    {
        assume_fixed_base = false;
    }

    if( _wbi_yarp_conf.check("assume_fixed_from_odometry") )
    {
        this->assume_fixed_base_from_odometry = true;
    }
}
Beispiel #9
0
bool SkinGroup::initSensors(yarp::os::Property &config)
{

    yarp::os::Bottle skinfiles = config.findGroup("parts").tail();

    yarp::os::ConstString skinFilePath = config.check("skinsensorpath", yarp::os::Value("C:/roboskin/software_yarp_related/iCub/app/kaspar/conf"), "specifiy skinsensor config file path").asString();
//    yarp::os::ConstString skinFilePath = config.check("skinsensorfilepath", yarp::os::Value("C:/roboskin/software_yarp_related/iCub/app/kaspar/conf"), "specifiy skinsensor config file path").asString();
    
    printf("==== %s   %d \n", skinFilePath.c_str(), skinfiles.size());
    for(int i = 0; i < skinfiles.size(); i++)
    {
        yarp::os::Property skinproperty;
        yarp::os::Bottle sensorConf(skinfiles.get(i).toString());
        if(skinproperty.fromConfigFile((skinFilePath + FILESEPARATOR + sensorConf.get(0).asString())))
        {
            // put new attribute ifLog to the property before initialising skin sensors
            //if(ifLogData)
            //{
            //    skinproperty.put("logdata", ifLogData);
            //    skinproperty.put("logfilepath", logpath.c_str());
            //}
			
            SkinBodyPart *sk = new SkinBodyPart(skinproperty);   // assuming property file is correct. No error checking and return. so be very careful
            sk->setPortToConnect(sensorConf.get(1).asString());
            
            if(sk->initConfiguration())
            {
                this->skinParts.push_back(sk);
            }
            else
            {
                delete sk;
				return false;
            }
		}
        else
        {
            fprintf(stderr, "Error loading skin sensor config file %s\n", sensorConf.get(0).asString().c_str());
			return false;
        }
    }
	return true;
}
Beispiel #10
0
bool SkinGroup::initConfiguration(yarp::os::Property &conf) {
  
  //int s = conf.size();
  //this->groupName = conf.get(0).asString().c_str();
  
  yarp::os::Value v = conf.find("groupname");
  
  if(v.isNull()) {
    printf("Not Group Name specified\n");
    return false;
  }
  else {
    this->groupName = v.asString().c_str();
  }
  
  
  initLogFile(conf);
  
  yarp::os::Value v2 = conf.find("parts");
  
  if(v2.isNull()) {
    return false;
  }
  else {
    // add all parts to this group
    
    if(!initSensors(conf)) {
      cerr << "ERROR: initSensors error. (SkinGroup)" << endl;
      return false;
    }
  }
  
  /*
    for (int j = 1; j < conf.size(); j++)
    {
    cout << conf.get(j).asString() << endl;
    int k = 0;
    for (k = 0; k < parts->size(); k++)
    {
    if (parts->at(k)->getPartName() == string(
    conf.get(j).asString().c_str()))
    {
    cout << "part : " << parts->at(k)->getPartName().c_str()
    << " is found and added to SkinGroup  "
    << this->groupName << endl;
    this->skinParts.push_back(parts->at(k));
    break;
    }
    }
    if (k == parts->size())
		{
		// Not found. Error
		cerr << "Sensor " << conf.get(j).asString().c_str()
		<< " for group " << this->groupName << " is not available."
					<< endl;
			return false;
		}
	}
	// not necessary. just to double check
	if (this->skinParts.size() != conf.size() - 1)
	{
		// Not found. Error
		cerr << "Not all sensors in sensorgroup " << this->groupName
				<< " are available. Check the config files" << endl;
		return false;
	}
  */
  cout << "OK. Sensors added for sensorgroup " << this->groupName << endl;
  
  // init other settings, e.g. offsets for each sensor in the whole data set
  
  taxelDimension = 0;
  for (size_t k = 0; k < skinParts.size(); k++)
    {
      offsets.push_back(taxelDimension);
      taxelDimension += skinParts[k]->getAllNumTaxels();
    }
  
  // other variables
  
  tempTactileData = new TactileData(taxelDimension);
  
  // load svm model file
  // TODO:
  yarp::os::ConstString _svmmodelfile = conf.find("svmmodel").asString();
  _svmmodelfile = conf.check("svmmodelfilepath", yarp::os::Value("traindata"), "").asString() + FILESEPARATOR + _svmmodelfile;
  
  this->svmmodelfile = _svmmodelfile.c_str();
  
  cout << "SKINGROUP : " << this->groupName << " has " << this->taxelDimension << " taxels" << endl;
  //this->classification = new TactileClassificationRawData(this->taxelDimension);
  this->classification = new TactileClassificationHist(this->taxelDimension);
  if(!this->classification->loadSVMModel(svmmodelfile.c_str()))
    {
      cout << "ERROR: cannot load SVMModel file " << svmmodelfile.c_str() << endl;
      return false;
    }
  
  yarp::os::Property custProp;
  custProp.put("normalisation", "none");
  custProp.put("hist_num_bins", 20);
  classification->customConfiguration(custProp);
  
  tState = new TactileState(TIME_DIMENSION, taxelDimension, 50);
  
  // init port for output broadcasting
  initOutport(conf);
  return true;
}
Beispiel #11
0
bool SkinGroup::initLogFile(yarp::os::Property &config)
{

  ifLogData = config.check("logdata");
  std::string logPath = config.check("logfilepath", yarp::os::Value("logs"), "specify log file path for data logging if logdata flag is specified").asString().c_str();
  

  // if log data to file
  //		ifLogData = config.check("logdata");
  yarp::os::Value nameValue = config.find("childName");
    //yarp::os::Value logPathValue = config.find("logfilepath");
    std::string childName = "";
      //string logpath = ""; //config.find("logfilepath").asString().c_str();
      
      if(!nameValue.isNull()) {
	childName = nameValue.asString().c_str();
	printf("Child name is %s\n", childName.c_str());
      }
      //if(!logPathValue.isNull())
      //{
	//	logpath = logPathValue.asString().c_str();
      printf("Log File Path is 5s\n", logPath.c_str());
      //}
      if(ifLogData) {
	time_t rawtime;
	struct tm * timeinfo;
	time ( &rawtime );
	timeinfo = localtime ( &rawtime );
	  std::string timeText = to_string(timeinfo->tm_sec) + "_" + to_string(timeinfo->tm_min) + "_" + to_string(timeinfo->tm_hour) + "_" + to_string(timeinfo->tm_mday)+ "_" + to_string(timeinfo->tm_mon + 1)+ "_" + to_string(timeinfo->tm_year + 1900);//asctime(timeinfo);

	  if(childName != "") {
	    logFile = this->getGroupName() + "_" + childName + "_" + timeText;
	  }
	  else {
	    logFile = this->getGroupName() + "_" + timeText;
	  }
	  
	  if(logPath != "") {
	    logFile = (logPath + FILESEPARATOR + logFile).c_str();
	  }
	  
	  printf("LOG DATA of part %s\n", logFile.c_str());
	  pLogFile =  fopen (logFile.c_str() , "w");
	  
	  if (pLogFile == NULL) {
	    fprintf(stderr, "Error opening file %s\n", logFile.c_str());
	    fprintf(stderr, "Log File disabled\n");
	    ifLogData = false;
	  }
	  else {
	    // write head info. 
	    
	    this->logText("version", "0.1");
	    
	    this->logText("partname", this->getGroupName().c_str());
	    
	    //int dim = this->sensorsNum*12;
	    //std::string s;
	    //std::stringstream out;
	    //out << dim;
	    //s = out.str();
	    //this->logText("dimension", s.c_str());
	  }
      }
      else {
	printf("NOT LOG DATA\n");
      }
      return ifLogData;
}
Beispiel #12
0
YarpScope::SimpleLoader::SimpleLoader(/* FIXME const */ yarp::os::Property &options, bool *ok)
{
    YarpScope::PortReader &portReader = YarpScope::PortReader::instance();
    YarpScope::PlotManager &plotManager = YarpScope::PlotManager::instance();

    Glib::ustring graph_remote, local_port, connection_carrier;
    bool connection_persistent;

    if (!options.check("remote")) {
        debug() << "Missing \"remote\" argument. Will wait for external connection";
    } else {
        graph_remote = options.find("remote").toString().c_str();
    }

    local_port = default_local_port;

    if (options.check("carrier")) {
        connection_carrier = options.find("carrier").asString().c_str();
    } else {
        connection_carrier = default_connection_carrier;
    }

    // TODO read from command line whether connections should be persistent or not
    connection_persistent = default_connection_persistent;


    if (!options.check("index")) {
        warning() << "Missing \"index\" argument. Will use index = 0";
    }
    const yarp::os::Value &indexValue = options.find("index");

    Glib::ustring plot_title, plot_bgcolor;
    int plot_size;
    float plot_minval, plot_maxval;
    bool plot_autorescale, plot_realtime, plot_triggermode;

    if (options.check("plot_title")) {
        plot_title = options.find("plot_title").toString().c_str();
    } else {
        plot_title = graph_remote;
    }

    if (options.check("min")) {
        plot_minval = (float)options.find("min").asDouble();
    } else {
        plot_minval = default_plot_minval;
    }

    if (options.check("max")) {
        plot_maxval = (float)options.find("max").asDouble();
    } else {
        plot_maxval = default_plot_maxval;
    }

    if (options.check("size")) {
        plot_size = options.find("size").asInt();
    } else {
        plot_size = default_plot_size;
    }

    if (options.check("bgcolor")) {
        plot_bgcolor = options.find("bgcolor").asString().c_str();
    }

    plot_autorescale = options.check("autorescale");

    // TODO enable realtime mode
    plot_realtime = options.check("realtime");
    (void)plot_realtime; // UNUSED

    // TODO enable trigger mode
    plot_triggermode = options.check("triggermode");
    (void)plot_triggermode; // UNUSED

    int plotIndex = plotManager.addPlot(plot_title, 0, 0, 1, 1, plot_minval, plot_maxval, plot_size, plot_bgcolor, plot_autorescale);


    Glib::ustring graph_title, graph_color, graph_type;
    int graph_index, graph_size;

    if (!indexValue.isList()) {

        graph_index = indexValue.asInt();

        if (options.check("graph_title")) {
            if (options.find("graph_title").isList()) {
                error() << "\"graph_title\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            graph_title = options.find("graph_title").toString().c_str();
        }

        if (options.check("color")) {
            if (options.find("color").isList()) {
                error() << "\"color\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            graph_color = options.find("color").toString().c_str();
        }

        if (options.check("type")) {
            if (options.find("type").isList()) {
                error() << "\"type\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            graph_type =  options.find("type").toString().c_str();
        } else {
            graph_type = default_graph_type;
        }

        if (options.check("graph_size")) {
            if (options.find("graph_size").isList()) {
                error() << "\"graph_size\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            graph_size =  options.find("graph_size").asInt();
        } else {
            graph_size = default_graph_size;
        }

        portReader.acquireData(graph_remote, graph_index, local_port, connection_carrier, connection_persistent);
        plotManager.addGraph(plotIndex, graph_remote, graph_index, graph_title, graph_color, graph_type, graph_size);

    } else {
        const yarp::os::Bottle &indexes = *indexValue.asList();
        yarp::os::Bottle titles, colors, types, sizes;

        if (options.check("graph_title")) {
            const yarp::os::Value &titlesValue = options.find("graph_title");
            if (!titlesValue.isList()) {
                error() << "\"graph_title\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            titles = *titlesValue.asList();
            if (titles.size() != indexes.size()) {
                error() << "\"graph_title\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
        } else {
            titles = yarp::os::Bottle::getNullBottle();
        }

        if (options.check("color")) {
            const yarp::os::Value &colorsValue = options.find("color");
            if (!colorsValue.isList()) {
                error() << "\"color\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            colors = *colorsValue.asList();
            if (colors.size() != indexes.size()) {
                error() << "\"color\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
        } else {
            colors = yarp::os::Bottle::getNullBottle();
        }

        if (options.check("type")) {
            const yarp::os::Value &typesValue = options.find("type");
            if (!typesValue.isList()) {
                error() << "\"type\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            types = *typesValue.asList();
            if (types.size() != indexes.size()) {
                error() << "\"type\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
        } else {
            types = yarp::os::Bottle::getNullBottle();
        }

        if (options.check("graph_size")) {
            const yarp::os::Value &sizesValue = options.find("graph_size");
            if (!sizesValue.isList()) {
                error() << "\"graph_size\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
            sizes = *sizesValue.asList();
            if (sizes.size() != indexes.size()) {
                error() << "\"graph_size\" and \"index\" arguments should have the same number of elements";
                *ok = false;
                return;
            }
        } else {
            sizes = yarp::os::Bottle::getNullBottle();
        }


        for (int i = 0; i < indexes.size(); i++) {
            graph_index = indexes.get(i).asInt();

            if (!titles.isNull()) {
                graph_title = titles.get(i).asString();
            }

            if (!colors.isNull()) {
                graph_color = colors.get(i).asString();
            }

            if (!types.isNull()) {
                graph_type = types.get(i).asString();
            } else {
                graph_type = default_graph_type;
            }

            if (!sizes.isNull()) {
                graph_size = sizes.get(i).asInt();
            } else {
                graph_size = default_graph_size;
            }

            portReader.acquireData(graph_remote, graph_index, local_port, connection_carrier, connection_persistent);
            plotManager.addGraph(plotIndex, graph_remote, graph_index, graph_title, graph_color, graph_type, graph_size);
        }
    }
    *ok = true;
}
Beispiel #13
0
/*! \brief Init the application with the current configuration.
 *
 *  \param config the configuration
 */
void MainWindow::init(yarp::os::Property config)
{
    this->config = config;

    string basepath=config.check("ymanagerini_dir", yarp::os::Value("")).asString().c_str();

    if(config.check("modpath")) {
        string strPath;
        string modPaths(config.find("modpath").asString().c_str());
        while (modPaths!="") {
            string::size_type pos=modPaths.find(";");
            strPath=modPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str()))
                strPath=basepath+strPath;
            if((strPath.rfind(PATH_SEPERATOR)==string::npos) ||
                    (strPath.rfind(PATH_SEPERATOR)!=strPath.size()-1))
                strPath = strPath + string(PATH_SEPERATOR);
            lazyManager.addModules(strPath.c_str());
            if (pos==string::npos || pos==0)
                break;
            modPaths=modPaths.substr(pos+1);
        }
    }

    if(config.check("respath")) {
        string strPath;
        string resPaths(config.find("respath").asString().c_str());
        while (resPaths!="") {
            string::size_type pos=resPaths.find(";");
            strPath=resPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str()))
                strPath=basepath+strPath;

            if((strPath.rfind(PATH_SEPERATOR)==string::npos) ||
                    (strPath.rfind(PATH_SEPERATOR)!=strPath.size()-1))
                strPath = strPath + string(PATH_SEPERATOR);

            lazyManager.addResources(strPath.c_str());
            if (pos==string::npos)
                break;
            resPaths=resPaths.substr(pos+1);
        }
    }

    yarp::manager::ErrorLogger* logger  = yarp::manager::ErrorLogger::Instance();


    if(config.check("apppath")) {
        string strPath;
        string appPaths(config.find("apppath").asString().c_str());
        while (appPaths!="") {
            string::size_type pos=appPaths.find(";");
            strPath=appPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str())) {
                strPath=basepath+strPath;
            }

            if((strPath.rfind(PATH_SEPERATOR)==string::npos) ||
                    (strPath.rfind(PATH_SEPERATOR)!=strPath.size()-1)) {
                strPath = strPath + string(PATH_SEPERATOR);
            }

            if(config.find("load_subfolders").asString() == "yes") {
                if(!loadRecursiveApplications(strPath.c_str())) {
                    logger->addError("Cannot load the applications from  " + strPath);
                }
                loadRecursiveTemplates(strPath.c_str());
            }
            else {
                lazyManager.addApplications(strPath.c_str());
            }
            if (pos==string::npos) {
                break;
            }
            appPaths=appPaths.substr(pos+1);
        }
    }

    if (config.check("templpath")) {
        string strPath;
        string templPaths(config.find("templpath").asString().c_str());
        while (templPaths!="") {
            string::size_type pos=templPaths.find(";");
            strPath=templPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str())) {
                strPath=basepath+strPath;
            }

            if(!loadRecursiveTemplates(strPath.c_str())) {
                logger->addError("Cannot load the templates from  " + strPath);
            }

            if (pos==string::npos) {
                break;
            }
            templPaths=templPaths.substr(pos+1);
        }
    }

    reportErrors();

    syncApplicationList();

    if(config.check("application")) {
        yarp::manager::XmlAppLoader appload(config.find("application").asString().c_str());
        if(!appload.init()) {
            return;
        }
        yarp::manager::Application* application = appload.getNextApplication();
        if(!application) {
            return;  // TODO far ritornare valore per chiudere in caso di errore
        }
        // add this application to the manager if does not exist
        if(!lazyManager.getKnowledgeBase()->getApplication(application->getName())) {
            lazyManager.getKnowledgeBase()->addApplication(application);
            syncApplicationList();
        }
        //manageApplication(application->getName());
    }
}
Beispiel #14
0
/*! \brief Init the application with the current configuration.
 *
 *  \param config the configuration
 */
void MainWindow::init(yarp::os::Property config)
{
    this->config = config;

    string basepath=config.check("ymanagerini_dir", yarp::os::Value("")).asString().c_str();
    templateList.clear();

    if(config.check("modpath")){
        string strPath;
        string modPaths(config.find("modpath").asString().c_str());
        while (modPaths!=""){
            string::size_type pos=modPaths.find(";");
            strPath=modPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str()))
                strPath=basepath+strPath;
            if((strPath.rfind(PATH_SEPERATOR)==string::npos) ||
            (strPath.rfind(PATH_SEPERATOR)!=strPath.size()-1))
                strPath = strPath + string(PATH_SEPERATOR);
            lazyManager.addModules(strPath.c_str());
            if (pos==string::npos || pos==0)
                break;
            modPaths=modPaths.substr(pos+1);
        }
    }

    if(config.check("respath")){
        string strPath;
        string resPaths(config.find("respath").asString().c_str());
        while (resPaths!=""){
            string::size_type pos=resPaths.find(";");
            strPath=resPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str()))
                strPath=basepath+strPath;

            if((strPath.rfind(PATH_SEPERATOR)==string::npos) ||
            (strPath.rfind(PATH_SEPERATOR)!=strPath.size()-1))
                strPath = strPath + string(PATH_SEPERATOR);

            lazyManager.addResources(strPath.c_str());
            if (pos==string::npos)
                break;
            resPaths=resPaths.substr(pos+1);
        }
    }

    yarp::manager::ErrorLogger* logger  = yarp::manager::ErrorLogger::Instance();

    if(config.check("apppath")){
        string strPath;
        string appPaths(config.find("apppath").asString().c_str());
        while (appPaths!=""){
            string::size_type pos=appPaths.find(";");
            strPath=appPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str())){
                strPath=basepath+strPath;
            }

            if((strPath.rfind(PATH_SEPERATOR)==string::npos) ||
                (strPath.rfind(PATH_SEPERATOR)!=strPath.size()-1)){
                    strPath = strPath + string(PATH_SEPERATOR);
            }

            if(config.find("load_subfolders").asString() == "yes"){
                if(!loadRecursiveApplications(strPath.c_str())){
                    logger->addError("Cannot load the applications from  " + strPath);
                }                
                loadRecursiveTemplates(strPath.c_str());
                std::sort(templateList.begin(),
                          templateList.end(), AppTemplateCompare);
                std::vector<yarp::manager::AppTemplate>::iterator itr;
                for(itr=templateList.begin(); itr!=templateList.end(); itr++)
                    ui->entitiesTree->addAppTemplate(&(*itr));
            }
            else{
                lazyManager.addApplications(strPath.c_str());
            }
            if (pos==string::npos){
                break;
            }
            appPaths=appPaths.substr(pos+1);
        }
    }

    if (config.check("templpath")){
        string strPath;
        string templPaths(config.find("templpath").asString().c_str());
        while (templPaths!=""){
            string::size_type pos=templPaths.find(";");
            strPath=templPaths.substr(0, pos);
            yarp::manager::trimString(strPath);
            if (!isAbsolute(strPath.c_str())){
                strPath=basepath+strPath;
            }

            if(!loadRecursiveTemplates(strPath.c_str()))
                logger->addError("Cannot load the templates from  " + strPath);
            else {
                ui->entitiesTree->clearTemplates();
                std::sort(templateList.begin(),
                          templateList.end(), AppTemplateCompare);
                std::vector<yarp::manager::AppTemplate>::iterator itr;
                for(itr=templateList.begin(); itr!=templateList.end(); itr++)
                    ui->entitiesTree->addAppTemplate(&(*itr));
            }

            if (pos==string::npos){
                break;
            }
            templPaths=templPaths.substr(pos+1);
        }
    }

    if(config.check("external_editor")){
        ext_editor = config.find("external_editor").asString();
        ((EntitiesTreeWidget*)ui->entitiesTree)->setExtEditor(ext_editor);
    }else{
#if defined(WIN32)
        ext_editor = "notepad.exe";
#else
        ext_editor = "xdg-open";
#endif
    }

    reportErrors();

    syncApplicationList();

    if(config.check("application")){
        yarp::manager::XmlAppLoader appload(config.find("application").asString().c_str());
        if(!appload.init()){
            return;
        }
        yarp::manager::Application* application = appload.getNextApplication();
        if(!application){
            return;  // TODO far ritornare valore per chiudere in caso di errore
        }
        // add this application to the manager if does not exist
        if(!lazyManager.getKnowledgeBase()->getApplication(application->getName())){
            lazyManager.getKnowledgeBase()->addApplication(application);
            syncApplicationList();
        }
        //manageApplication(application->getName());
    }
}