From 987fc428f6f50120419aec434472507e50ef5b68 Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Wed, 23 Jan 2013 10:55:46 +0000 Subject: [PATCH] Added Tactile fluids, fixed tactile buttons git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@100 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- AngularPosition/AnswerPosition.cpp | 24 +++++- AngularPosition/AnswerPosition.h | 3 + DeltaTimeJND/AnswerDeltaTime.cpp | 115 ++++++++++++++--------------- DeltaTimeJND/AnswerDeltaTime.h | 16 ++-- DeltaTimeJND/AnswerDeltaTime.ui | 2 +- DeltaTimeJND/deltatimejnd.ui | 26 +++---- 6 files changed, 102 insertions(+), 84 deletions(-) diff --git a/AngularPosition/AnswerPosition.cpp b/AngularPosition/AnswerPosition.cpp index 091592c..9649541 100644 --- a/AngularPosition/AnswerPosition.cpp +++ b/AngularPosition/AnswerPosition.cpp @@ -7,7 +7,7 @@ #include AnswerPosition::AnswerPosition(QWidget *parent, Qt::WFlags flags) -:QMainWindow(parent, flags), _currentdirection(-1), _currenttrial(0) +:QMainWindow(parent, flags), _currentdirection(-1), _currenttrial(0), _logfile(NULL) { try { @@ -82,7 +82,7 @@ void AnswerPosition::init(QString user, int repetitions, int nbdirections, int f _logfile = fopen(logfilename.toStdString().c_str(), "w"); qDebug() << "log: " << logfilename; if (_logfile) - fprintf(_logfile, "Degrees,Direction,Answer,Error\n"); + fprintf(_logfile, "Time,Degrees,Direction,Answer,Delta,DeltaDegrees,Error\n"); _player->setFrequency(frequency); @@ -102,6 +102,8 @@ void AnswerPosition::init(QString user, int repetitions, int nbdirections, int f } _progress->setMaximum(_trials.size()); + _timer.start(); + runTrial(); } @@ -120,7 +122,20 @@ void AnswerPosition::runTrial() void AnswerPosition::answer() { if (_logfile) - fprintf(_logfile, "%d,%d,%d\n", (_trials.at(_currenttrial) * 90) / 4, _trials.at(_currenttrial), _currentdirection, _trials.at(_currenttrial) == _currentdirection); + { + //fprintf(_logfile, "Time,Degrees,Direction,Answer,Delta,Error\n"); + + int delta = std::min(abs(_trials.at(_currenttrial) - _currentdirection), + abs(16 + _trials.at(_currenttrial) - _currentdirection)); + fprintf(_logfile, "%lld,%d,%d,%d,%d,%d,%d\n", + _timer.elapsed(), + (_trials.at(_currenttrial) * 90) / 4, + _trials.at(_currenttrial), + _currentdirection, + delta, + delta * 90 / 4, + _trials.at(_currenttrial) != _currentdirection); + } QAbstractButton* checked = _group.checkedButton(); if (checked) @@ -174,5 +189,6 @@ void AnswerPosition::setAngle(int angle) void AnswerPosition::stop() { - _player->stop(); + unsigned char amp[] = {0, 0, 0, 0}; + _player->setAmplitudes(4, amp); } \ No newline at end of file diff --git a/AngularPosition/AnswerPosition.h b/AngularPosition/AnswerPosition.h index 2d8e93f..8bfa8fc 100644 --- a/AngularPosition/AnswerPosition.h +++ b/AngularPosition/AnswerPosition.h @@ -4,6 +4,7 @@ #include #include "ui_AnswerAngularPosition.h" #include +#include #include @@ -37,6 +38,8 @@ class AnswerPosition : public QMainWindow, public Ui::AnswerPosition QList _trials; int _currenttrial; + QElapsedTimer _timer; + TactonPlayer *_player; }; diff --git a/DeltaTimeJND/AnswerDeltaTime.cpp b/DeltaTimeJND/AnswerDeltaTime.cpp index f00afa5..8a46c5f 100644 --- a/DeltaTimeJND/AnswerDeltaTime.cpp +++ b/DeltaTimeJND/AnswerDeltaTime.cpp @@ -7,7 +7,7 @@ #include AnswerDeltaTime::AnswerDeltaTime(QWidget *parent) -: QMainWindow(parent), _logfile(NULL), _goodanswer(-1), _currentconfig(0) +: QMainWindow(parent), _goodanswer(-1), _currentconfig(0), _logfile(NULL), _logfile2(NULL) { try { @@ -46,7 +46,7 @@ AnswerDeltaTime::~AnswerDeltaTime() //delete _animation; } -void AnswerDeltaTime::init(QString user, int frequency, int timegap, int duration, double delta, int reversals) +void AnswerDeltaTime::init(QString user, int frequency, int timegap, int duration, int delta, int reversals) { //two vibrators alone _configurations[0][0] = 0; @@ -64,59 +64,45 @@ void AnswerDeltaTime::init(QString user, int frequency, int timegap, int duratio _reversals = reversals; _frequency = frequency; _delta = delta; - - _animation = new QTimeLine(duration, this); - _animation->setFrameRange(0, duration/timegap); -// _animation->setUpdateInterval(timegap); - connect(_animation, SIGNAL(frameChanged(int)), this, SLOT(playTest(int))); - connect(_animation, SIGNAL(finished()), this, SLOT(stop())); + _duration = duration; //create log file QString date = QDate::currentDate().toString("yyyy-MM-dd") + "-" + QTime::currentTime().toString("HH-mm-ss"); - QString logfilename = user + "-" + date + "-answers"; + QString logfilename = user + "-" + date + "-answers.csv"; if (_logfile = fopen(logfilename.toStdString().c_str(), "w")) - fprintf(_logfile, "Angle1,Angle2,Duration,Interval,GoodAnswer,UserAnswer,Error\n"); - logfilename = user + "-" + date + "-jnd"; + fprintf(_logfile, "Time,Angle1,Angle2,Duration,Interval,GoodAnswer,UserAnswer,Error\n"); + logfilename = user + "-" + date + "-jnd.csv"; if (_logfile2 = fopen(logfilename.toStdString().c_str(), "w")) - fprintf(_logfile2, "A1,A2,JND\n"); + fprintf(_logfile2, "Time,A1,A2,JND\n"); for (int i = 0 ; i < 4 ; i++) { - _currenttest[i] = 1.0; + _currenttest[i] = timegap; _configfinished[i] = false; } unsigned char amp[] = {0, 0, 0, 0}; _tactonPlayer->setAmplitudes(4, amp); _tactonPlayer->setFrequency(frequency); - + + _timer.start(); runTrial(); } -void AnswerDeltaTime::setAngle(int angle) +void AnswerDeltaTime::playTest() { - unsigned char amplitudes[4]; - memset(amplitudes, 0, 4); - - //vertical - if (angle < 180) - amplitudes[1] = 255 * sin(angle * M_PI / 180.0); - else - amplitudes[3] = - 255 * sin(angle * M_PI / 180.0); - - //horizontal - if (angle < 90 || angle > 270) - amplitudes[0] = 255 * cos(angle * M_PI / 180.0); - else - amplitudes[2] = - 255 * cos(angle * M_PI / 180.0); - - _tactonPlayer->setAmplitudes(4, amplitudes); -} + if (_currenttest[_currentconfig] == 0) + { + playOther(); + return; + } -void AnswerDeltaTime::playTest(int frame) -{ - qDebug() << "f" << frame << "\n"; - setAngle(_configurations[_currentconfig][frame % 2]); + unsigned int angles[2] = { _configurations[_currentconfig][0], _configurations[_currentconfig][1]}; + _tactonPlayer->playAngleSequence( + 2, + _currenttest[_currentconfig], + _duration / _currenttest[_currentconfig], + angles); } void AnswerDeltaTime::playOther() @@ -129,16 +115,16 @@ void AnswerDeltaTime::playOther() amplitudes[0] = amplitudes[1] = 255; break; case 2: - amplitudes[0] = amplitudes[1] = amplitudes[2] = amplitudes[3] = 255; + amplitudes[0] = amplitudes[1] = amplitudes[2] = amplitudes[3] = 127; break; case 3: - amplitudes[0] = amplitudes[1] = amplitudes[3] = 255; + amplitudes[0] = amplitudes[1] = amplitudes[3] = 170; break; } _tactonPlayer->setAmplitudes(4, amplitudes); - QTimer::singleShot(_animation->duration(), this, SLOT(stop())); + QTimer::singleShot(_duration, this, SLOT(stop())); } void AnswerDeltaTime::stop() @@ -185,15 +171,15 @@ void AnswerDeltaTime::answer() if (val) { _currenttest[_currentconfig] -= _delta; - if (_currenttest[_currentconfig] < 0.0) - _currenttest[_currentconfig] = 0.0; + if (_currenttest[_currentconfig] < 0) + _currenttest[_currentconfig] = 0; } //wrong answer: increase the gap else { _currenttest[_currentconfig] += _delta; - if (_currenttest[_currentconfig] > 1.0) - _currenttest[_currentconfig] = 1.0; +/* if (_currenttest[_currentconfig] > 1.0) + _currenttest[_currentconfig] = 1.0;*/ } } } @@ -205,15 +191,15 @@ void AnswerDeltaTime::answer() if (val) { _currenttest[_currentconfig] -= _delta; - if (_currenttest[_currentconfig] < 0.0) - _currenttest[_currentconfig] = 0.0; + if (_currenttest[_currentconfig] < 0) + _currenttest[_currentconfig] = 0; } //wrong answer: increase the gap else { _currenttest[_currentconfig] += _delta; - if (_currenttest[_currentconfig] > 1.0) - _currenttest[_currentconfig] = 1.0; +/* if (_currenttest[_currentconfig] > 1.0) + _currenttest[_currentconfig] = 1.0;*/ } } lastval[_currentconfig] = val; @@ -246,41 +232,52 @@ void AnswerDeltaTime::log(int answer) const { if (_logfile == NULL) return; - fprintf(_logfile, "%d,%d,%0.2f,%d,%d,%d,%d\n", - _configurations[_currentconfig][0], _configurations[_currentconfig][1], _animation->duration(), _currenttest[_currentconfig], _goodanswer, answer, _goodanswer == answer); + fprintf(_logfile, "%lld,%d,%d,%d,%d,%d,%d,%d\n", + _timer.elapsed(), + _configurations[_currentconfig][0], + _configurations[_currentconfig][1], + _duration, + _currenttest[_currentconfig], + _goodanswer, + answer, + _goodanswer != answer); } void AnswerDeltaTime::log2() const { if (_logfile2 == NULL) return; - fprintf(_logfile2, "%d,%d,%0.2f\n", _configurations[_currentconfig][0], _configurations[_currentconfig][1], _jnd[_currentconfig]); + fprintf(_logfile2, "%lld,%d,%d,%0.2f\n", + _timer.elapsed(), + _configurations[_currentconfig][0], + _configurations[_currentconfig][1], + _jnd[_currentconfig]); } void AnswerDeltaTime::runTrial() { _goodanswer = rand() % 3; - qDebug() << "good: " << _goodanswer << "\n"; - _animation->setFrameRange(0, _animation->duration()/_currenttest[_currentconfig]); +// qDebug() << "good: " << _goodanswer << "\n"; +// _animation->setFrameRange(0, _duration/_currenttest[_currentconfig]); switch(_goodanswer) { case 0: - QTimer::singleShot(500, _animation, SLOT(start())); - QTimer::singleShot(1500 + _animation->duration(), this, SLOT(playOther())); - QTimer::singleShot(2500 + 2 * _animation->duration(), this, SLOT(playOther())); + QTimer::singleShot(500, this, SLOT(playTest())); + QTimer::singleShot(1500 + _duration, this, SLOT(playOther())); + QTimer::singleShot(2500 + 2 * _duration, this, SLOT(playOther())); break; case 1: QTimer::singleShot(500, this, SLOT(playOther())); - QTimer::singleShot(1500 + _animation->duration(), _animation, SLOT(start())); - QTimer::singleShot(2500 + 2 * _animation->duration(), this, SLOT(playOther())); + QTimer::singleShot(1500 + _duration, this, SLOT(playTest())); + QTimer::singleShot(2500 + 2 * _duration, this, SLOT(playOther())); break; case 2: QTimer::singleShot(500, this, SLOT(playOther())); - QTimer::singleShot(1500 + _animation->duration(), this, SLOT(playOther())); - QTimer::singleShot(2500 + 2 * _animation->duration(), _animation, SLOT(start())); + QTimer::singleShot(1500 + _duration, this, SLOT(playOther())); + QTimer::singleShot(2500 + 2 * _duration, this, SLOT(playTest())); break; } } diff --git a/DeltaTimeJND/AnswerDeltaTime.h b/DeltaTimeJND/AnswerDeltaTime.h index 5bf220b..6817c05 100644 --- a/DeltaTimeJND/AnswerDeltaTime.h +++ b/DeltaTimeJND/AnswerDeltaTime.h @@ -2,7 +2,9 @@ #define ANSWERDELTATIME_H #include -#include +#include +#include +#include #include "ui_AnswerDeltaTime.h" #include @@ -15,7 +17,7 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow AnswerDeltaTime(QWidget *parent); ~AnswerDeltaTime(); - void init(QString user, int frequency, int timegap, int duration, double delta, int reversals); + void init(QString user, int frequency, int timegap, int duration, int delta, int reversals); private: //log the answers @@ -24,7 +26,6 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow void log2() const; void runTrial(); - void setAngle(int angle); FILE *_logfile, *_logfile2; TactonPlayer *_tactonPlayer; @@ -33,7 +34,8 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow int _configurations[4][2]; //4 configurations of 2 angles int _frequency; int _reversals; - double _delta; + int _delta; + int _duration; //exp status int _goodanswer; @@ -47,12 +49,12 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow //results double _jnd[4]; - //manage alternation between 2 vibrations - QTimeLine *_animation; + //for logs + QElapsedTimer _timer; private slots: //play 2 vibrations - void playTest(int frame); + void playTest(); //play 1 vibration void playOther(); //stop vibrations diff --git a/DeltaTimeJND/AnswerDeltaTime.ui b/DeltaTimeJND/AnswerDeltaTime.ui index 056831b..bede251 100644 --- a/DeltaTimeJND/AnswerDeltaTime.ui +++ b/DeltaTimeJND/AnswerDeltaTime.ui @@ -23,7 +23,7 @@ - Quelle vibration est la plus forte ? + Quelle vibration est alternée ? Qt::AlignCenter diff --git a/DeltaTimeJND/deltatimejnd.ui b/DeltaTimeJND/deltatimejnd.ui index b6f909a..e60cf98 100644 --- a/DeltaTimeJND/deltatimejnd.ui +++ b/DeltaTimeJND/deltatimejnd.ui @@ -77,19 +77,6 @@ - - - - 1.000000000000000 - - - 0.010000000000000 - - - 0.100000000000000 - - - @@ -130,6 +117,19 @@ + + + + 1 + + + 100 + + + 10 + + + -- 2.30.2