Exemple #1
0
int main(int argc, char* argv[])
{
   // Version number of the NatNet protocol, as reported by the server.
   unsigned char natNetMajor;
   unsigned char natNetMinor;
   
   // Sockets
   int sdCommand;
   int sdData;
   
   // Catch ctrl-c and terminate gracefully.
   signal(SIGINT, terminate);
   
   // Set addresses
   readOpts( argc, argv );
   // Use this socket address to send commands to the server.
   struct sockaddr_in serverCommands = NatNet::createAddress(Globals::serverAddress, NatNet::commandPort);
   
   // Create sockets
   sdCommand = NatNet::createCommandSocket( Globals::localAddress );
   sdData = NatNet::createDataSocket( Globals::localAddress );
   
   // Start the CommandListener in a new thread.
   CommandListener commandListener(sdCommand);
   commandListener.start();

   // Send a ping packet to the server so that it sends us the NatNet version
   // in its response to commandListener.
   NatNetPacket ping = NatNetPacket::pingPacket();
   ping.send(sdCommand, serverCommands);
   
   // Wait here for ping response to give us the NatNet version.
   commandListener.getNatNetVersion(natNetMajor, natNetMinor);
   
   // Start up a FrameListener in a new thread.
   FrameListener frameListener(sdData, natNetMajor, natNetMinor);
   frameListener.start();
   
   // This infinite loop simulates a "worker" thread that reads the frame
   // buffer each time through, and exits when ctrl-c is pressed.
   printFrames(frameListener);
   //timeStats(frameListener);
   
   // Wait for threads to finish.
   frameListener.stop();
   commandListener.stop();
   frameListener.join();
   commandListener.join();
   
   // Epilogue
   close(sdData);
   close(sdCommand);
   return 0;
}
int main(int argc, char* argv[])
{
  // Initialization
  ros::init(argc, argv, "pub_mocap_data");
  ros::NodeHandle nh;
  ros::Publisher pub_mocap_data = nh.advertise<geometry_msgs::PoseWithCovarianceStamped>("pub_mocap_data/data", 1000); 
  pos_x = 0;
  pos_y = 0;
  pos_z = 0;
	
  roll = 0;
  pitch = 0;
  yaw = 0;
  
  /*************************** Data Log ****************************/
  //Create the name of data log
  /*char text[200];
  time_t now  = time(NULL);
  struct tm *t  = localtime(&now);
  strftime(text,sizeof(text)-1,"%Y%m%d-%H%M%S",t);
  ostringstream fn;
  fn << "./" << text << ".txt";
  string filename = fn.str();

  // Convert string to char array
  char* fnstr  = new char[filename.size()+1];
  fnstr[filename.size()] = 0;
  memcpy(fnstr,filename.c_str(),filename.size());
  output_file.open(fnstr);
  * /
  /************************** End Data Log *************************/

	
  // Version number of the NatNet protocol, as reported by the server.
  unsigned char natNetMajor;
  unsigned char natNetMinor;
  
  // Sockets
  int sdCommand;
  int sdData;
   
  // Catch ctrl-c and terminate gracefully.
  signal(SIGINT, terminate);
  
  // Set addresses
  readOpts( argc, argv );
  // Use this socket address to send commands to the server.
  struct sockaddr_in serverCommands = NatNet::createAddress(Globals::serverAddress, NatNet::commandPort);
  
  // Create sockets
  sdCommand = NatNet::createCommandSocket( Globals::localAddress );
  sdData = NatNet::createDataSocket( Globals::localAddress );
  
  // Start the CommandListener in a new thread.
  CommandListener commandListener(sdCommand);
  commandListener.start();
  
  // Send a ping packet to the server so that it sends us the NatNet version
  // in its response to commandListener.
  NatNetPacket ping = NatNetPacket::pingPacket();
  ping.send(sdCommand, serverCommands);
   
  // Wait here for ping response to give us the NatNet version.
  commandListener.getNatNetVersion(natNetMajor, natNetMinor);
   
  // Start up a FrameListener in a new thread.
  FrameListener frameListener(sdData, natNetMajor, natNetMinor);
  frameListener.start();
  
  // This infinite loop simulates a "worker" thread that reads the frame
  // buffer each time through, and exits when ctrl-c is pressed.
  ReceiveFrames(frameListener,pub_mocap_data);
  //timeStats(frameListener);
   
  // Wait for threads to finish.
  frameListener.stop();
  commandListener.stop();
  frameListener.join();
  commandListener.join();
  
  // Epilogue
  close(sdData);
  close(sdCommand);
  
  return 0;
}