Page 1 of 1

polling data issue (with source code)

PostPosted: 05 Mar 2014, 07:20
by wxz
hi,

I'm trying to manually poll data by calling gtl::GazeApi's get_frame() method. The code below shows details. The output on the console shows that the eye tracker was successfully connect. However, the retrieved data is garbage. What did I miss?

Code: Select all
// GazeDataCollector.h
#pragma once
#include "../include/gazeapi_interfaces.h"
#include "../include/gazeapi.h"

class GazeDataCollector : public gtl::IGazeListener
{
public:
   GazeDataCollector(void);
   ~GazeDataCollector(void);

   bool Connect();
   void Disconnect();
   bool GetFrame();

private:
   void on_gaze_data(gtl::GazeData const &gaze_data);

   gtl::GazeApi m_gApi;
   bool connected;
   gtl::GazeData data_;
};


Code: Select all
//GazeDataCollector.cpp
#include "GazeDataCollector.h"
#include <iostream>

GazeDataCollector::GazeDataCollector(void) : connected(false)
{
   std::cout << "constructor" << std::endl;
}


GazeDataCollector::~GazeDataCollector(void)
{
   if(connected)
      Disconnect();
   std::cout << "destructor" << std::endl;
}

bool GazeDataCollector::Connect()
{
   if(m_gApi.connect() )
   {
      m_gApi.add_listener(*this);
      m_gApi.set_push(false);
      connected = true;
      return true;
   }
   return false;
}

bool GazeDataCollector::GetFrame()
{
   m_gApi.get_frame(data_);
   if(data_.state & gtl::GazeData::GD_STATE_TRACKING_GAZE)
   {
      gtl::Point2D const & smoothedCoordinates = data_.avg;
      std::cout << "data received. " << smoothedCoordinates.x << ", " << smoothedCoordinates.y << std::endl;
   }

   return false;
}

void GazeDataCollector::Disconnect()
{
   m_gApi.remove_listener(*this);
   m_gApi.disconnect();
}

void GazeDataCollector::on_gaze_data(gtl::GazeData const &gaze_data)
{
   if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
    {
        gtl::Point2D const & smoothedCoordinates = gaze_data.avg;

        // Move GUI point, do hit-testing, log coordinates, etc.
      std::cout << "data received. " << smoothedCoordinates.x << ", " << smoothedCoordinates.y << std::endl;
    }
}


Code: Select all
#include "GazeDataCollector.h"
#include <iostream>
#include "stdlib.h"

int main()
{
   GazeDataCollector gaze;

   if(gaze.Connect())
   {
      std::cout << "Connected." << std::endl;
      std::cout << "start loop" << std::endl;
      for(int i=0; i<50; i++)
      {
         gaze.GetFrame();
         _sleep(30);   // pause for 30 ms
      }
      std::cout << "end loop" << std::endl;
   }

   return 0;
}

Re: polling data issue (with source code)

PostPosted: 05 Mar 2014, 17:41
by Martin
Looking into this and will get back to you asap.

Re: polling data issue (with source code)

PostPosted: 05 Mar 2014, 18:00
by Martin
Ok, found the issue. The call to get_frame doesn't populate the gaze data object passed to the method. What the method currently does is to send a request to the server for the latest data. The data will then be delivered by the listener callback once it arrives.

The next update for the C++ SDK will make all get-data calls to the server in blocking-mode so that it returns upon calling like it should.

Sorry for the inconvenience.

Re: polling data issue (with source code)

PostPosted: 05 Mar 2014, 18:33
by mingxinbit
I suggest you can modify the MyGaze class code in the part of CallBack function.

Whatever, I think the CallBack function used in C plus plus for receiving data is good. You can add some variables used for gaze data return, then you received the data in your main function.

Do you think?

Re: polling data issue (with source code)

PostPosted: 05 Mar 2014, 19:07
by wxz
the callback is the next to try on my list.
Thanks for your swift reply Martin!
The eye tribe eye tracker is as accurate as any other eye trackers I've used before, yet with a much consumer-friendly price tag. Great work!