Mickey::~Mickey() { if(linuxtrack_get_tracking_state() == RUNNING){ linuxtrack_suspend(); } updateTimer.stop(); delete trans; trans = NULL; btnThread.setFinish(); btnThread.wait(); }
int main(int argc, char *argv[]) { char *section = NULL;//"Default [ \nblablabla"; float heading, pitch, roll; float tx, ty, tz; unsigned int counter; int retval; if(argc > 1){ section = argv[1]; } printf("Section: %s\n", section); retval = linuxtrack_init(section); while(linuxtrack_get_tracking_state() == INITIALIZING){ ltr_int_usleep(333333); } if (retval != 0) { printf("Error %d detected! Aborting!\n", retval); return retval; }; printf("Trying to recenter!\n"); linuxtrack_recenter(); pthread_create(&reader, NULL, kbd_reader, NULL); unsigned int cntr=-1; while (!quit_flag) { retval = linuxtrack_get_pose (&heading,&pitch,&roll, &tx, &ty, &tz, &counter); if(retval < 0){ printf("Problem reading update!\n"); break; } if(cntr != counter){ cntr = counter; printf("hdg:%8.3f pitch:%8.3f roll:%8.3f ", heading, pitch, roll); printf("tx:%8.3f y:%8.3f z:%8.3f\n", tx, ty, tz); } ltr_int_usleep(100000); } pthread_join(reader, NULL); return 0; }
bool intialise_tracking(void) { linuxtrack_state_type state; // Initialize the tracking using Default profile state = linuxtrack_init(nullptr); if (state < LINUXTRACK_OK){ printf("%s\n", linuxtrack_explain(state)); return false; } int timeout = 0; // Wait up to 20 seconds for the tracker initialization while (timeout < 200){ state = linuxtrack_get_tracking_state(); printf("Status: %s\n", linuxtrack_explain(state)); if((state == RUNNING) || (state == PAUSED)){ return true; } usleep(100000); ++timeout; } printf("Linuxtrack doesn't work right!\n"); printf("Make sure it is installed and configured correctly.\n"); return false; }
void Mickey::updateTimer_activated() { static float heading_p = 0.0; static float pitch_p = 0.0; linuxtrack_pose_t full_pose; float blobs[3*3]; int blobs_read; //float heading, pitch, roll, tx, ty, tz; //unsigned int counter; static int lastTrackingState = -1; int trackingState = linuxtrack_get_tracking_state(); if(lastTrackingState != trackingState){ lastTrackingState = trackingState; if(trackingState == RUNNING){ switch(state){ case TRACKING: GUI.setStatusLabel(QString::fromUtf8("Tracking")); break; case CALIBRATING: GUI.setStatusLabel(QString::fromUtf8("Calibrating")); break; case STANDBY: GUI.setStatusLabel(QString::fromUtf8("Paused")); break; } }else{ switch(trackingState){ case INITIALIZING: GUI.setStatusLabel(QString::fromUtf8("Initializing")); break; case err_NOT_INITIALIZED: case err_SYMBOL_LOOKUP: case err_NO_CONFIG: case err_NOT_FOUND: case err_PROCESSING_FRAME: GUI.setStatusLabel(QString::fromUtf8("Error")); break; default: GUI.setStatusLabel(QString::fromUtf8("Inactive")); break; } } } if(trackingState != RUNNING){ return; } if(recenterFlag){ if(initTimer.elapsed() < settleTime){ return; }else{ linuxtrack_recenter(); recenterFlag = false; } } // if(linuxtrack_get_pose(&heading, &pitch, &roll, &tx, &ty, &tz, &counter) > 0){ if(linuxtrack_get_pose_full(&full_pose, blobs, 3, &blobs_read) > 0){ //new frame has arrived /*heading = full_pose.yaw; pitch = full_pose.pitch; roll = full_pose.roll; tx = full_pose.tx; ty = full_pose.ty; tz = full_pose.tz; counter = full_pose.counter; */ heading_p = full_pose.raw_yaw; pitch_p = full_pose.raw_pitch; //ui.XLabel->setText(QString("X: %1").arg(heading)); //ui.YLabel->setText(QString("Y: %1").arg(pitch)); } int elapsed = updateElapsed.elapsed(); updateElapsed.restart(); //reversing signs to get the cursor move according to the head movement float dx, dy; trans->update(heading_p, pitch_p, relative, elapsed, dx, dy); if(state == TRACKING){ if(relative){ int idx = (int)dx; int idy = (int)dy; if((idx != 0) || (idy != 0)){ mouse.move((int)dx, (int)dy); //QPoint pos = QCursor::pos(); //pos += QPoint(dx,dy); //QCursor::setPos(pos); } }else{ QPoint c = screenCenter + QPoint(screenCenter.x() * dx, screenCenter.y() * dy); QCursor::setPos(c); } } }