JA_Training_Stage2.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. function [exclusion_training, criteria] = JA_Training_Stage2(r_block, data_subject, PTP_name)
  2. % The structure of the script is the same as JA_Main_Experiment_Stage2.m
  3. % with the following difference (check out the main_expeirment function, before this one)
  4. % 1) no CF is present for in this block. PTP (SBJ in the scripts) provides responses on both
  5. % turns.
  6. % 2) No TMS delivered.
  7. % differently from the Main Experiment blocks
  8. % PTP (SBJ) provides responses in both turns, first with his/her right hand
  9. % then, with the left hand in the second turn
  10. % some features in the Par structure are similar to the main_experiment
  11. % function, even though no TMS is present and no CF is present
  12. %% initialise workspace
  13. addpath('C:\Users\neuro\Desktop\JA_Stage1');
  14. cd('C:\Users\neuro\Desktop\JA_Stage2');
  15. sca;
  16. close all;
  17. delete(instrfindall)
  18. tic
  19. tinker = 0;
  20. show_RT = 0;
  21. TMS_delay = {'none'}
  22. cfg = []
  23. cfg.relationship = 'training'
  24. cfg.PTP_name = PTP_name;
  25. cfg.TMS_delay = TMS_delay;
  26. [saving_settings, relationship, PTP_name] = JA_saving_settings(cfg);
  27. [window, screen_dimensions, screenNum, CenterX, CenterY, ifi] = JA_Screen_Settings(tinker);
  28. screen_dimensions_ratio = screen_dimensions(4)/screen_dimensions(3);
  29. GD = JA_CFs_quickness_games_distribution(relationship);
  30. % final design is a table containing all the info of each trial
  31. [final_design, game, real_trials, catch_trials] = JA_CFs_trial_type_within_games_alt(GD)
  32. % add delays between ball landing and color appearence
  33. [final_design] = JA_ball_colors_delays(final_design, ifi)
  34. %(leftover from the main experiment function)
  35. [final_design] = JA_CF_response_delays_and_timings(final_design, ifi)
  36. % (leftover from the main experiment function)
  37. [final_design] = JA_trigger_values_setting(final_design)
  38. % what response has SBJ provided on his/her own original turn (the second)
  39. final_design(:,14) = cell(size(final_design,1),1);
  40. final_design.Properties.VariableNames{14} = 'SBJ_performance_Type';
  41. % what response has SBJ provided on his/her own first turn (left hand)
  42. final_design(:,15) = cell(size(final_design,1),1);
  43. final_design.Properties.VariableNames{15} = 'CF_performance_Type';
  44. %%
  45. % clear other opened ports
  46. delete(instrfindall);
  47. clear s
  48. %Set up the serial port
  49. global s;
  50. s = serial('COM5');
  51. set(s, 'BaudRate', 115200); % set BaudRate to 115200 (as in Arduino!!!!!)
  52. % open serial
  53. fopen(s);
  54. WaitSecs(2);
  55. for d = 1:2
  56. scrittura(s);
  57. end
  58. % define Parallel Port (see main_experiment function)
  59. ioObj = io64;
  60. status = io64(ioObj);
  61. % specify address where u want to send triggers
  62. address = hex2dec('DFB8'); %select LTP1 output port address
  63. io64(ioObj, address, 0); %initialisation
  64. %%
  65. Par = [];
  66. Par.PTP_name = PTP_name;
  67. Par.window = window;
  68. Par.screen_dimensions = screen_dimensions;
  69. Par.ifi = ifi;
  70. Par.VBL = [];
  71. Par.tr = 1;
  72. Par.real_trials_x_game = real_trials;
  73. Par.catch_trials_x_game = catch_trials;
  74. Par.trials_x_game = real_trials + catch_trials;
  75. Par.charge = 0.3; %secs
  76. Par_baseline{Par.tr} = [];
  77. Par.relationship = relationship;
  78. Par.final_design = final_design;
  79. Par.initial_color = [0.5 0.5 0.5];
  80. Par.lift_color = [1 1 0];%[0 0.5 1];
  81. Par.press_color = [1 0.0 0.0];%[1 0.5 0];
  82. Par.catch_color = [1 0.55 0.0];
  83. Par.color_change_duration = 4*Par.ifi;
  84. Par.address = address;
  85. Par.PP = ioObj;
  86. Par.threshold_catch_response = 0.05;
  87. Par.SBJ_RT_tmp = {[]};
  88. Par.SBJ_RT = {[]};
  89. Par.SBJ_classification = {[]};
  90. Par.SBJ_RT_median = {[]};
  91. Par.CF_RT_tmp = {[]};
  92. Par.CF_RT = {[]};
  93. Par.CF_classification = {[]};
  94. Par.CF_RT_median = {[]};
  95. Par.VBL_first_frame{1} = [];
  96. Par.VBL_ball_landed_on_table_CF{1} = [];
  97. Par.VBL_ball_delay_CF{1} = [];
  98. Par.VBL_ball_changes_color_CF{1} = [];
  99. Par.VBL_ball_back_to_gray_CF{1} = [];
  100. Par.VBL_piston_CF{1} = [];
  101. Par.VBL_TMS{1} = [];
  102. Par.VBL_ball_landed_on_table_SBJ{1} = [];
  103. Par.VBL_ball_changes_color_SBJ{1} = [];
  104. Par.VBL_ball_back_to_gray_SBJ{1} = [];
  105. Par.VBL_piston_SBJ{1} = [];
  106. Par.outcome_feedback_trials = find(diff(cell2mat(Par.final_design.Games)));
  107. Par.warming_up_correctness.catch = {[]};
  108. Par.warming_up_correctness.real = {[]};
  109. % task instructions
  110. JA_instruction_selection(Par);
  111. %%
  112. HideCursor
  113. switch Par.relationship
  114. case 'warming_up'
  115. EEG_Trigger(Par.PP,Par.address,122);
  116. case 'training'
  117. EEG_Trigger(Par.PP,Par.address,123);
  118. case 'joint'
  119. EEG_Trigger(Par.PP,Par.address,124);
  120. case 'parallel'
  121. EEG_Trigger(Par.PP,Par.address,125);
  122. case 'competitive'
  123. EEG_Trigger(Par.PP,Par.address,126);
  124. case 'imagery'
  125. EEG_Trigger(Par.PP,Par.address,127);
  126. end
  127. %%
  128. for x = 1:size(final_design,1)
  129. Par.tr = x;
  130. % initialize objects on the screen
  131. [Ob, Par] = JA_Initialise_Shapes(Par);
  132. %at the onset check if sensors are pressed and saves the baseline
  133. [bs, Par] = JA_check_hands_Warming_Up(Par, s)
  134. Par.baseline{Par.tr} = bs;
  135. % load the objects on the 'hidden screen' before flipping it on the front
  136. [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
  137. [Par.VBL] = Screen(Par.window, 'Flip');
  138. Par.VBL_first_frame{Par.tr} = Par.VBL;
  139. value = Par.final_design.Trial_Type_Trigger(Par.tr);
  140. EEG_Trigger(Par.PP,Par.address,value);
  141. % trial starts --> ball falls down --> when toiches the table_CF it
  142. Par.VBL_ball_landed_on_table_CF{Par.tr} = [];
  143. arg = [];
  144. arg.player = 'CF';
  145. arg.distanceX = 0; % proportion of the horizontal screen side
  146. arg.distanceY = 0.4; % proportion of the vertical screen side
  147. [Ob, Par] = JA_Object_Movement(Par,Ob, arg);
  148. % after a delay change color
  149. Par.VBL_ball_changes_color_CF{Par.tr} = [];
  150. Par.VBL_ball_back_to_gray_CF{Par.tr} = [];
  151. arg = [];
  152. arg.player = 'CF';
  153. [Ob, Par] = JA_Ball_color_change(Par,Ob, arg);
  154. Par.VBL_TMS{Par.tr} = [];
  155. Par.VBL_piston_CF{Par.tr} = [];
  156. % get responses from PTP's right hand
  157. %(as if he/she was the CF, but getting the pressure values from the SBJ_DCG sensor)
  158. arg = [];
  159. arg.player = 'CF';
  160. arg.sensor = 'SBJ_DCG';
  161. [Ob, Par] = JA_SBJ_performance(Par,Ob,arg,s)
  162. % second turn --> ball moves leftwards --> the ball touches the table_SBJ
  163. Par.VBL_ball_landed_on_table_SBJ{Par.tr} = [];
  164. arg = [];
  165. arg.player = 'SBJ';
  166. arg.distanceX = -0.4; % proportion of the horizontal screen side
  167. arg.distanceY = 0.0; % proportion of the vertical screen side
  168. [Ob, Par] = JA_Object_Movement(Par, Ob, arg)
  169. % after a delay change color
  170. Par.VBL_ball_changes_color_SBJ{Par.tr} = [];
  171. Par.VBL_ball_back_to_gray_SBJ{Par.tr} = [];
  172. arg = [];
  173. arg.player = 'SBJ';
  174. [Ob, Par] = JA_Ball_color_change(Par,Ob, arg);
  175. %..as in the main experiment, get response from the left hand (SBJ_RISP sensor)
  176. Par.VBL_piston_SBJ{Par.tr} = [];
  177. arg = [];
  178. arg.player = 'SBJ';
  179. arg.sensor = 'SBJ_RISP';
  180. [Ob,Par] = JA_SBJ_performance(Par, Ob, arg, s);
  181. % the ball has been hit by SBJ's piston and traveles towards the top
  182. % of the screen
  183. arg = [];
  184. arg.player = 'no_player';
  185. arg.distanceX = 0.0; % proportion of the horizontal screen side
  186. arg.distanceY = -0.4; % proportion of the vertical screen side
  187. [Ob, Par] = JA_Object_Movement(Par, Ob, arg)
  188. % feedback screen if something went wrong or catch trial
  189. [Par] = JA_interim_feedback_warming_up(Par);
  190. % outcome feedback
  191. [Par] = JA_outcome_feedback_warming_up(Par);
  192. scrittura(s)
  193. end
  194. sca
  195. end_block_time = toc;
  196. %%
  197. [abs_number_of_out_of_range_CF,...
  198. out_time_range_percentage_CF,...
  199. abs_number_wrong_catch_CF,...
  200. wrong_catch_percentage_CF,...
  201. abs_number_wrong_responses_last_three_game_CF,...
  202. wrong_response_last_three_games_percentage_CF]= JA_exclusion_criteria_CF(Par);
  203. [abs_number_of_out_of_range_SBJ,...
  204. out_time_range_percentage_SBJ,...
  205. abs_number_wrong_catch_SBJ,...
  206. wrong_catch_percentage_SBj,...
  207. abs_number_wrong_responses_last_three_game_SBJ,...
  208. wrong_response_last_three_games_percentage_SBJ]= JA_exclusion_criteria_SBJ(Par)
  209. %%
  210. total_out_of_time_range_percentage = 100*(abs_number_of_out_of_range_CF + abs_number_of_out_of_range_SBJ)/ (9*12*2)
  211. total_within_time_range_percentage = 100 - total_out_of_time_range_percentage;
  212. total_wrong_catch_percentage = 100*(abs_number_wrong_catch_CF + abs_number_wrong_catch_SBJ)/ (2*12*2)
  213. total_correct_catch_percentage = 100 - total_wrong_catch_percentage;
  214. if (total_correct_catch_percentage < 50) && (total_out_of_time_range_percentage > 30); % if correct responses < 70%
  215. exclusion_training = 1;
  216. else
  217. exclusion_training = 0;
  218. end
  219. criteria.out_of_time = total_out_of_time_range_percentage;
  220. criteria.correct_catch = total_correct_catch_percentage;
  221. save(data_subject);
  222. end