Esempio n. 1
0
bool Settings::load()
{
#ifdef TARGET_ROBOT
  robot = NaoBody().getName();
#else
  robot = "Nao";
#endif

  bool loadedSettingsFromFile = false;
#ifdef TARGET_ROBOT
  // load settings from team.cfg
  try
  {
    ConfigMap teams;
    if(teams.read("teams.cfg", false, &ConfigMap::printOnErr) >= 0)
    {
      teams.setFlags(teams.getFlags() | ConfigMap::READONLY);

      std::vector<std::string> keys = teams.getKeys();
      for(std::vector<std::string>::const_iterator i = keys.begin(), end = keys.end(); i != end; ++i)
      {
        const ConfigValue& teamValue = teams[*i];
        if(teamValue.getType() != ConfigValue::MAP)
          continue;
        const ConfigMap& team = teamValue;
        if(!team.hasKey("players"))
          continue;
        const ConfigValue& playersValue = team["players"];
        if(playersValue.getType() != ConfigValue::LIST)
          continue;

        const ListConfigValue& players = playersValue;
        for(int i = 0, len = players.length(); i < len; ++i)
        {
          const ConfigValue& playersValue = players[i];
          if(playersValue.getType() != ConfigValue::PLAIN)
            continue;
          if(((const PlainConfigValue&)playersValue).str() == robot)
          {
            playerNumber = i + 1;
            team["number"] >> teamNumber;
            teamPort = 10001 + teamNumber * 100;
            team["location"] >> location;
            std::string entryName;
            team["color"] >> entryName;
            if(entryName == "blue")
              teamColor = TEAM_BLUE;
            else if(entryName == "red")
              teamColor = TEAM_RED;
            else
              ASSERT(false);
            loadedSettingsFromFile = true;
            goto loadedTeamsCfg;
          }
        }
      }
loadedTeamsCfg:
      ;
    }
Esempio n. 2
0
void BallPerceptor::init(const FieldDimensions& theFieldDimensions)
{
  sqrMaxBallDistance = float(Vector2<int>(theFieldDimensions.xPosOpponentFieldBorder - theFieldDimensions.xPosOwnFieldBorder,
                                          theFieldDimensions.yPosLeftFieldBorder - theFieldDimensions.yPosRightFieldBorder).squareAbs());

  /*
  cout << "theFieldDimensions.xPosOpponentFieldBorder: " << theFieldDimensions.xPosOpponentFieldBorder << endl;
  cout << "theFieldDimensions.xPosOwnFieldBorder:      " << theFieldDimensions.xPosOwnFieldBorder      << endl;
  cout << "theFieldDimensions.yPosLeftFieldBorder:     " << theFieldDimensions.yPosLeftFieldBorder     << endl;
  cout << "theFieldDimensions.yPosRightFieldBorder:    " << theFieldDimensions.yPosRightFieldBorder    << endl;
 */

  ConfigMap params;
  params["clippingApproxRadiusScale"] << 2.f;
  params["clippingApproxRadiusPixelBonus"] << 2.5f;

  params["scanMaxColorDistance"] << (unsigned int) 30;
  params["scanPixelTolerance"] << (unsigned int) 2;

  params["refineMaxPixelCount"] << (unsigned int) 2;
  params["refineMaxColorDistance"] << (unsigned int) 40;

  params["checkMaxRadiusDifference"] << 1.6f;
  params["checkMinRadiusDifference"] << 0.9f;
  params["checkMinRadiusPixelBonus"] << 6.f;

  params["checkOutlineRadiusScale"] << 1.1f;
  params["checkOutlineRadiusPixelBonus"] << 2.f;

  //params.read(Global::getSettings().expandRobotLocationFilename("ballPerceptor.cfg"));
  params.read("/home/nao/.config/naoqi/Data/Config/Locations/Default/Robots/Nao/ballPerceptor.cfg");

  params["clippingApproxRadiusScale"] >> p.clippingApproxRadiusScale;
  params["clippingApproxRadiusPixelBonus"] >> p.clippingApproxRadiusPixelBonus;

  params["scanMaxColorDistance"] >> p.scanMaxColorDistance;
  params["scanPixelTolerance"] >> p.scanPixelTolerance;

  params["refineMaxPixelCount"] >> p.refineMaxPixelCount;
  params["refineMaxColorDistance"] >> p.refineMaxColorDistance;

  params["checkMaxRadiusDifference"] >> p.checkMaxRadiusDifference;
  params["checkMinRadiusDifference"] >> p.checkMinRadiusDifference;
  params["checkMinRadiusPixelBonus"] >> p.checkMinRadiusPixelBonus;

  params["checkOutlineRadiusScale"] >> p.checkOutlineRadiusScale;
  params["checkOutlineRadiusPixelBonus"] >> p.checkOutlineRadiusPixelBonus;
}
bool ColorTableCreator::loadTrainingData(string fileName)
{
  handMadeClassification.clear();
  ConfigMap cm;
  if(cm.read(fileName) < 0)
    return false;

  try
  {
    cm["handMadeClassification"] >> handMadeClassification;
  }
  catch(std::invalid_argument e)
  {
    return false;
  } //In this case the Vector was empty

  return true;
}
Esempio n. 4
0
std::vector<Robot> Robot::getRobots()
{
  std::vector<Robot> robots;
  std::string robotsDir = "Robots";
  Directory d;
  if(d.open(*File::getFullNames(robotsDir).begin() + "/*"))
  {
    std::string dir;
    bool isDir;
    while(d.read(dir, isDir))
    {
      if(isDir)
      {
        ConfigMap cm;
        std::string s = linuxToPlatformPath(dir + "/robot.cfg");
        int status = cm.read(s);
        if(status > 0)
        {
          Robot r;
          cm >> r;
          robots.push_back(r);
        }
      }
    }