Example #1
0
std::vector<Vec2> DebugMap::getOpenTiles( Vec2 coord ){
    std::vector<Vec2> result;
    
    // 검색결과 저장 및 재검색때 사용하는 코드 추가
    
    // 중심을 기준으로 4방향중 이동가능한 타일 좌표를 추출
    Vec2 t = Vec2( coord.x, coord.y+1 );
    Vec2 r = Vec2( coord.x+1, coord.y );
    Vec2 b = Vec2( coord.x, coord.y-1 );
    Vec2 l = Vec2( coord.x-1, coord.y );
    
    if( !isMarkedCoord( t ) &&  checkLoad( coord.x, coord.y, t.x, t.y ) == D::PASS ) result.push_back( t );
    if( !isMarkedCoord( r ) &&  checkLoad( coord.x, coord.y, r.x, r.y ) == D::PASS ) result.push_back( r );
    if( !isMarkedCoord( b ) &&  checkLoad( coord.x, coord.y, b.x, b.y ) == D::PASS ) result.push_back( b );
    if( !isMarkedCoord( l ) &&  checkLoad( coord.x, coord.y, l.x, l.y ) == D::PASS ) result.push_back( l );
    
    return result;
}
void GroundContactDetector::update(GroundContactState& groundContactState)
{
  MODIFY("module:GroundContactDetector:parameters", p);
  PLOT("module:GroundContactDetector:groundContact", groundContactState.contact ? 0.75 : 0.25);

#ifdef TARGET_ROBOT
  if(p.forceContact)
#endif
  {
    groundContactState.contact = true;
    //groundContactState.contactSafe = true;
    return;
  }

  // states
  ContactState stateFsrLeft = checkFsr(true);
  ContactState stateFsrRight = checkFsr(false);
  ContactState stateLoad = checkLoad();
  // contact plots
  PLOT("module:GroundContactDetector:contactLoad", stateLoad.contact ? 0.75 : 0.25);
  PLOT("module:GroundContactDetector:contactFsrLeft", stateFsrLeft.contact ? 0.75 : 0.25);
  PLOT("module:GroundContactDetector:contactFsrRight", stateFsrRight.contact ? 0.75 : 0.25);
  // confidence plots
  PLOT("module:GroundContactDetector:confidenceLoad", stateLoad.confidence);
  PLOT("module:GroundContactDetector:confidenceFsrLeft", stateFsrLeft.confidence);
  PLOT("module:GroundContactDetector:confidenceFsrRight", stateFsrRight.confidence);

  float confidenceContact = 0.f;
  float confidenceNoContact = 0.f;
  if(stateFsrLeft.contact) confidenceContact += stateFsrLeft.confidence;
  else confidenceNoContact += stateFsrLeft.confidence;
  if(stateFsrRight.contact) confidenceContact += stateFsrRight.confidence;
  else confidenceNoContact += stateFsrRight.confidence;
  if(stateLoad.contact) confidenceContact += stateLoad.confidence;
  else confidenceNoContact += stateLoad.confidence;

  confidenceContactBuffer.add(confidenceContact);
  confidenceNoContactBuffer.add(confidenceNoContact);
  if(confidenceContactBuffer.getSum() >= BUFFER_SIZE * p.contactThreshold)
    contact = true;
  else if(confidenceNoContactBuffer.getSum() >= BUFFER_SIZE * p.noContactThreshold)
    contact = false;

  groundContactState.contact = contact || theMotionRequest.motion == MotionRequest::specialAction || theMotionInfo.motion == MotionRequest::specialAction;
  PLOT("module:GroundContactDetector:contactThreshold", BUFFER_SIZE * p.contactThreshold);
  PLOT("module:GroundContactDetector:noContactThreshold", BUFFER_SIZE * p.noContactThreshold);
  PLOT("module:GroundContactDetector:confidenceContact", confidenceContactBuffer.getSum());
  PLOT("module:GroundContactDetector:confidenceNoContact", confidenceNoContactBuffer.getSum());

  if((contact && !lastContact) || (contact && contactStartTime == 0))
    contactStartTime = theFrameInfo.time;
  //groundContactState.contactSafe = contact && theFrameInfo.getTimeSince(contactStartTime) >= p.safeContactTime;
  if(!contact && lastContact)
  {
#ifndef TARGET_SIM
    if(contactStartTime != 0 && theMotionInfo.motion == MotionRequest::walk)
      SoundPlayer::play("high.wav");
#endif
  }

  lastContact = contact;
}
/*
 * main function : -> parse command line args
 * 		   -> open SNMP session
 */
int
main (int argc, char *argv[])
{
  netsnmp_session session, *ss = NULL;
  int opt;
  int exitcode = UNKNOWN;
  char *community = NULL;
  char *hostname = NULL;
  char *bn = argv[0];
  int timeout = 0;
  int version = SNMP_VERSION_1;
  char *token;

  /* Print the help if not arguments provided */ 
  if(argc==1) {
	usage();
	return(UNKNOWN);
  }
  /*
   * get the common command line arguments 
   */

  while ((opt = getopt (argc, argv, "?hVdvt:w:c:m:C:H:s:")) != -1)
    {
      switch (opt)
	{
	case '?':
	case 'h':
	  /* print help */
	  usage ();
	  exit (UNKNOWN);

	case 'V':
	  print_version ();
	  exit (UNKNOWN);
	
	case 'd':
	  perfdata = 1;
	  break;

	case 't':
	  /* Timeout */
	  if (!is_integer (optarg))
	    {
	      printf ("Timeout interval (%s)must be integer!\n", optarg);
	      exit (UNKNOWN);
	    }

	  timeout = atoi (optarg);
	  if (verbose)
	    printf ("%s: Timeout set to %d\n", bn, timeout);
	  break;

	case 'C':
	  /* SNMP Community */
	  community = strdup (optarg);

	  if (verbose)
	    printf ("%s: Community set to %s\n", bn, community);

	  break;

	case 'H':
	  /* SNMP Hostname */
	  hostname = strdup (optarg);

	  if (verbose)
	    printf ("%s: Hostname set to %s\n", bn, hostname);

	  break;

	case 'v':
	  /* Verbose mode */
	  verbose = 1;
	  printf ("%s: Verbose mode\n", bn);
	  break;

	case 'm':
	  /* WINDOWS / LINUX Check style */
	  if (strcmp (optarg, "W") == 0)
	    {
	      style = WINDOWS;
	    }
	  else if (strcmp (optarg, "L") == 0)
	    {
	      style = LINUX;
	    }
	  else
	    {
	      printf
		("Format : -m [W|L]  : -m W for windows\t -m L for Linux\n");
	    }

	  break;

	case 's':
	  /* SNMP Version */
	  if (strcmp (optarg, "2c") == 0)
	    {
	      version = SNMP_VERSION_2c;
	    }
	  else if (strcmp (optarg, "1") == 0)
	    {
	      version = SNMP_VERSION_1;
	    }
	  else
	    {
	      printf
		("Sorry, only SNMP vers. 1 and 2c are supported at this time\n");
	      exit (UNKNOWN);
	    }
	  break;

	case 'w':
	  /* ARGS for warning min */
	  if (strlen (optarg) <= 3)	/* Percent limit */
	    {
	      warningmin[0] = atoi (optarg);
	      /* In order to check the type of limit entered */
	      warningmin[1] = 9999;
	      break;
	    }
	  else if (strlen (optarg) <= 8)	/* Load averages limits */
	    {
	      token = strtok (optarg, ",");
	      warningmin[0] = atoi (token);
	      if ((token = strtok (NULL, ",")) != NULL)
		{
		  warningmin[1] = atoi (token);
		}

	      if ((token = strtok (NULL, ",")) != NULL)
		{
		  warningmin[2] = atoi (token);
		  break;
		}
	    }

	  printf ("Format : -w xx or -w xx,xx,xx\n");
	  exit (UNKNOWN);

	  break;

	case 'c':
	  /* CRITICAL min */
	  if (strlen (optarg) <= 3)	/* Percent limit */
	    {
	      criticalmin[0] = atoi (optarg);
	      /* In order to check the type of limit entered */
	      criticalmin[1] = 9999;
	      break;
	    }
	  else if (strlen (optarg) <= 8)	/* Load averages limits */
	    {
	      /* Separate with delimiter , */
	      token = strtok (optarg, ",");
	      criticalmin[0] = atoi (token);
	      if ((token = strtok (NULL, ",")) != NULL)
		{
		  criticalmin[1] = atoi (token);
		}

	      if ((token = strtok (NULL, ",")) != NULL)
		{
		  criticalmin[2] = atoi (token);
		  break;
		}
	    }

	  printf ("Format : -c xx or -c xx,xx,xx\n");
	  exit (UNKNOWN);

	  break;



	}
    }
  /* If no style set */
  if (style == 3)
    {
      printf
	("You must choose between linux / windows monitoring ( -m L or -m W)\n");
      exit (UNKNOWN);
    }
  else if ((style == WINDOWS)
	   && ((warningmin[1] != 9999) || (criticalmin[1] != 9999)))
    {
      printf
	("If you choose -m W, you must set -w xx and -c xx (xx = limit in percent\n");
      exit (UNKNOWN);

    }
  else if ((style == LINUX)
	   && ((warningmin[1] == 9999) || (criticalmin[1] == 9999)))
    {
      printf
	("If you choose -m L, you must set -w xx,xx,xx and -c xx,xx,xx\n (xx,xx,xx = limits for load average 1,5,15 minutes\n");
      exit (UNKNOWN);
    }

  if ((warningmin[0] == -1) || (criticalmin[0] == -1))
    {
      printf ("Must set the warning and critical values (-w and -c)\n");
      exit (UNKNOWN);


    }

  if (warningmin[0] > criticalmin[0])
    {
      printf ("warning minimum must be lower than critical minimum\n");
      exit (UNKNOWN);
    }




  if (!hostname || !community)
    {
      printf ("Both Community and Hostname must be set\n");
      exit (UNKNOWN);

    }


  snmp_sess_init (&session);

  init_snmp ("check_load");

  session.version = version;

  session.peername = hostname;
  session.community = (unsigned char *) community;
  session.community_len = strlen (community);

  if (timeout)
    session.timeout = timeout * 1000000L;



  SOCK_STARTUP;

  /*
   * open an SNMP session 
   */
  ss = snmp_open (&session);
  if (ss == NULL)
    {
      /*
       * diagnose snmp_open errors with the input netsnmp_session pointer 
       */
      snmp_sess_perror ("snmp_check_process", &session);
      SOCK_CLEANUP;
      exit (UNKNOWN);
    }

  exitcode = checkLoad (ss);

  snmp_close (ss);

  SOCK_CLEANUP;

  free (community);
  free (hostname);

  return exitcode;
}