123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- function JA_Main_Experiment_Stage2(r_block, data_subject, PTP_name)
- %% initialise workspace
- addpath('C:\Users\neuro\Desktop\JA_Stage1');
- cd('C:\Users\neuro\Desktop\JA_Stage2');
- sca;
- close all;
- delete(instrfindall)
- %
- tinker = 0;
- show_RT = 0;
- relationship = r_block{1};
- TMS_delay = {'-0.05'} % from -100 to-0 from CF response
- tic;
- cfg = []
- cfg.relationship = relationship;%'competitive' %'parallel', 'joint', 'imagery'
- cfg.PTP_name = PTP_name;
- cfg.TMS_delay = TMS_delay;
- % [saving_settings, relationship, PTP_name] = JA_saving_settings(cfg);
- %
- [window, screen_dimensions, screenNum, CenterX, CenterY, ifi] = JA_Screen_Settings(tinker);
- screen_dimensions_ratio = screen_dimensions(4)/screen_dimensions(3);
- GD = JA_CFs_quickness_games_distribution(relationship);
- % final design is a table containing all the info of each trial
- [final_design, game, real_trials, catch_trials] = JA_CFs_trial_type_within_games_Stage2(GD);
- % add balanced out_slow and out_fast
- [final_design] = JA_Add_balanced_OUT_trials_CFs_within_games_Stage2(final_design)
- % add delays between ball landing and color appearence
- [final_design] = JA_ball_colors_delays(final_design, ifi)
- % CF's response delays
- [final_design] = JA_CF_response_delays_and_timings(final_design, ifi)
- % trigger values
- [final_design] = JA_trigger_values_setting(final_design)
- % PTP (SBJ) performance type
- final_design(:,14) = cell(size(final_design,1),1);
- final_design.Properties.VariableNames{14} = 'SBJ_performance_Type';
- % TMS delays
- [final_design] = JA_TMS_random_delays(final_design, TMS_delay, ifi)
- %% clear other opened ports
- delete(instrfindall);
- clear s
- %Set up the serial port
- global s;
- s = serial('COM5'); % serial COM for Arduino connection. different for different systems
- set(s, 'BaudRate', 115200); % set BaudRate to 115200 (as in Arduino!!!!!)
- % open serial
- fopen(s);
- WaitSecs(2);
- for d = 1:2
- scrittura(s); % scrittura reads instantaneous arduino values from the three pressure sensors
- end
- % define Parallel Port (mex file utility)
- % downloadable here
- % http://apps.usd.edu/coglab/psyc770/IO64.html
- ioObj = io64;
- status = io64(ioObj);
- % specify address where you want to send triggers (assumning triggering on the rise front of the TTL)
- address = hex2dec('DFB8'); %select LTP1 output port address (different for different systems)
- io64(ioObj, address, 0); %initialise the parallel port "out" pins to zero
- %%
- % Par is going to be the structure that contains all the infos
- Par = [];
- Par.PTP_name = PTP_name;
- Par.window = window;
- Par.screen_dimensions = screen_dimensions;
- Par.ifi = ifi; % 60Hz in our system
- Par.VBL = [];
- Par.tr = 1; % trial number
- Par.real_trials_x_game = real_trials;
- Par.catch_trials_x_game = catch_trials;
- Par.trials_x_game = real_trials + catch_trials;
- Par.charge = 0.3; % piston delay after press/lift threshold has been reached (secs)
- Par_baseline{Par.tr} = [];
- Par.relationship = relationship;
- Par.final_design = final_design;
- Par.initial_color = [0.5 0.5 0.5];
- Par.lift_color = [1 1 0];%yellow
- Par.press_color = [1 0.0 0.0];% red
- Par.catch_color = [1 0.55 0.0]; % orange
- Par.color_change_duration = 4*Par.ifi; %0.067 secs
- Par.address = address;
- Par.PP = ioObj;
- Par.threshold_catch_response = 0.05;
- Par.SBJ_RT_tmp = {[]};
- Par.SBJ_RT = {[]};
- Par.SBJ_classification = {[]};
- Par.SBJ_RT_median = {[]};
- Par.CF_RT = {[]};
- Par.CF_RT_median = {[]};
- Par.VBL_first_frame{1} = [];
- Par.VBL_ball_landed_on_table_CF{1} = [];
- Par.VBL_ball_delay_CF{1} = [];
- Par.VBL_ball_changes_color_CF{1} = [];
- Par.VBL_ball_back_to_gray_CF{1} = [];
- Par.VBL_piston_CF{1} = [];
- Par.VBL_TMS{1} = [];
- Par.TMS_delay = TMS_delay;
- Par.VBL_ball_landed_on_table_SBJ{1} = [];
- Par.VBL_ball_changes_color_SBJ{1} = [];
- Par.VBL_ball_back_to_gray_SBJ{1} = [];
- Par.VBL_piston_SBJ{1} = [];
- Par.outcome_feedback_trials = find(diff(cell2mat(Par.final_design.Games)));
- % task instructions from pictures
- JA_instruction_selection(Par);
- %%
- HideCursor
- switch Par.relationship
-
- case 'warming_up'
- % parallel port triggering (only EEG trigger, no TMS)
- % according to the relationship condition of the block
- EEG_Trigger(Par.PP,Par.address,122);
-
- case 'training'
-
- EEG_Trigger(Par.PP,Par.address,123);
-
- case 'joint'
-
- EEG_Trigger(Par.PP,Par.address,124);
-
- case 'parallel'
-
- EEG_Trigger(Par.PP,Par.address,125);
-
- case 'competitive'
-
- EEG_Trigger(Par.PP,Par.address,126);
-
- case 'imagery'
- EEG_Trigger(Par.PP,Par.address,127);
-
- end
- %%
- for x = 1:size(final_design,1)
- Par.tr = x;
-
- % calculate the CF_RT for the following trial
- % better here in order not to waste run-time
- % initialise CF and SBJ RTs
- Par.CF_RT{Par.tr} = [];
- Par.SBJ_RT{Par.tr} = [];
- [Par] = JA_Average_previous_trials(Par);
-
- % initialize objects on the screen
- [Ob, Par] = JA_Initialise_Shapes(Par);
-
- %at the onset check if sensors are pressed and saves the baseline
- %(initial pressure conditions which will be used to detect lifts and presses)
- [bs, Par] = JA_check_hands_Main_Experiment(Par,s);
- Par.baseline{Par.tr} = bs;
-
-
- % load the objects on the 'hidden background screen' before flipping it on the
- % forescreen
- [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
- [Par.VBL] = Screen(Par.window, 'Flip');
- Par.VBL_first_frame{Par.tr} = Par.VBL;
- value = Par.final_design.Trial_Type_Trigger(Par.tr);
- EEG_Trigger(Par.PP,Par.address,value);
-
-
-
-
- % trial starts --> ball falls down --> when toiches the table_CF it
- Par.VBL_ball_landed_on_table_CF{Par.tr} = [];
-
- arg = [];
- arg.player = 'CF';
- arg.distanceX = 0; % proportion of the horizontal screen side
- arg.distanceY = 0.4; % proportion of the vertical screen side
-
- [Ob, Par] = JA_Object_Movement(Par,Ob, arg);
-
-
-
- % after a delay --> change ball color
- Par.VBL_ball_changes_color_CF{Par.tr} = [];
- Par.VBL_ball_back_to_gray_CF{Par.tr} = [];
-
- arg = [];
- arg.player = 'CF';
- [Ob, Par] = JA_Ball_color_change(Par,Ob, arg);
-
-
-
-
- % after CF response waiting time CF piston hits the ball
-
- Par.VBL_TMS{Par.tr} = [];
- Par.VBL_piston_CF{Par.tr} = [];
-
- [Ob,Par] = JA_CF_performance(Par, Ob);
-
-
-
- % SBJ turn starts --> ball moves leftwards --> the ball touches the table_SBJ
- Par.VBL_ball_landed_on_table_SBJ{Par.tr} = [];
-
- arg = [];
- arg.player = 'SBJ';
- arg.distanceX = -0.4; % proportion of the vertical screen side
- arg.distanceY = 0.0; % proportion of the vertical screen side
-
- [Ob, Par] = JA_Object_Movement(Par,Ob, arg);
-
-
- % after a delay change color
- Par.VBL_ball_changes_color_SBJ{Par.tr} = [];
- Par.VBL_ball_back_to_gray_SBJ{Par.tr} = [];
-
- arg = [];
- arg.player = 'SBJ';
- [Ob, Par] = JA_Ball_color_change(Par,Ob, arg);
-
-
- % after SBJ response SBJ's piston hits the ball
- Par.VBL_piston_SBJ{Par.tr} = [];
-
- arg = [];
- arg.player = 'SBJ';
- arg.sensor = 'SBJ_RISP';
- [Ob,Par] = JA_SBJ_performance(Par, Ob, arg, s);
-
-
- % the ball has been hit by SBJ's piston and travels towards the top
- % of the screen
- arg = [];
- arg.player = 'no_player';
- arg.distanceX = 0.0; % proportion of the vertical screen side
- arg.distanceY = -0.4; % proportion of the vertical screen side
-
- [Ob, Par] = JA_Object_Movement(Par,Ob, arg);
-
-
- % feedback screen if something went wrong or catch trial
-
-
- % in order to avoid messages on the CF side in motor imagery blocks
- if strcmp(Par.relationship, 'imagery')
- [Par] = JA_interim_feedback_IMAGERY_Stage_2(Par);
-
- else
-
- [Par] = JA_interim_feedback(Par)
-
- end
-
-
- % outcome feedback: it presents outcome about the game performance.
- % motor imagery outcome feedbacks are already taken care of
- % inside the function
- [Par] = JA_outcome_feedback(Par, GD)
-
- scrittura(s)
-
- end
- sca
- % save(saving_settings);
- save(data_subject);
- end_block_time = toc;
- end
|