int main(int argc, char *argv[]) {
  /* define variables */
  WbDeviceTag turret_sensor;
  double perf_data[3];
  double clock = 0;

  /* initialize Webots */
  wb_robot_init();
  
  // read robot id from the robot's name
  char* robot_name;
  robot_name=(char*) wb_robot_get_name(); 
  sscanf(robot_name,"e-puck%d",&robot_id);
  
  emitter = wb_robot_get_device("emitter");
  wb_emitter_set_range(emitter,COM_RANGE);
  receiver = wb_robot_get_device("receiver");
  wb_receiver_set_channel(receiver,0);
  wb_receiver_enable(receiver,TIME_STEP);

  wb_robot_step(TIME_STEP);
  
  turret_sensor = wb_robot_get_device("ts");
  wb_light_sensor_enable(turret_sensor,TIME_STEP);    

  /* main loop */
  while (wb_robot_step(TIME_STEP) != -1) {
    clock += (double)TIME_STEP/1000;
    /* get light sensor value */
    sensor_value = wb_light_sensor_get_value(turret_sensor);

    if(wb_receiver_get_queue_length(receiver) > 0) {
      wb_emitter_set_channel(emitter,3);
      perf_data[0] = (double)robot_id;
      perf_data[1] = (double)(pkt_count-1);
      perf_data[2] = 0;
      wb_emitter_send(emitter,perf_data,3*sizeof(double));
      break; // stop node
    }
    else {
      send_data(clock); // send measurement data
    }
  }
  wb_robot_cleanup();

  return 0;
}
예제 #2
0
void reset()
{
  int i;
  robotName = wb_robot_get_name();
  currentState = FORWARD;

  // Make sure to initialize the RNG with different values for each thread
  srand(time(NULL) + (int)&robotName);

  char e_puck_name[] = "ps0";
  char sensorsName[5];

  // Emitter and receiver device tags
  emitterTag = wb_robot_get_device("emitter");
  receiverTag = wb_robot_get_device("receiver");

  // Configure communication devices
  wb_receiver_enable(receiverTag, TIME_STEP);
  wb_emitter_set_range(emitterTag, COMM_RADIUS);
  wb_emitter_set_channel(emitterTag, COMMUNICATION_CHANNEL);
  wb_receiver_set_channel(receiverTag, COMMUNICATION_CHANNEL);

  sprintf(sensorsName, "%s", e_puck_name);
  for (i = 0; i < NB_SENSORS; i++) {
    sensors[i] = wb_robot_get_device(sensorsName);
    wb_distance_sensor_enable(sensors[i], TIME_STEP);

    if ((i + 1) >= 10) {
      sensorsName[2] = '1';
      sensorsName[3]++;

      if ((i + 1) == 10) {
        sensorsName[3] = '0';
        sensorsName[4] = (char) '\0';
        }
    } else {
        sensorsName[2]++;
    }
  }

  wb_differential_wheels_enable_encoders(TIME_STEP);

  printf("Robot %s is reset\n", robotName);
  return;
}