JA_Main_Experiment.m 6.3 KB

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