JA_Training.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. %% initialise workspace
  2. cd('C:\Users\neuro\Desktop\JA_Stage1')
  3. sca;
  4. close all;
  5. clearvars
  6. delete(instrfindall)
  7. tic
  8. tinker = 0;
  9. show_RT = 0;
  10. TMS_delay = {'none'}
  11. cfg = []
  12. cfg.relationship = 'training' %'parallel', 'joint', 'imagery'
  13. cfg.PTP_name = 'S09_pilot';
  14. cfg.TMS_delay = TMS_delay;
  15. [saving_settings, relationship, PTP_name] = JA_saving_settings(cfg);
  16. [window, screen_dimensions, screenNum, CenterX, CenterY, ifi] = JA_Screen_Settings(tinker);
  17. screen_dimensions_ratio = screen_dimensions(4)/screen_dimensions(3);
  18. % % CAMBIARE LE ISTRUZIONI come su manoscritto e agginugere IMAGERY!!!!
  19. % [general_intructions] = JA_instruction_selection_Warming_Up();
  20. GD = JA_CFs_quickness_games_distribution(relationship);
  21. [final_design, game, real_trials, catch_trials] = JA_CFs_trial_type_within_games_alt(GD)
  22. [final_design] = JA_ball_colors_delays(final_design, ifi)
  23. [final_design] = JA_CF_response_delays_and_timings(final_design, ifi)
  24. [final_design] = JA_trigger_values_setting(final_design)
  25. % what response has SBJ provided on his/her own original turn (the second)
  26. final_design(:,14) = cell(size(final_design,1),1);
  27. final_design.Properties.VariableNames{14} = 'SBJ_performance_Type';
  28. % the fifth colum represents the delays
  29. final_design(:,15) = cell(size(final_design,1),1);
  30. final_design.Properties.VariableNames{15} = 'CF_performance_Type';
  31. %%
  32. % clear other opened ports
  33. delete(instrfindall);
  34. clear s
  35. %Set up the serial port
  36. global s;
  37. s = serial('COM5');
  38. set(s, 'BaudRate', 115200); % set BaudRate to 115200 (as in Arduino!!!!!)
  39. % open serial
  40. fopen(s);
  41. WaitSecs(2);
  42. for d = 1:2
  43. scrittura(s);
  44. end
  45. % define PP
  46. ioObj = io64;
  47. status = io64(ioObj);
  48. % specify address where u want to send triggers
  49. address = hex2dec('DFB8'); %select LTP1 output port address
  50. io64(ioObj, address, 0); %set Trigger to zero where it allready should be!!
  51. %%
  52. Par = [];
  53. Par.PTP_name = PTP_name;
  54. Par.window = window;
  55. Par.screen_dimensions = screen_dimensions;
  56. Par.ifi = ifi;
  57. Par.VBL = [];
  58. Par.tr = 1;
  59. Par.real_trials_x_game = real_trials;
  60. Par.catch_trials_x_game = catch_trials;
  61. Par.trials_x_game = real_trials + catch_trials;
  62. Par.charge = 0.3; %secs
  63. Par_baseline{Par.tr} = [];
  64. Par.relationship = relationship;
  65. Par.final_design = final_design;
  66. Par.initial_color = [0.5 0.5 0.5];
  67. Par.lift_color = [1 1 0];%[0 0.5 1];
  68. Par.press_color = [1 0.0 0.0];%[1 0.5 0];
  69. Par.catch_color = [1 0.55 0.0];
  70. Par.color_change_duration = 4*Par.ifi;
  71. Par.address = address;
  72. Par.PP = ioObj;
  73. Par.threshold_catch_response = 0.05;
  74. Par.SBJ_RT_tmp = {[]};
  75. Par.SBJ_RT = {[]};
  76. Par.SBJ_classification = {[]};
  77. Par.SBJ_RT_median = {[]};
  78. Par.CF_RT_tmp = {[]};
  79. Par.CF_RT = {[]};
  80. Par.CF_classification = {[]};
  81. Par.CF_RT_median = {[]};
  82. Par.VBL_first_frame{1} = [];
  83. Par.VBL_ball_landed_on_table_CF{1} = [];
  84. Par.VBL_ball_delay_CF{1} = [];
  85. Par.VBL_ball_changes_color_CF{1} = [];
  86. Par.VBL_ball_back_to_gray_CF{1} = [];
  87. Par.VBL_piston_CF{1} = [];
  88. Par.VBL_TMS{1} = [];
  89. Par.VBL_ball_landed_on_table_SBJ{1} = [];
  90. Par.VBL_ball_changes_color_SBJ{1} = [];
  91. Par.VBL_ball_back_to_gray_SBJ{1} = [];
  92. Par.VBL_piston_SBJ{1} = [];
  93. Par.outcome_feedback_trials = find(diff(cell2mat(Par.final_design.Games)));
  94. Par.warming_up_correctness.catch = {[]};
  95. Par.warming_up_correctness.real = {[]};
  96. %%
  97. HideCursor
  98. for x = 1:size(final_design,1)
  99. Par.tr = x;
  100. % initialize objects on the screen
  101. [Ob, Par] = JA_Initialise_Shapes(Par);
  102. %at the onset check if sensors are pressed and saves the baseline
  103. [bs, Par] = JA_check_hands_Warming_Up(Par, s)
  104. Par.baseline{Par.tr} = bs;
  105. % load the objects on the 'hidden screen' before flipping it on the front
  106. [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
  107. [Par.VBL] = Screen(Par.window, 'Flip');
  108. Par.VBL_first_frame{Par.tr} = Par.VBL;
  109. value = Par.final_design.Trial_Type_Trigger(Par.tr);
  110. EEG_Trigger(Par.PP,Par.address,value);
  111. % trial starts --> ball falls down --> when toiches the table_CF it
  112. Par.VBL_ball_landed_on_table_CF{Par.tr} = [];
  113. arg = [];
  114. arg.player = 'CF';
  115. arg.distanceX = 0; % proportion of the vertical screen side
  116. arg.distanceY = 0.4; % proportion of the vertical screen side
  117. [Ob, Par] = JA_Object_Movement(Par,Ob, arg);
  118. % after a delay change color
  119. Par.VBL_ball_changes_color_CF{Par.tr} = [];
  120. Par.VBL_ball_back_to_gray_CF{Par.tr} = [];
  121. arg = [];
  122. arg.player = 'CF';
  123. [Ob, Par] = JA_Ball_color_change(Par,Ob, arg);
  124. % after CF response waiting time Cf piston hits the ball
  125. Par.VBL_TMS{Par.tr} = [];
  126. Par.VBL_piston_CF{Par.tr} = [];
  127. arg = [];
  128. arg.player = 'CF';
  129. arg.sensor = 'SBJ_DCG';
  130. [Ob, Par] = JA_SBJ_performance(Par,Ob,arg,s)
  131. %[Ob,Par] = JA_CF_performance(Par, Ob);
  132. % SBJ turn starts --> ball moves leftwards --> the ball touches the table_SBJ
  133. Par.VBL_ball_landed_on_table_SBJ{Par.tr} = [];
  134. arg = [];
  135. arg.player = 'SBJ';
  136. arg.distanceX = -0.4; % proportion of the vertical screen side
  137. arg.distanceY = 0.0; % proportion of the vertical screen side
  138. [Ob, Par] = JA_Object_Movement(Par, Ob, arg)
  139. % after a delay change color
  140. Par.VBL_ball_changes_color_SBJ{Par.tr} = [];
  141. Par.VBL_ball_back_to_gray_SBJ{Par.tr} = [];
  142. arg = [];
  143. arg.player = 'SBJ';
  144. [Ob, Par] = JA_Ball_color_change(Par,Ob, arg);
  145. % after SBJ response SBJ's piston hits the ball
  146. Par.VBL_piston_SBJ{Par.tr} = [];
  147. arg = [];
  148. arg.player = 'SBJ';
  149. arg.sensor = 'SBJ_RISP';
  150. [Ob,Par] = JA_SBJ_performance(Par, Ob, arg, s);
  151. % the ball has been hit by SBJ's piston and traveles towards the top
  152. % of the screen
  153. arg = [];
  154. arg.player = 'no_player';
  155. arg.distanceX = 0.0; % proportion of the vertical screen side
  156. arg.distanceY = -0.4; % proportion of the vertical screen side
  157. [Ob, Par] = JA_Object_Movement(Par, Ob, arg)
  158. % feedback screen if something went wrong or catch trial
  159. [Par] = JA_interim_feedback_warming_up(Par);
  160. % outcome feedback
  161. [Par] = JA_outcome_feedback_warming_up(Par);
  162. scrittura(s)
  163. end
  164. sca
  165. save(saving_settings);
  166. end_block_time = toc;