Added Tactile fluids, fixed tactile buttons
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 23 Jan 2013 10:55:46 +0000 (10:55 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 23 Jan 2013 10:55:46 +0000 (10:55 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@100 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

AngularPosition/AnswerPosition.cpp
AngularPosition/AnswerPosition.h
DeltaTimeJND/AnswerDeltaTime.cpp
DeltaTimeJND/AnswerDeltaTime.h
DeltaTimeJND/AnswerDeltaTime.ui
DeltaTimeJND/deltatimejnd.ui

index 091592ca04a8ff55de8b31cf842081ee70d886b9..9649541df80a042a93b44b819e09089d621d63bc 100644 (file)
@@ -7,7 +7,7 @@
 #include <QString>\r
 \r
 AnswerPosition::AnswerPosition(QWidget *parent, Qt::WFlags flags)\r
-:QMainWindow(parent, flags), _currentdirection(-1), _currenttrial(0)\r
+:QMainWindow(parent, flags), _currentdirection(-1), _currenttrial(0), _logfile(NULL)\r
 {\r
        try\r
        {\r
@@ -82,7 +82,7 @@ void AnswerPosition::init(QString user, int repetitions, int nbdirections, int f
        _logfile = fopen(logfilename.toStdString().c_str(), "w");\r
        qDebug() << "log: " << logfilename;\r
        if (_logfile)\r
-               fprintf(_logfile, "Degrees,Direction,Answer,Error\n");\r
+               fprintf(_logfile, "Time,Degrees,Direction,Answer,Delta,DeltaDegrees,Error\n");\r
 \r
        _player->setFrequency(frequency);\r
 \r
@@ -102,6 +102,8 @@ void AnswerPosition::init(QString user, int repetitions, int nbdirections, int f
        }\r
        _progress->setMaximum(_trials.size());\r
 \r
+       _timer.start();\r
+\r
        runTrial();\r
 }\r
 \r
@@ -120,7 +122,20 @@ void AnswerPosition::runTrial()
 void AnswerPosition::answer()\r
 {\r
        if (_logfile)\r
-               fprintf(_logfile, "%d,%d,%d\n", (_trials.at(_currenttrial) * 90) / 4, _trials.at(_currenttrial), _currentdirection, _trials.at(_currenttrial) == _currentdirection);\r
+       {\r
+               //fprintf(_logfile, "Time,Degrees,Direction,Answer,Delta,Error\n");\r
+\r
+               int delta = std::min(abs(_trials.at(_currenttrial) - _currentdirection),\r
+                       abs(16 + _trials.at(_currenttrial) - _currentdirection));\r
+               fprintf(_logfile, "%lld,%d,%d,%d,%d,%d,%d\n", \r
+                       _timer.elapsed(), \r
+                       (_trials.at(_currenttrial) * 90) / 4, \r
+                       _trials.at(_currenttrial), \r
+                       _currentdirection,\r
+                       delta,\r
+                       delta * 90 / 4,\r
+                       _trials.at(_currenttrial) != _currentdirection);\r
+       }\r
 \r
        QAbstractButton* checked = _group.checkedButton();\r
        if (checked)\r
@@ -174,5 +189,6 @@ void AnswerPosition::setAngle(int angle)
 \r
 void AnswerPosition::stop()\r
 {\r
-       _player->stop();\r
+       unsigned char amp[] = {0, 0, 0, 0};\r
+       _player->setAmplitudes(4, amp);\r
 }
\ No newline at end of file
index 2d8e93f251dbad9087b59de94984149c3c1f3b21..8bfa8fc5b429cb62753ffd4647657906b196ec6c 100644 (file)
@@ -4,6 +4,7 @@
 #include <QtGui/QMainWindow>\r
 #include "ui_AnswerAngularPosition.h"\r
 #include <QButtonGroup>\r
+#include <QElapsedTimer>\r
 \r
 #include <TactonPlayer\TactonPlayer.hpp>\r
 \r
@@ -37,6 +38,8 @@ class AnswerPosition : public QMainWindow, public Ui::AnswerPosition
                QList<int> _trials;\r
                int _currenttrial;\r
 \r
+               QElapsedTimer _timer;\r
+\r
                TactonPlayer *_player;\r
 };\r
 \r
index f00afa5042d078cfb461f7340bac577fbb4e4f2e..8a46c5f4eb226e40960c804b1f5ed1d10fe382b7 100644 (file)
@@ -7,7 +7,7 @@
 #include <QDebug>\r
 \r
 AnswerDeltaTime::AnswerDeltaTime(QWidget *parent)\r
-: QMainWindow(parent), _logfile(NULL), _goodanswer(-1), _currentconfig(0)\r
+: QMainWindow(parent), _goodanswer(-1), _currentconfig(0), _logfile(NULL), _logfile2(NULL)\r
 {\r
        try\r
        {\r
@@ -46,7 +46,7 @@ AnswerDeltaTime::~AnswerDeltaTime()
        //delete _animation;\r
 }\r
 \r
-void AnswerDeltaTime::init(QString user, int frequency, int timegap, int duration, double delta, int reversals)\r
+void AnswerDeltaTime::init(QString user, int frequency, int timegap, int duration, int delta, int reversals)\r
 {\r
        //two vibrators alone\r
        _configurations[0][0] = 0;\r
@@ -64,59 +64,45 @@ void AnswerDeltaTime::init(QString user, int frequency, int timegap, int duratio
        _reversals = reversals;\r
        _frequency = frequency;\r
        _delta = delta;\r
-\r
-       _animation = new QTimeLine(duration, this);\r
-       _animation->setFrameRange(0, duration/timegap);\r
-//     _animation->setUpdateInterval(timegap);\r
-       connect(_animation, SIGNAL(frameChanged(int)), this, SLOT(playTest(int)));\r
-       connect(_animation, SIGNAL(finished()), this, SLOT(stop()));\r
+       _duration = duration;\r
 \r
        //create log file\r
        QString date = QDate::currentDate().toString("yyyy-MM-dd") + "-" + QTime::currentTime().toString("HH-mm-ss");\r
-       QString logfilename = user + "-" + date + "-answers";\r
+       QString logfilename = user + "-" + date + "-answers.csv";\r
        if (_logfile = fopen(logfilename.toStdString().c_str(), "w"))\r
-               fprintf(_logfile, "Angle1,Angle2,Duration,Interval,GoodAnswer,UserAnswer,Error\n");\r
-       logfilename = user + "-" + date + "-jnd";\r
+               fprintf(_logfile, "Time,Angle1,Angle2,Duration,Interval,GoodAnswer,UserAnswer,Error\n");\r
+       logfilename = user + "-" + date + "-jnd.csv";\r
        if (_logfile2 = fopen(logfilename.toStdString().c_str(), "w"))\r
-               fprintf(_logfile2, "A1,A2,JND\n");\r
+               fprintf(_logfile2, "Time,A1,A2,JND\n");\r
 \r
        for (int i = 0 ; i < 4 ; i++)\r
        {\r
-               _currenttest[i] = 1.0;\r
+               _currenttest[i] = timegap;\r
                _configfinished[i] = false;\r
        }\r
 \r
        unsigned char amp[] = {0, 0, 0, 0};\r
        _tactonPlayer->setAmplitudes(4, amp);\r
        _tactonPlayer->setFrequency(frequency);\r
-\r
+       \r
+       _timer.start();\r
        runTrial();\r
 }\r
 \r
-void AnswerDeltaTime::setAngle(int angle)\r
+void AnswerDeltaTime::playTest()\r
 {\r
-       unsigned char amplitudes[4];\r
-       memset(amplitudes, 0, 4);\r
-\r
-       //vertical\r
-       if (angle < 180)\r
-               amplitudes[1] = 255 * sin(angle * M_PI / 180.0);\r
-       else\r
-               amplitudes[3] = - 255 * sin(angle * M_PI / 180.0);\r
-\r
-       //horizontal\r
-       if (angle < 90 || angle > 270)\r
-               amplitudes[0] = 255 * cos(angle * M_PI / 180.0);\r
-       else\r
-               amplitudes[2] = - 255 * cos(angle * M_PI / 180.0);\r
-\r
-       _tactonPlayer->setAmplitudes(4, amplitudes);\r
-}\r
+       if (_currenttest[_currentconfig] == 0)\r
+       {\r
+               playOther();\r
+               return;\r
+       }\r
 \r
-void AnswerDeltaTime::playTest(int frame)\r
-{\r
-       qDebug() << "f" << frame << "\n";\r
-       setAngle(_configurations[_currentconfig][frame % 2]);\r
+       unsigned int angles[2] = { _configurations[_currentconfig][0], _configurations[_currentconfig][1]};\r
+       _tactonPlayer->playAngleSequence(\r
+               2, \r
+               _currenttest[_currentconfig], \r
+               _duration / _currenttest[_currentconfig], \r
+               angles);\r
 }\r
 \r
 void AnswerDeltaTime::playOther()\r
@@ -129,16 +115,16 @@ void AnswerDeltaTime::playOther()
                        amplitudes[0] = amplitudes[1] = 255;\r
                        break;\r
                case 2:\r
-                       amplitudes[0] = amplitudes[1] = amplitudes[2] = amplitudes[3] = 255;\r
+                       amplitudes[0] = amplitudes[1] = amplitudes[2] = amplitudes[3] = 127;\r
                        break;\r
                case 3:\r
-                       amplitudes[0] = amplitudes[1] = amplitudes[3] = 255;\r
+                       amplitudes[0] = amplitudes[1] = amplitudes[3] = 170;\r
                        break;\r
        }\r
 \r
        _tactonPlayer->setAmplitudes(4, amplitudes);\r
 \r
-       QTimer::singleShot(_animation->duration(), this, SLOT(stop()));\r
+       QTimer::singleShot(_duration, this, SLOT(stop()));\r
 }\r
 \r
 void AnswerDeltaTime::stop()\r
@@ -185,15 +171,15 @@ void AnswerDeltaTime::answer()
                        if (val)\r
                        {\r
                                _currenttest[_currentconfig] -= _delta;\r
-                               if (_currenttest[_currentconfig] < 0.0)\r
-                                       _currenttest[_currentconfig] = 0.0;\r
+                               if (_currenttest[_currentconfig] < 0)\r
+                                       _currenttest[_currentconfig] = 0;\r
                        }\r
                        //wrong answer: increase the gap\r
                        else\r
                        {\r
                                _currenttest[_currentconfig] += _delta;\r
-                               if (_currenttest[_currentconfig] > 1.0)\r
-                                       _currenttest[_currentconfig] = 1.0;\r
+/*                             if (_currenttest[_currentconfig] > 1.0)\r
+                                       _currenttest[_currentconfig] = 1.0;*/\r
                        }\r
                }\r
        }\r
@@ -205,15 +191,15 @@ void AnswerDeltaTime::answer()
                if (val)\r
                {\r
                        _currenttest[_currentconfig] -= _delta;\r
-                       if (_currenttest[_currentconfig] < 0.0)\r
-                               _currenttest[_currentconfig] = 0.0;\r
+                       if (_currenttest[_currentconfig] < 0)\r
+                               _currenttest[_currentconfig] = 0;\r
                }\r
                //wrong answer: increase the gap\r
                else\r
                {\r
                        _currenttest[_currentconfig] += _delta;\r
-                       if (_currenttest[_currentconfig] > 1.0)\r
-                               _currenttest[_currentconfig] = 1.0;\r
+/*                     if (_currenttest[_currentconfig] > 1.0)\r
+                               _currenttest[_currentconfig] = 1.0;*/\r
                }\r
        }\r
        lastval[_currentconfig] = val;\r
@@ -246,41 +232,52 @@ void AnswerDeltaTime::log(int answer) const
 {\r
        if (_logfile == NULL)\r
                return;\r
-       fprintf(_logfile, "%d,%d,%0.2f,%d,%d,%d,%d\n", \r
-               _configurations[_currentconfig][0], _configurations[_currentconfig][1], _animation->duration(), _currenttest[_currentconfig], _goodanswer, answer, _goodanswer == answer);\r
+       fprintf(_logfile, "%lld,%d,%d,%d,%d,%d,%d,%d\n", \r
+               _timer.elapsed(), \r
+               _configurations[_currentconfig][0], \r
+               _configurations[_currentconfig][1], \r
+               _duration, \r
+               _currenttest[_currentconfig], \r
+               _goodanswer, \r
+               answer, \r
+               _goodanswer != answer);\r
 }\r
 \r
 void AnswerDeltaTime::log2() const\r
 {\r
        if (_logfile2 == NULL)\r
                return;\r
-       fprintf(_logfile2, "%d,%d,%0.2f\n", _configurations[_currentconfig][0], _configurations[_currentconfig][1], _jnd[_currentconfig]);\r
+       fprintf(_logfile2, "%lld,%d,%d,%0.2f\n", \r
+               _timer.elapsed(), \r
+               _configurations[_currentconfig][0], \r
+               _configurations[_currentconfig][1], \r
+               _jnd[_currentconfig]);\r
 }\r
 \r
 void AnswerDeltaTime::runTrial()\r
 {\r
        _goodanswer = rand() % 3;\r
 \r
-       qDebug() << "good: " << _goodanswer << "\n";\r
-       _animation->setFrameRange(0, _animation->duration()/_currenttest[_currentconfig]);\r
+//     qDebug() << "good: " << _goodanswer << "\n";\r
+//     _animation->setFrameRange(0, _duration/_currenttest[_currentconfig]);\r
 \r
 \r
        switch(_goodanswer)\r
        {\r
                case 0:\r
-                       QTimer::singleShot(500, _animation, SLOT(start()));\r
-                       QTimer::singleShot(1500 + _animation->duration(), this, SLOT(playOther()));\r
-                       QTimer::singleShot(2500 + 2 * _animation->duration(), this, SLOT(playOther()));\r
+                       QTimer::singleShot(500, this, SLOT(playTest()));\r
+                       QTimer::singleShot(1500 + _duration, this, SLOT(playOther()));\r
+                       QTimer::singleShot(2500 + 2 * _duration, this, SLOT(playOther()));\r
                        break;\r
                case 1:\r
                        QTimer::singleShot(500, this, SLOT(playOther()));\r
-                       QTimer::singleShot(1500 + _animation->duration(), _animation, SLOT(start()));\r
-                       QTimer::singleShot(2500 + 2 * _animation->duration(), this, SLOT(playOther()));\r
+                       QTimer::singleShot(1500 + _duration, this, SLOT(playTest()));\r
+                       QTimer::singleShot(2500 + 2 * _duration, this, SLOT(playOther()));\r
                        break;\r
                case 2:\r
                        QTimer::singleShot(500, this, SLOT(playOther()));\r
-                       QTimer::singleShot(1500 + _animation->duration(), this, SLOT(playOther()));\r
-                       QTimer::singleShot(2500 + 2 * _animation->duration(), _animation, SLOT(start()));\r
+                       QTimer::singleShot(1500 + _duration, this, SLOT(playOther()));\r
+                       QTimer::singleShot(2500 + 2 * _duration, this, SLOT(playTest()));\r
                        break;\r
        }\r
 }\r
index 5bf220b6c5617eb960598537474611de30d52052..6817c05f3eb62d4db278eda4e97006731a1c9112 100644 (file)
@@ -2,7 +2,9 @@
 #define ANSWERDELTATIME_H\r
 \r
 #include <QMainWindow>\r
-#include <QTimeline>\r
+#include <QTimer>\r
+#include <QTime>\r
+#include <QElapsedTimer>\r
 #include "ui_AnswerDeltaTime.h"\r
 \r
 #include <TactonPlayer\TactonPlayer.hpp>\r
@@ -15,7 +17,7 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow
                AnswerDeltaTime(QWidget *parent);\r
                ~AnswerDeltaTime();\r
 \r
-               void init(QString user, int frequency, int timegap, int duration, double delta, int reversals);\r
+               void init(QString user, int frequency, int timegap, int duration, int delta, int reversals);\r
 \r
        private:\r
                //log the answers\r
@@ -24,7 +26,6 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow
                void log2() const;\r
 \r
                void runTrial();\r
-               void setAngle(int angle);\r
 \r
                FILE *_logfile, *_logfile2;\r
                TactonPlayer *_tactonPlayer;\r
@@ -33,7 +34,8 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow
                int _configurations[4][2]; //4 configurations of 2 angles\r
                int _frequency;\r
                int _reversals;\r
-               double _delta;\r
+               int _delta;\r
+               int _duration;\r
 \r
                //exp status\r
                int _goodanswer;\r
@@ -47,12 +49,12 @@ class AnswerDeltaTime : public QMainWindow, Ui::AnswerWindow
                //results\r
                double _jnd[4];\r
 \r
-               //manage alternation between 2 vibrations\r
-               QTimeLine *_animation;\r
+               //for logs\r
+               QElapsedTimer _timer;\r
 \r
        private slots:\r
                //play 2 vibrations\r
-               void playTest(int frame);\r
+               void playTest();\r
                //play 1 vibration\r
                void playOther();\r
                //stop vibrations\r
index 056831b4c8187cd574c904754c1fa5cc50e45c83..bede25181d4a16bbffeb4e40b24765b3b56d5bb7 100644 (file)
@@ -23,7 +23,7 @@
        </font>\r
       </property>\r
       <property name="text">\r
-       <string>Quelle vibration est la plus forte ?</string>\r
+       <string>Quelle vibration est alternée ?</string>\r
       </property>\r
       <property name="alignment">\r
        <set>Qt::AlignCenter</set>\r
index b6f909a5efad481a4eea2f3f3d5aca084fe00650..e60cf9845dafe9c3498e4b9d90e5d96339963bd9 100644 (file)
         </property>\r
        </widget>\r
       </item>\r
-      <item row="3" column="1">\r
-       <widget class="QDoubleSpinBox" name="_delta">\r
-        <property name="maximum">\r
-         <double>1.000000000000000</double>\r
-        </property>\r
-        <property name="singleStep">\r
-         <double>0.010000000000000</double>\r
-        </property>\r
-        <property name="value">\r
-         <double>0.100000000000000</double>\r
-        </property>\r
-       </widget>\r
-      </item>\r
       <item row="4" column="0">\r
        <widget class="QLabel" name="reversalsLabel">\r
         <property name="text">\r
         </property>\r
        </widget>\r
       </item>\r
+      <item row="3" column="1">\r
+       <widget class="QSpinBox" name="_delta">\r
+        <property name="minimum">\r
+         <number>1</number>\r
+        </property>\r
+        <property name="maximum">\r
+         <number>100</number>\r
+        </property>\r
+        <property name="value">\r
+         <number>10</number>\r
+        </property>\r
+       </widget>\r
+      </item>\r
      </layout>\r
     </item>\r
     <item>\r