JA_CF_performance.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. function [Ob,Par] = JA_CF_performance(Par, Ob)
  2. %% Wait the selected seconds before make the piston hit the ball
  3. %% distinguish between catch and real trials, then calculate waiting time
  4. if strcmp(Par.final_design.CF_colors{Par.tr}, 'catch_color') % independently of whether is an ok or failed catch
  5. waiting_time = Par.final_design.CF_response_timings(Par.tr)+Par.charge;
  6. else
  7. % in case it is a normal trial, switch on final.design.Type
  8. switch Par.final_design.Type{Par.tr}
  9. case {'slow_tr','fast_tr'}
  10. waiting_time = ...
  11. Par.SBJ_RT_median{Par.tr} +... % SBJ_RT already includes charge
  12. Par.final_design.CF_response_timings(Par.tr)
  13. %+Par.charge;
  14. case {'out_slow','out_fast'}
  15. waiting_time = Par.final_design.CF_response_timings(Par.tr)+ Par.charge;
  16. end
  17. end
  18. %% calculate waiting_time
  19. [~, wt_as] = JA_frames_function(waiting_time, Par.ifi);
  20. %% when should I deliver the TMS pulse
  21. if strcmp(Par.TMS_delay, '-0.05')
  22. % from the piston hitting time subtract an amount of time, the result is the TMS delay from color change
  23. [~,TMS_delay_as] = JA_frames_function(waiting_time - abs(Par.final_design.TMS(Par.tr)), Par.ifi);
  24. end
  25. if strcmp(Par.TMS_delay, '0.0')
  26. % add a +/- 50 ms delay to the median SBJ_RT
  27. [~,TMS_delay_as] = JA_frames_function(Par.SBJ_RT_median{Par.tr} + Par.final_design.TMS(Par.tr)-Par.charge, Par.ifi);
  28. end
  29. %% the ball has to become gray (initial_color) again
  30. % prepare the piston final position
  31. target_object = 'piston_CF';
  32. [new_piston_dimensions] = JA_piston_sliding_final_dimension(Ob, target_object);
  33. % set the EEG trigger code value for the current trial
  34. piston_trigger_name = strcat(target_object, '_Trigger');
  35. value = Par.final_design.(piston_trigger_name)(Par.tr);
  36. %%
  37. if TMS_delay_as == wt_as % if fddelay beteen hitting and tms is zero
  38. % prepare new piston position
  39. target_object = 'piston_CF';
  40. Ob.(target_object).dimension = new_piston_dimensions;
  41. [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
  42. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL_ball_changes_color_CF{Par.tr}+TMS_delay_as);
  43. can_i_trigger = 1;
  44. disp('TMS delivered')
  45. [can_i_trigger] = PP_Trigger(Par.PP,Par.address,can_i_trigger);
  46. % get VBL of TMS pulse
  47. Par.VBL_TMS{Par.tr} = Par.VBL;
  48. % get VBL of piston hitting the ball
  49. Par.VBL_piston_CF{Par.tr} = Par.VBL;
  50. % EEG trigger code for color change
  51. EEG_Trigger(Par.PP,Par.address,value);
  52. else % if it is different from zero, do tms and hitting in sequence
  53. % prepare delay for TMS pulse
  54. % print on front screen what is going on and get a VBL timing
  55. [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
  56. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL_ball_changes_color_CF{Par.tr}+TMS_delay_as);
  57. can_i_trigger = 1;
  58. disp('TMS delivered')
  59. [can_i_trigger] = PP_Trigger(Par.PP,Par.address,can_i_trigger);
  60. % get VBL of TMS pulse
  61. Par.VBL_TMS{Par.tr} = Par.VBL;
  62. % prepare new piston position
  63. target_object = 'piston_CF';
  64. Ob.(target_object).dimension = new_piston_dimensions;
  65. % load and print on screen
  66. [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
  67. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL_ball_changes_color_CF{Par.tr}+wt_as);
  68. % get VBL of piston hitting the ball
  69. Par.VBL_piston_CF{Par.tr} = Par.VBL;
  70. % EEG trigger code for color change
  71. EEG_Trigger(Par.PP,Par.address,value);
  72. end
  73. end
  74. % end