NaviTrack Tutorial:Integrating:Passing coordinates data

From NAMIC Wiki
Jump to: navigation, search
Home < NaviTrack Tutorial:Integrating:Passing coordinates data

What you need to do

  1. Create NaviTrack module to provide a node that can be accessed by you application.
  2. Modify your application to push and pull NaviTrack events cyclically with certain interval.
  3. Create NaviTrack configuration XML file to build tree structure of data flow.

Sending side

Modify MyTutorialModule

To send data through NaviTrack, it is necessary to generate a new event, which contains the data. The following code is implemented into MyTutorialModule to be called from your application.

void MyTutorialModule::setTracker(std::vector<float> pos,std::vector<float> quat)
{
  if (pos.size() != 3 || quat.size() != 4) {
    std::cout << "MyTutorialModule::setTracker(): illegal vector size." << std::endl;
    return;
  }

  if(source!=NULL)
    {
      ot::Event *event = new ot::Event();
      event->setAttribute("position",pos);
      event->setAttribute("orientation",quat);
      event->timeStamp();
      source->updateObservers( *event );
    }
}

pushpos.cxx

Receiving side

Modify MyTutorialSink and MyTutorialModule

An event to pull coordinate data is handled in onEventGenerated() function in MyTutorialSink. There are two steps to pass the coordinate data to your application: STEP 1) onEventGenerated() stores the data into member variables in MyTutorialSinke; STEP 2) your application fetch the data from MyTutorialSink through MyTutorialModule.

Bellows are examples to implement STEP 1 and STEP 2.

MyTutorialSink.h: Add member variables to hold the coordinate data:

 private:
   std::vector<float> position;
   std::vector<float> orientation;

MyTutorialSink.cxx:

 void MyTutorialSink::onEventGenerated( Event& event, Node& generator)
 {
   if (event.hasAttribute("position"))
     for(int i = 0; i < 3; i ++)
       position[i]=event.getPosition()[i];
   else
     {
       position[0]=0.0;
       position[1]=0.0;
       position[2]=0.0;
     }
 
   if (event.hasAttribute("orientation"))
     {
       for  (int i = 0; i < 4; i ++) {
         orientation[i]= event.getOrientation()[i];
       }
       std::cout << "orientation !!!" << std::endl;
     }
   else
     {
       orientation[0]=0.0;
       orientation[1]=0.0;
       orientation[2]=0.0;
       orientation[3]=0.0;
     }
 }

MyTutorialModule.cxx (and .h): add the follwing function:

 void MyTutorialModule::getTracker(std::vector<float>& pos,std::vector<float>& quat)
 {
   //std::cout << "MyTutorialModule::getTracker() is called." << std::endl;
 
   if(sink!=NULL)
     {
       sink->getTracker(pos, quat);
     }
 }

pullpos.cxx

Testing

Let's try to send position data from pushpos to pullpos program through network.

Configure NaviTrack XML files

tutorial_source.xml (for pushpos)

tutorial_sink.xml (for pullpos)

Run the programs

Open two terminals and go to the directory where the programs exists.

Terminal 1 (pushpos: sending side)

$ ./pushpos tutorial_source.xml

Terminal 2 (pullpos: receiving side)

$ ./pullpos tutorial_sink.xml





Back to Integrating into your application.