Difference between revisions of "NaviTrack Tutorial:Creating module:Testing"

From NAMIC Wiki
Jump to: navigation, search
Line 20: Line 20:
  
 
=Testing MyTutorialSource=
 
=Testing MyTutorialSource=
 
+
'''Make sure your LD_LIBRARY_PATH (Linux) or PATH (Windows) contains the absolute path for NaviTrack library (libNaviTrack.so on Linux, and NaviTrack.dll on Windows)''' <br>
 
Let us see how MyTutorialSource works by sending coordinate data
 
Let us see how MyTutorialSource works by sending coordinate data
 
generated by MyTutorialSource to another NaviTrack.
 
generated by MyTutorialSource to another NaviTrack.

Revision as of 14:11, 18 May 2007

Home < NaviTrack Tutorial:Creating module:Testing

NaviTrack configuration files

In this testing, we use three NaviTrack configuration files included in the sample source codes archive that you have already downloaded. (File:NTTutorial May2007.zip)

tutorial_consolesink.xml

This file is used to receive coordinate data from NetworkSink and display the value onto a console by using ConsoleSink.

tutorial_source.xml

This file is used to send coordinate data, which is generated by pushEvent() in MyTutorialModule, to other hosts, by using NetworkSink.

tutorial_sink.xml

This file is used to receive coodinate data from NetworkSink and display the value onto a console by using MyTutorialSink.

Testing MyTutorialSource

Make sure your LD_LIBRARY_PATH (Linux) or PATH (Windows) contains the absolute path for NaviTrack library (libNaviTrack.so on Linux, and NaviTrack.dll on Windows)
Let us see how MyTutorialSource works by sending coordinate data generated by MyTutorialSource to another NaviTrack.

In a console, run:

$ middleware tutorial_consolesink.xml

and in another console, run:

$ middleware tutorial_source.xml

Then you can see coordinate values are varying on the console, where you run a NaviTrack with tutorial_consolesink.xml.

In this testing, the essential part of generating cordinate values is in pushEvent() of MyTutorialSource.cxx. In this function, you could see the following code:

void MyTutorialModule::pushEvent()
{
  if(source)
    {
      std::cout << "MyTutorialModule::pushEvent() is called." << std::endl;
      source->event.getPosition()[0] += 0.01;
      source->event.getPosition()[1] += 0.02;
      source->event.getPosition()[2] += 0.03;
      source->event.getOrientation()[0] += 0.01;
      source->event.getOrientation()[1] += 0.02;
      source->event.getOrientation()[2] += 0.03;
      source->event.getOrientation()[3] += 0.04;
      
      source->event.timeStamp();
      source->updateObservers( source->event );
    }
}

Testing MyTutorialSink

Next, we use MyTutorialSink instead of ConsoleSink. Stop the NaviTrack launched with tutorial_consolesink.xml and, run:

$ middleware tutorial_sink.xml

In this case, you could see the output from MyTutorialSink.

The actual code to display coordinate data is in onEventGenerated() of MyTutorialSink. The following code is implemented in this function:

void MyTutorialSink::onEventGenerated( Event& event, Node& generator)
 {
   float orientation[4];
   float position[3];
 
   if (event.hasAttribute("orientation"))
     {
       for  (int i = 0; i < 4; i ++)
         orientation[i]=-event.getOrientation()[i];
     }
   else
     {
       orientation[0]=0.0;
       orientation[1]=1.0;
       orientation[2]=0.0;
       orientation[3]=0.0;
     }
   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;
     }
   std::cout << "MyTutorialSink::onEventGenerated(): pos = ("
             << position[0] << ", " << position[1] << ", " << position[2] << ")"
             << std::endl;
   std::cout << "MyTutorialSink::onEventGenerated(): ori = ("
             << orientation[0] << ", " << orientation[1] << ", " << orientation[2] << ","
             << orientation[3] << ")"  << std::endl;
   
 }