Example #1
0
/*
Enables all the trackers and sets the streaming frequency.
Note: Trackers according to VRPN and Trackers as defined by OWL
are two entirely different things.
*/
bool vrpn_Tracker_PhaseSpace::enableTracker(bool enable)
{
#ifdef DEBUG
  printf("%s %d\n", __PRETTY_FUNCTION__, enable);
#endif

  if(!owlRunning) return false;

  // Scale the reports for this tracker to be in meters rather than
  // in MM, to match the VRPN standard.
  owlScale(MM_TO_METERS);

  if(!slave) {
    int option = enable ? OWL_ENABLE : OWL_DISABLE;
    owlTracker(0,option); //enables/disables the point tracker
    if(!owlGetStatus())
      return false;

    //enable/disable the rigid trackers
    for(int i = 1; i <= numRigids; i++) {
      owlTracker(i,option);
      if(!owlGetStatus())
        return false;
    }
  }

  if(enable) {
    setFrequency(frequency);
    owlSetInteger(OWL_EVENTS, OWL_ENABLE);
    owlSetInteger(OWL_STREAMING,OWL_ENABLE);
    if(!owlGetStatus())
      return false;
    printf("Streaming enabled.\n");
  } else {
    owlSetInteger(OWL_EVENTS, OWL_DISABLE);
    owlSetInteger(OWL_STREAMING,OWL_DISABLE);
    if(!owlGetStatus())
      return false;
    printf("Streaming disabled.\n");
  }
  return true;
}
void PhasespaceCore::initializeCommunication() {
  ROS_INFO_STREAM("[PhaseSpace] Initalizing the PhaseSpace...");

  // opens a socket and configures the communication channels to pass data between the OWL server and client; this
  // function will block until there is a connection or an error; returns the passed flags if OK
  if (owlInit(server_ip_.c_str(), init_flags_) < 0) {
    ROS_FATAL_STREAM("[PhaseSpace] Can't initialize the communication with OWL server: " << owlGetError());
    throw excp_;
  }

  // initializes a point tracker:
  //  - OWL_CREATE: tells the system to create a tracker
  //  - OWL_POINT_TRACKER: specifies the creation of a point tracker
  owlTrackeri(tracker_, OWL_CREATE, OWL_POINT_TRACKER);

  // creates the marker structures, each with the proper id:
  //  - MARKER Macro: builds a marker id out of a tracker id and marker index
  //  - OWL_SET_LED: the following 'i' is an integer representing the LED ID of the marker
  for (int i=0; i<init_marker_count_; i++) {
    owlMarkeri(MARKER(tracker_, i), OWL_SET_LED, i);
  }

  // enables the tracker (it has to be disabled when the markers have to be added)
  owlTracker(tracker_, OWL_ENABLE);

  // checking the status will block until all commands are processed and any errors are sent to the client
  if (!owlGetStatus()) {
    ROS_FATAL_STREAM("[PhaseSpace] Initialization generic error: " << owlGetError());
    throw excp_;
  }

  // sets frequency with default maximum value (OWL_MAX_FREQUENCY = 480 Hz):
  //  - OWL_FREQUENCY: specifies the rate at which the server streams data
  owlSetFloat(OWL_FREQUENCY, OWL_MAX_FREQUENCY);
  // enables the streaming of data
  owlSetInteger(OWL_STREAMING, OWL_ENABLE);
}