/**
 * @brief advanceTrial: This function to the next trial
 */
void advanceTrial()
{
    fingersTimer.start(); // Here we change trial mode

    if (trialMode == HANDONSTARTMODE )
    {
        // Wait to show the stimulus that the fingers points are projected in the screen
        trialMode = STIMULUSMODE;
    }
    else // trialMode == STIMULUSMODE
    {
		trialMode = HANDONSTARTMODE;
		paintGL();
		beepTrial();
		double oldDistance = factors.getCurrent().at("Distances");
        // Reinsert the trial if too much occluded frames
		double maxInvisibleFramesPercent = util::str2num<double>(parameters.find("MaxPercentOccludedFrames"))/100.0;
		if ( (invisibleIndexFrames / ((double)drawingTrialFrame) > maxInvisibleFramesPercent ) ||
			(invisibleThumbFrames / ((double)drawingTrialFrame) > maxInvisibleFramesPercent )||
			(invisibleWristFrames / ((double)drawingTrialFrame) > maxInvisibleFramesPercent ) )
		{
			map<string,double> currentFactorsList = factors.getCurrent();
            beepBad();
            cerr << "Reinserted current trial (InvIndex,InvThumb,drawingTrialFrame,totTrialFrame)" << invisibleIndexFrames << " " << invisibleThumbFrames << " " << drawingTrialFrame << " " << trialFrame << endl;
            factors.reinsert(currentFactorsList);
		}
		if (factors.isEmpty())
        {
            beepLong();
            beepLong();
            beepLong();
            plato_stop();
			exit(0);
        }
        invisibleIndexFrames = invisibleThumbFrames = invisibleWristFrames = trialFrame = drawingTrialFrame = 0;
        totalTrialNumber++;
		factors.next();
		
		if (oldDistance == factors.getCurrent().at("Distances"))
		{
			Timer sleepTimer; sleepTimer.sleep(1000);
		}
		
		double marker5z = markers.at(5).p.z();
		generateSphereStimulus( factors.getCurrent().at("StimulusRadius") );
        initProjectionScreen(factors.getCurrent().at("Distances"));
        moveStimulusObject(visualStimCenter,3500);
    }
}
Example #2
0
void advanceTrial()
{
	double timeElapsed = timer.getElapsedTimeInMilliSec();
	responseFile.precision(3);
    responseFile << 
					parameters.find("SubjectName") << "\t" <<
					//interoculardistance << "\t" <<
					trialNumber << "\t" <<
					stimPosn << "\t" <<
					trial.getCurrent()["RodVisibleTime"] << "\t" <<
					trial.getCurrent()["AbsDepth"] <<"\t" <<
                    //"50" << "\t" <<//trial.getCurrent()["ObjHeight"] <<"\t" <<
                    timer.getElapsedTimeInMilliSec() << "\t" <<
					//trial.getCurrent()["HapticFB"] << "\t" <<
					//randCond << "\t" <<
					//randIncrement << "\t" <<
					stimCond << "\t" <<
					BG_WHITE << "\t" <<
					endl;
	
	trialFile.close();

	double percent_occluded_frames = num_lost_frames/TGA_frame;
	bool not_enough_frames = percent_occluded_frames > 0.20;
	cout << num_lost_frames << "_" << frameN << "_" << percent_occluded_frames << endl;
	int overwrite = 0;

	if (training || !reachedObject || not_enough_frames ) {
		cout << training << "_" << !reachedObject << "_" << not_enough_frames << endl;
		map<std::string,double> currentFactorsList = trial.getCurrent();
		trial.reinsert(currentFactorsList);
		beepOk(1);
		overwrite = 1;
	}

	if( !trial.isEmpty() )
	{
		if (!overwrite)
			trialNumber++;
		cout << trialNumber << endl;
		factors = trial.getNext();
		initTrial();
	}
	else
	{
		exit(0);
	}

}
Example #3
0
void advanceTrial()
{
    double timeElapsed = timer.getElapsedTimeInMilliSec();
    double percent_occluded_frames = (double)framesOccluded/(frameN-frames_at_start-frames_post_grasp);
    bool not_enough_frames = percent_occluded_frames > 0.20;

    if(not_enough_frames)
    {
        beepOk(1);
        trial.reinsert(trial.getCurrent());
        good_trial = 0;
    } else
    {
        beepOk(0);
        good_trial = 1;
    }

    responseFile.precision(3); // max three decimal positions
    responseFile << fixed <<
                 parameters.find("SubjectName") << "\t" <<
                 interoculardistance << "\t" <<
                 trialNumber << "\t" <<
                 trial.getCurrent()["AbsDepth"] << "\t" <<
                 objwidth << "\t" <<
                 objdepth << "\t" <<
                 timeElapsed << "\t" <<
                 good_trial
                 << endl;

    markersFile.close();

    trialNumber++;
    if(trial.hasNext())
    {
        trial.next();
        initTrial();
    } else
    {
        responseFile.close();
        expFinished = true;
    }

}
Example #4
0
void advanceTrial()
{   if ( trialMode == STIMULUSMODE )
    {   bool pretrialMode=trialMode;
        trialMode++;
        trialMode=trialMode%2;
        totalTrialNumber++;

        if (block.at("Phase") != 1 )
        {
            double percentOccludedFrames = ((double)occludedFrames/(double)drawingTrialFrame )*100.0;
            if ( percentOccludedFrames > str2num<double>(parameters.find("TestPercentOccludedFrames")) )
            {
                cerr << "Percent occluded frames is" << percentOccludedFrames << " " << occludedFrames << " over " << drawingTrialFrame << endl;
                trial.reinsert(factors);

            }
            drawingTrialFrame=0;
            occludedFrames=0;
        }
        trialFrame=0;
        switch( block.at("Phase") )
        {
        case 0:  //pre-test
        {
            if ( !trial.isEmpty() )	// ci son ancora trial
            {   beepTrial();
                initStimulus(testStimHeight,testStimRadius);
                factors = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter  = rodAway;
                initProjectionScreen(visualRodCenter.z());
                moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                beepTrial();
            }
            else // si prepara per la modalità 1 (adaptation)
            {   trialMode = HANDONSTARTMODE;
                block = module.getNext();
                initStimulus(testStimHeight,testStimRadius );
                double zadaptmin = str2num<double>(parameters.find("AdaptZMin"));
                double zadaptmax = str2num<double>(parameters.find("AdaptZMax"));

                if (str2num<int>(parameters.find("AdaptMoveMonitor"))==1)
                    visualRodCenter=Vector3d(0,0,mathcommon::unifRand(zadaptmin,zadaptmax));
                else
                    visualRodCenter=Vector3d(0,0, (zadaptmin+zadaptmax)/2);
                initProjectionScreen( visualRodCenter.z());

                if ( str2num<int>(parameters.find("AdaptHapticFeedback"))==1 )
                    hapticRodCenter = visualRodCenter - Vector3d(0,0,adaptOffsets.at(block1TrialNumber));
                else
                    hapticRodCenter = rodAway;

                moveRod(Vector3d(0,0,hapticRodCenter.z() ),RODSPEED);

                checkBounds();
                beepLong();
            }
            block0TrialNumber++;
        }
        break;
        case 1:  // adaptation
        {
            block1TrialNumber++;
            if ( block1TrialNumber < str2num<int>(parameters.find("AdaptTrials")) )
            {   beepTrial();
                initStimulus(adaptStimHeight,adaptStimRadius);
                double zadaptmin = str2num<double>(parameters.find("AdaptZMin"));
                double zadaptmax = str2num<double>(parameters.find("AdaptZMax"));

                if (str2num<int>(parameters.find("AdaptMoveMonitor"))==1)
                    visualRodCenter = Vector3d(0,0,mathcommon::unifRand(zadaptmin,zadaptmax));
                else
                    visualRodCenter=Vector3d(0,0, (zadaptmin+zadaptmax)/2);

                if ( str2num<int>(parameters.find("AdaptHapticFeedback"))==1 )
                {
                    hapticRodCenter = visualRodCenter - Vector3d(0,0,adaptOffsets.at(block1TrialNumber));
                    moveScreenAbsoluteAsynchronous(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                    moveRod(hapticRodCenter,RODSPEED);
                }
                else
                {
                    hapticRodCenter = rodAway;
                    moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                }

                initProjectionScreen( visualRodCenter.z());
                beepTrial();
            }
            else
            {   beepLong();
                trialMode = HANDONSTARTMODE;
                block  = module.getNext();
                // reset the factors in order to prepare the next test phase
                trial.init(parameters);
                factors.clear();
                factors  = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                //cerr << "DISTANCE= " << factors.at("Distances") << endl;
                initStimulus(testStimHeight,testStimRadius);
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter = rodAway;

                moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                moveRod(rodAway,RODSPEED);
                initProjectionScreen(visualRodCenter.z());

                beepTrial();
            }
        }
        break;
        case 2:  /// post-test
        {   if ( trial.isEmpty() )
            {   beepLong();
                cleanup();
                exit(0);
            }
            else
            {   beepTrial();
                initStimulus(testStimHeight,testStimRadius);
                factors = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                cerr << "DISTANCE= " << factors.at("Distances") << endl;
                visualRodCenter =  Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter  = rodAway;
                initProjectionScreen(visualRodCenter.z());
                moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                beepTrial();
            }
            block2TrialNumber++;
        }
        break;
        }
        globalTimer.start();
    }
    // Mettere una idle così non perde il primo trial
    idle();
}
// Funzione di callback per gestire pressioni dei tasti
void handleKeypress(unsigned char key, int x, int y)
{   
	switch (key)
	{   
		#ifdef SIMULATION
		case '0':
		{
			good_trial = 1;
			advanceTrial();
		} break;

		case '1':
			allVisibleFingers = !allVisibleFingers;
			break;

		case '2':
		{
			trial.reinsert(trial.getCurrent());
			good_trial = 0;
			advanceTrial();
		} break;

		#endif

		case 'i': // show info
			visibleInfo=!visibleInfo;
			break;

		case 'm': // increase IOD
			interoculardistance += 0.5;
			break;

		case 'n': // decrease IOD
			interoculardistance -= 0.5;
			break;

		case 27: // press escape to quit
		{   
			cleanup(); // clean the optotrak buffer
			exit(0);
		} break;

		// fingers calibration
		case 'f':
		case 'F':
		{
			// Interpolate the fingertip (fourth virtual marker)
			if ( fingerCalibrationDone==2 && allVisibleFingers && allVisibleObject )
			{
				fingerCalibrationDone=3;
				calibration_fingers(fingerCalibrationDone);
				beepOk(0);
				break;
			}

			// Start the experiment
			if ( fingerCalibrationDone==3  && allVisibleFingers )
			{
				fingerCalibrationDone=4;
				beepOk(0);
				visibleInfo=false;
				drawGLScene(); // this is needed otherwise the next motor command freezes the screen
				initProjectionScreen(-280);
			}
		} break;

		case ' ': // confirm that you grasped
		{
			if(allVisibleFingers)
			{
				iGrasped = true;
				isStimulusDrawn = false;
			}
		} break;
		
	}
}
Example #6
0
// Funzione di callback per gestire pressioni dei tasti
void handleKeypress(unsigned char key, int x, int y)
{
    switch (key)
    {
#ifdef SIMULATION
    case '0':
    {
        good_trial = 1;
        advanceTrial();
    }
    break;

    case '1':
        allVisibleFingers = !allVisibleFingers;
        break;

    case '2':
    {
        trial.reinsert(trial.getCurrent());
        good_trial = 0;
        advanceTrial();
    }
    break;

#endif

    case 'i': // show info
        visibleInfo=!visibleInfo;
        break;

    case 'm': // increase IOD
        interoculardistance += 0.5;
        break;

    case 'n': // decrease IOD
        interoculardistance -= 0.5;
        break;

    case 27: // press escape to quit
    {
        cleanup(); // clean the optotrak buffer
        exit(0);
    }
    break;

    // fingers calibration
    case 'f':
    case 'F':
    {
        // Interpolate the fingertip (fourth virtual marker)
        if ( fingerCalibrationDone==2 && allVisibleObject && allVisibleFingers )
        {
            fingerCalibrationDone=3;
            calibration_fingers(fingerCalibrationDone);
            beepOk(3);
            break;
        }

        // Start the experiment
        if ( fingerCalibrationDone==3  && allVisibleFingers )
        {
            fingerCalibrationDone=4;
            beepOk(0);
            home_position = ind;
            visibleInfo=false;
            drawGLScene(); // this is needed otherwise the next motor command freezes the screen

            // check where the object is
            object_reset_position = markers[3].p.transpose();
            // calculate where the object has to go
            Vector3d object_position(0.0,object_reset_position.y(),-550.0);
            // move the object to position from where it is
            moveObjectAbsolute(object_position, object_reset_position, 5000);

            trial.next();
            initTrial();
        }

        if (fingerCalibrationDone==4 && training)
            areFingersDrawn = !areFingersDrawn;

    }
    break;

    case ' ': // confirm that you grasped
    {
        if(allVisibleFingers)
        {
            iGrasped = true;
            isStimulusDrawn = false;
        }
    }
    break;

    /*		case 't':
    		{
    			training = true;
    			experiment =false;
    			beepOk(0);
    		} break;
    */
    case 'e':
    {
        if(training)
        {
            training = false;
            experiment = true;
            initTrial();
        }
    }
    break;

    case 's':
    {
        if(training)
            initTrial();
    }
    break;

    case 8: // backspace resets calibration
    {
        fingerCalibrationDone=0;
    }
    break;
    }
}
void advanceTrial()
{
	// Determine if previous trial was a good trial
	double percentOccludedFrames = numLostFrames/TGA_frame;
	bool notEnoughFrames = percentOccludedFrames > 0.10 ;
	int overwrite = 0;

	// If any of these things are true when advanceTrial is called, reinsert!
	if (training || !reachedObject || notEnoughFrames ) {
        beepOk(3); // 1000hz, 50ms
		if (training)
			cout << "Training Mode!" << endl;
		if (!reachedObject)
			cout << "I don't think you reached the object..." << endl;
		if (notEnoughFrames)
			cout << "Be visible!" << endl;

		if (!controlCondition) {
			map<std::string,double> currentFactorsList = trial.getCurrent();
			trial.reinsert(currentFactorsList);
		}

		overwrite = 1;
	}

	// Write previous trial to response file
	if (!overwrite && !controlCondition)
	{
		responseFile.precision(3);
		responseFile << 
						parameters.find("SubjectName") << "\t" <<
						trialNumber << "\t" <<
						TGA_time << "\t" <<
						trial.getCurrent()["ObjPosn"] << "\t" <<
                        sm_lg << "\t" <<
						con_inc << "\t" <<
						endl;
	} else if (!overwrite && controlCondition) {
		controlResponseFile.precision(3);
		controlResponseFile << 
						parameters.find("SubjectName") << "\t" <<
						controlTrial << "\t" <<
						TGA_time << "\t" <<
						currentObj << "\t" <<
                        sm_lg << "\t" <<
						con_inc << "\t" <<
						endl;
	}

	// Close previous trial file
	trialFile.close();

	// If we're done with control block
	if (controlCondition && controlTrial==16) {
		if (!overwrite) { // and not overwriting, change over
			plato_stop();
			exit(0);
			//controlCondition=false;
			//endControl=true;
		}
		else // if we ARE overwriting, initTrial again until we get it
			initTrial();
	}
	// If we're still in the control block
	if (controlCondition && controlTrial<16 ){
		if (!overwrite) //and not overwriting
			controlTrial++; //increment
		initTrial(); //initTrial will handle a repeat or the next trial
	}
	// If we're in the main block
	if( !trial.isEmpty() && !controlCondition)
	{
		if (!endControl) { // If it's NOT the v. first main block trial
			if (!overwrite) // and we're not overwriting due to a bad trial
				trialNumber++; // increment
			factors = trial.getNext(); // get the next trial and initialize it!
			initTrial();
		} else { // It IS the v. first main block trial (endControl)
			endControl=false; // turn this switch off so we know next time around that it's trial 1
			initTrial(); // initTrial WITHOUT getNext because we already gotNext at the end of calibration
		}
	}
	// Finally, if we're out of trials, finish the experiment.
	else if (trial.isEmpty() && !controlCondition)
	{
		controlCondition=true;
		initTrial();
	}
}