JA_check_hands_Main_Experiment.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. function [sens,Par,s] = JA_check_hands_Main_Experiment(Par, s)
  2. % it checks that before the onset of the trial sensors sense enough pressure
  3. % threshold to be exceeded
  4. threshold = 50;
  5. [~, ifi_as] = JA_frames_function(1, Par.ifi);
  6. initial_test = 0.5; %secs
  7. t = 0;
  8. tic;
  9. scrittura(s);
  10. while t <= initial_test
  11. t = toc;
  12. % check if after 0.5 s the sensors are fine --> if so exit the function
  13. [sens] = JA_inside_fun_READ_WRITE();
  14. end
  15. % if any sensor does not sense enough pressure
  16. if sens.CF < threshold ...
  17. || sens.SBJ_DCG < threshold...
  18. || sens.SBJ_RISP < threshold
  19. while 1 % run the while loop until all the sensors sense pressure above threshold for 3 consecutive seconds
  20. % ask PTP and CF to put fingers on sensors by printing it on
  21. % the screen
  22. JA_inside_fun_FINGER_ON_SENSORS('Dita sui sensori!:-)')
  23. % wait 1 second
  24. WaitSecs(1.0);
  25. % check sensors again
  26. [sens] = JA_inside_fun_READ_WRITE();
  27. % if any of the sensors still do not feel enough pressure
  28. if sens.CF < threshold || sens.SBJ_DCG < threshold || sens.SBJ_RISP < threshold
  29. % go back to the while loop
  30. disp('not enough')
  31. continue
  32. else % in case all sense enough pressure --> start count down of 3 seconds
  33. [sens] = JA_inside_fun_FOR_CYCLE_COUNT_DOWN();
  34. disp('out of for cycle')
  35. % if the for loop ends --> sensors sensed enough pressure
  36. % --> return
  37. end
  38. disp('control last sensor cheking')
  39. if sens.CF > threshold ...
  40. && sens.SBJ_DCG > threshold...
  41. && sens.SBJ_RISP > threshold
  42. % if the cycle inside JA_inside_fun_FOR_CYCLE_COUNT_DOWNend well, exit function
  43. disp('great!')
  44. return
  45. else
  46. disp('not_enough...do it again')
  47. end
  48. end
  49. % fi the while loop spits enough pressure on sensors
  50. % recorded on a period of 0.5 seconds
  51. % exit the function providing sensor values as output
  52. end
  53. %end
  54. disp('good initial conditions')
  55. return % if initial conditions are good, exit function
  56. function [sens] = JA_inside_fun_READ_WRITE()
  57. % get baseline pressure
  58. tmp_value = scrittura(s);
  59. % slpit the 3 values that are read from the three pins in arduino
  60. tmp2 = (strsplit(tmp_value, '_'));
  61. % assign each value to the correct object (the SBJ_DCG is needed to check participnats' engagement effect)
  62. bs = str2double(tmp2);
  63. sens.CF = bs(1); % sensor used by CF to
  64. sens.SBJ_DCG = bs(2);
  65. sens.SBJ_RISP = bs(3);
  66. end
  67. function [] = JA_inside_fun_COUNT_DOWN(number)
  68. cd_num = num2str(number);
  69. % draw black 'hidden screen'
  70. Screen('FillRect', Par.window, [0 0 0], Par.screen_dimensions);
  71. % draw a count down starting from 3 on the hidden screen
  72. Screen('TextSize', Par.window, 80);
  73. DrawFormattedText(Par.window, cd_num, 'center',...
  74. 'center', [0 1 1]);
  75. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+Par.ifi,1);
  76. end
  77. function [] = JA_inside_fun_FINGER_ON_SENSORS(text)
  78. %text = 'Dita sui sensori!:-)';
  79. % draw black background
  80. Screen('FillRect', Par.window, [0 0 0], Par.screen_dimensions);
  81. % set text size
  82. Screen('TextSize', Par.window, 80);
  83. % draw text 'fingers on the sensors!' on the 'hidden screen'
  84. DrawFormattedText(Par.window, text, 'center',...
  85. 'center', [0 1 1]);
  86. % flip the 'hidden screen' to the 'front screen'
  87. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+ifi_as,1);
  88. end
  89. function [sens] = JA_inside_fun_FOR_CYCLE_COUNT_DOWN()
  90. for last_count = 3:-1:1
  91. % display count down
  92. JA_inside_fun_COUNT_DOWN(last_count)
  93. % check sensors --> are they still ok?
  94. [sens] = JA_inside_fun_READ_WRITE();
  95. % if any of them do not feel eonough pressure break the for
  96. % loop --> this will bring the script to the beginning of
  97. %the while loop
  98. if sens.CF < threshold...
  99. || sens.SBJ_DCG < threshold...
  100. || sens.SBJ_RISP < threshold
  101. ...go back to the 'while loop' before the for loop
  102. disp('at least one sensor does not sense...go back to while');
  103. break
  104. end
  105. % wait before starting the next count
  106. WaitSecs(0.5);
  107. end
  108. end
  109. end