Skip to content

Commit d519820

Browse files
committed
finalised app
1 parent b1a9a0b commit d519820

13 files changed

Lines changed: 608 additions & 354 deletions

src/Actions/SettingsAction.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ SettingsAction::SettingsAction(QObject* parent, const QString& title) :
2626
//_eyeOffsetAction(this, "Eye offset", 0.8, 2, 1.04, 3),
2727
_pointOpacityAction(this, "Point opacity", 0, 1, 1.0f, 2),
2828
//_camDistAction(this, "Cam dist", 0, 3, 1.75, 2),
29-
_selectionColorPicker(this, "Selection Color", QColor(255,0,0))
29+
_selectionColorPicker(this, "Selection Color", QColor(255,0,0)),
30+
_resetViewAction(this, "Reset camera")
3031
{
3132
GroupsAction::GroupActions groupActions;
3233

@@ -78,6 +79,10 @@ SettingsAction::SettingsAction(QObject* parent, const QString& title) :
7879
_plugin->getOpenGLRendererWidget()->toggleFullScreen();
7980
});
8081

82+
connect(&_resetViewAction, &TriggerAction::triggered, this, [this]() {
83+
_plugin->getOpenGLRendererWidget()->resetViewPos();
84+
});
85+
8186
connect(&_clearSelectionAction, &TriggerAction::triggered, this, [this]() {
8287
_plugin->clearSelection();
8388
_pointOpacityAction.setValue(1.f);

src/Actions/SettingsAction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SettingsAction : public GroupAction
6363
TriggerAction& getConnectToTrackerAction() { return _connectToTrackerAction; }
6464
TriggerAction& getStartCalibAction() { return _startCalibAction; }
6565
TriggerAction& getToggleFullScreen() { return _toggleFullScreen; }
66+
TriggerAction& getResetViewAction() { return _resetViewAction; }
6667
TriggerAction& getClearSelectionAction() { return _clearSelectionAction; }
6768
DecimalAction& getPointOpacityAction() { return _pointOpacityAction; }
6869
//DecimalAction& getEyeOffsetAction() { return _eyeOffsetAction; }
@@ -85,6 +86,7 @@ class SettingsAction : public GroupAction
8586
TriggerAction _startCalibAction;
8687
TriggerAction _clearSelectionAction;
8788
TriggerAction _toggleFullScreen;
89+
TriggerAction _resetViewAction;
8890
DecimalAction _pointOpacityAction;
8991
//DecimalAction _eyeOffsetAction;
9092
//DecimalAction _camDistAction;

src/Controllers/Tracker.cpp

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5859
QMatrix4x4 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

9899
PSTracker::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+
131148
bool 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

src/Controllers/Tracker.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <iostream>
1313
#include <mutex>
1414
#include <QElapsedTimer>
15+
#include <QTimer>
1516

1617
#include <vector>
1718
#include <string>
@@ -98,7 +99,9 @@ class PSTracker : public QObject
9899
public:
99100
PSTracker(QObject* parent = nullptr);
100101
~PSTracker();
102+
101103
void Connect();
104+
void Start();
102105

103106
bool GetTargetMatrix(const int& index, QMatrix4x4& pose);
104107
QMatrix4x4 GetReference() const;
@@ -111,12 +114,12 @@ class PSTracker : public QObject
111114
}
112115

113116
bool getTrackerConnected() const;
114-
void initPST();
115117

116118

117119

118120
signals:
119121
void connected();
122+
void stopped();
120123

121124

122125
private:
@@ -125,13 +128,14 @@ class PSTracker : public QObject
125128
MyListener listener;
126129
PSTech::pstsdk::Tracker* _pst = nullptr;
127130

128-
/* Reflects whether an instance of pst exists, ie if a tracker is plugged in */
129-
bool _detected = false;
130131
/* Reflects whether the tracker is activated and actively sending information */
131132
bool _connected = false;
132133

133134
/** Timing of the animation after there has been a tracking lost */
134135
QElapsedTimer lerpTimer;
136+
137+
QTimer* connectionTimer;
138+
135139
/** Time to animate the target between the last live position to the new one, after there has been a tracking lost */
136140
const qint64 lerpDuraton = 300;
137141
std::vector<bool> poseAcurate;
@@ -140,4 +144,6 @@ class PSTracker : public QObject
140144
QMatrix4x4 oldPos;
141145
float idleRotationAngle = 0.0f;
142146

147+
bool triedAutoReboot = false;
148+
143149
};

0 commit comments

Comments
 (0)