@@ -48,13 +48,14 @@ void MyListener::OnTrackerData(const PSTech::pstsdk::TrackerData& td)
4848 // Unlocked automaically when the mutex goes out of scope
4949 const std::lock_guard<std::mutex> lock (mtx);
5050
51- pstToQtMatrix (mat, targetMatrices[index]);
51+ pstToQtMatrix (mat, targetMatrices[index]);
5252
5353 }
5454
5555 }
5656
5757}
58+
5859QMatrix4x4 MyListener::getTragetMatrix (const int & index) const {
5960 const std::lock_guard<std::mutex> lock (mtx);
6061 // If the viewer instance is greater than the number of targets, just use the last target
@@ -96,6 +97,14 @@ static void Exithandler(int sig)
9697
9798
9899PSTracker::PSTracker (QObject *parent) : QObject(parent) {
100+ connectionTimer = new QTimer (this );
101+ connect (connectionTimer, &QTimer::timeout, this , [this ]() {
102+ qDebug () << " Checking connection" ;
103+ if (!checkTrackerStatus ()) {
104+ emit stopped ();
105+ }
106+ connectionTimer->stop ();
107+ });
99108 // Register the exit handler with the application
100109 #ifdef WIN32
101110 SetConsoleCtrlHandler ((PHANDLER_ROUTINE)ConsoleHandler, TRUE );
@@ -107,18 +116,24 @@ PSTracker::PSTracker(QObject *parent) : QObject(parent) {
107116 #endif
108117}
109118
110- void PSTracker::initPST () {
119+ // / <summary>
120+ // / Establsh connection with the PS Tech
121+ // / </summary>
122+ void PSTracker::Connect () {
111123 PSTech::pstsdk::EnableLogging ();
112- if (_pst == nullptr ) {
113- try {
114- _pst = new PSTech::pstsdk::Tracker ();
115- _detected = true ;
116- }
117- catch (PSTech::TrackerException& e) {
118- std::cout << " Could not connect to tracker." << std::endl;
119- std::cout << e.full_description () << std::endl; // DEV
120- throw " The PS-tech tracker is not detected" ;
124+ try {
125+ Exithandler (0 );
126+ if (_pst != nullptr ) {
127+ qDebug () << " Deleting old PST instance" ;
128+ delete _pst;
121129 }
130+ qDebug () << " Creating PST instance" ;
131+ _pst = new PSTech::pstsdk::Tracker ();
132+ }
133+ catch (PSTech::TrackerException& e) {
134+ std::cout << " Could not connect to tracker." << std::endl;
135+ std::cout << e.full_description () << std::endl; // DEV
136+ throw " The PS-tech tracker is not detected" ;
122137 }
123138}
124139
@@ -128,8 +143,10 @@ PSTracker::~PSTracker() {
128143}
129144
130145
146+
147+
131148bool PSTracker::checkTrackerStatus () {
132- if (!_detected ) {
149+ if (_pst == nullptr ) {
133150 throw " The PS-tech tracker is not detected" ;
134151 }
135152
@@ -154,6 +171,11 @@ bool PSTracker::checkTrackerStatus() {
154171 }
155172 case PSTech::pstsdk::StatusMessage::ERR_TIMEOUT: {
156173 qDebug () << " PS Tech : Grabber timeout error" ;
174+ if (!triedAutoReboot) {
175+ triedAutoReboot = true ;
176+ qDebug () << " tryingAutoReboot" ;
177+ Start ();
178+ }
157179 break ;
158180 }
159181 case PSTech::pstsdk::StatusMessage::ERR_NOCAMS_FOUND: {
@@ -188,14 +210,16 @@ bool PSTracker::getTrackerConnected() const {
188210 return _connected;
189211};
190212
191-
192- void PSTracker::Connect ()
213+ // / <summary>
214+ // / Start the PS Tech server and listen at target movements
215+ // / </summary>
216+ void PSTracker::Start ()
193217{
194- if (!_detected ) throw " The PS-tech tracker is not detected" ;
218+ if (_pst == nullptr ) throw " The PS-tech tracker is not detected" ;
195219
196- if (_connected){
197- return ;
198- }
220+ if (_connected){
221+ return ;
222+ }
199223
200224 // Implement error handling of PSTech::TrackerException exceptions to prevent
201225 // improper PST Tracker shutdown on errors.
@@ -224,6 +248,9 @@ void PSTracker::Connect()
224248 _pst->Start ();
225249
226250
251+ triedAutoReboot = false ;
252+
253+ _pst->DisableImageTransfer ();
227254
228255
229256
@@ -265,6 +292,11 @@ void PSTracker::Connect()
265292 if (checkTrackerStatus ()) {
266293 _connected = true ;
267294 emit connected ();
295+
296+ qDebug () << " Tracker started" ;
297+ }
298+ else {
299+ qDebug () << " Failed starting tracker" ;
268300 }
269301
270302 }
@@ -279,7 +311,6 @@ void PSTracker::Connect()
279311 // return;
280312 }
281313
282- qDebug () << " Connected to tracker!" ;
283314}
284315
285316// / <summary>
@@ -295,13 +326,9 @@ bool PSTracker::GetTargetMatrix(const int& index, QMatrix4x4& pose)
295326 {
296327 pose = listener.getTragetMatrix (index);
297328
298- // Exagerrate translations to move more freely
299- pose.data ()[12 ] *= 10 ;
300- pose.data ()[13 ] *= 10 ;
301- pose.data ()[14 ] *= 10 ;
302-
303329
304330 if (listener.getIsIdle (index)) {
331+ if (!connectionTimer->isActive ()) connectionTimer->start (5 *1000 );
305332 return false ;
306333 }
307334
@@ -338,6 +365,7 @@ bool PSTracker::GetTargetMatrix(const int& index, QMatrix4x4& pose)
338365
339366 }
340367
368+ if (!connectionTimer->isActive ()) connectionTimer->start (5 * 1000 );
341369 return false ;
342370}
343371
0 commit comments