ISP_MoBi_get_maximal_force.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. function [max_force_left, max_force_right] = ISP_MoBi_get_maximal_force(window, misure_schermo, ifi,s,time_x_avg, estimation_time)
  2. [ifi_af, ifi_as, ifi_nf, ifi_ns] = MoBI_frames_Brescia(ifi, ifi);
  3. [onesec_af, onesec_as, onesec_nf, onesec_ns] = MoBI_frames_Brescia(1, ifi);
  4. %% INSTRUCTION FOR FORCE ESTIMATION LEFT SIDE
  5. Screen('FillRect', window, [0 0 0], misure_schermo);
  6. % "at the Go signal press the sensor in the left hand as strong as you can until the stop signal"
  7. Screen('TextSize', window, 20);
  8. DrawFormattedText(window, 'al "Via!" premi il sensore SINISTRO più possibile fino allo "stop" ', 'center',...
  9. 'center', [1 1 1]);
  10. [VBL]=Screen(window, 'Flip', ifi, 1);
  11. %% WAIT FOR A KEYBOARD TYPING
  12. KbStrokeWait
  13. %% start the estimation
  14. % DISPLAY 1, 2, 3, Go! (Via!)
  15. for p = 1:3
  16. Screen('FillRect', window, [0 0 0], misure_schermo);
  17. Screen('TextSize', window, 80);
  18. DrawFormattedText(window, num2str(p), 'center',...
  19. 'center', [1 1 1]);
  20. [VBL]=Screen(window, 'Flip', VBL+onesec_as, 1);
  21. end
  22. % Go!
  23. Screen('FillRect', window, [0 0 0], misure_schermo);
  24. Screen('TextSize', window, 80);
  25. DrawFormattedText(window, 'Via!', 'center',...
  26. 'center', [1 1 1]);
  27. [VBL]=Screen(window, 'Flip', VBL+onesec_as, 1);
  28. % set time required for the estimation
  29. estimation_max_force_time = estimation_time;
  30. % wait 0.2 sec after Via! appeared...
  31. WaitSecs(0.2)
  32. %% READ VALUES FROM A0 (FIRST PIN) --> GET MAXIMAL FORCE
  33. for t = 1:round(estimation_max_force_time/ifi_ns); % for the number of frames in the estimation time...
  34. % ardunio writes onto the serial port, matlab reads
  35. tmp_value{t} = MoBi_scrittura(s);
  36. % strsplit the 3 values that are read from the three pins in arduino
  37. tmp2{t} = (strsplit(tmp_value{t}, '_'));
  38. % convert the reading from string to double type
  39. sensore_val(t) = str2double(tmp2{t}{1});
  40. % do the process at each frame...
  41. Screen('FillRect', window, [0 0 0], misure_schermo);
  42. Screen('TextSize', window, 80);
  43. DrawFormattedText(window, num2str(sensore_val(t)), 'center',...
  44. 'center', [1 1 1]);
  45. [VBL]=Screen(window, 'Flip', VBL+ifi_as, 1);
  46. end
  47. % calculate mean force
  48. step =(round(time_x_avg/ifi,0));
  49. for rng = 1:size(sensore_val,2)-step
  50. sensore_val_avg(rng) = mean(sensore_val(1,rng:rng+step),2);
  51. end
  52. % find the maximal value from the recorded series
  53. max_force_left = max(sensore_val_avg);
  54. % stop recording and show STOP label
  55. Screen('FillRect', window, [0 0 0], misure_schermo);
  56. Screen('TextSize', window, 80);
  57. DrawFormattedText(window, 'Stop', 'center',...
  58. 'center', [1 1 1]);
  59. [VBL]=Screen(window, 'Flip', VBL+onesec_as, 1);
  60. % wait before going on (we do not care about precision time here)
  61. WaitSecs(0.5)
  62. %% SET MOCK VALUE FOR FORCE
  63. max_force_right = 900;
  64. end