123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- function [Ob, Par] = JA_SBJ_performance(Par,Ob,arg,s)
- %%
- % if a standard trial --> set charger
- % set a frame counter
- % is it a catch trial? --> if yes set the set charge counter --> check if
- % it is below a low_threshold? --> output that no response has been provided within the time limits (1.0 + charge secs)
- % if charger is higher than low_threshold
- %
- %% set parameters
- [~,ifi_as] = JA_frames_function(Par.ifi, Par.ifi);
- [~,~,~,charge_ns] = JA_frames_function(Par.charge, Par.ifi);
- %% assign objects to tobj and tsens variables
- % prepare the piston final position
- player = arg.player;
- tmp_VBL_ball_changes_color = strcat('VBL_ball_changes_color_', player);
- tmp_VBL_ball_back_to_gray = strcat('VBL_ball_back_to_gray_', player);
- start_counting = Par.(tmp_VBL_ball_changes_color){Par.tr};
- target_object = strcat('piston_', player);
- [new_piston_dimensions] = JA_piston_sliding_final_dimension(Ob, target_object);
- % set the EEG trigger code value for the current trial
- piston_trigger_name = strcat(target_object, '_Trigger');
- value_hitting_piston = Par.final_design.(piston_trigger_name)(Par.tr);
- % set the target sensors to be checked
- sens = strcat('arduino_', arg.sensor);
- tsens = Ob.(sens); % piston_SBJ
- % set the position to extract after reading from arduino
- switch sens
- case 'arduino_CF_RISP'
- reading_from_arduino_position = 1;
- case 'arduino_SBJ_RISP'
- reading_from_arduino_position = 3;
- case 'arduino_SBJ_DCG'
- reading_from_arduino_position = 2;
- end
- % get baseline pressure
- baseline = Par.baseline{Par.tr}.(arg.sensor);
- % proportion of change from bs
- baseline_percentage = [0.05 1.4];
- % set valid response time window
- valid_response_window = [0.15 1] + Par.charge; % RT + charge delay
- tmp_turn = strcat(player, '_colors');
- correct_response = Par.final_design.(tmp_turn){Par.tr};
- switch correct_response
- case 'lift_color'
- charger_threshold = -charge_ns;
- case 'press_color'
- charger_threshold = charge_ns;
- case 'catch_color' % it does not matter which threshold is placed here
- charger_threshold = charge_ns;
- end
- charger = 0;% charger_threshold;
- RT = nan;
- %%
- % get timing at this point, after the color got gray again (0.0667 ms theoretically)
- initial_time_counting = Par.(tmp_VBL_ball_back_to_gray){Par.tr};
- % set stop signal
- done = 0;
- % set cycle counter
- t = 1;
- abstime(t) = initial_time_counting;
- % while the stop signal is off
- while (done == 0)
-
- % increase counter
- t = t+1;
- % read sensor status
- JA_inside_fun_READ_WRITE();
-
- % timestamp of first cycle is the initial timestamp
- abstime(t) = GetSecs;
- estimate(t) = abstime(t) - abstime(t-1);
-
- JA_inside_fun_CHARGER();
-
- JA_inside_fun_CHECK_CHARGER_STATUS();
- end
- %% hit the ball
- tmp_piston_name = strcat('VBL_piston_', player);
- Ob.(target_object).dimension = new_piston_dimensions;
- % print on front screen what is going on and get a VBL timing
- [Ob, Par]= JA_Load_Obj_On_Screen(Par, Ob);
- [Par.VBL] = Screen(Par.window, 'Flip');
- % get VBL of piston hitting the ball
- Par.(tmp_piston_name){Par.tr} = Par.VBL;
- % EEG trigger code for color change
- EEG_Trigger(Par.PP,Par.address,value_hitting_piston);
- %%
- tmp_name_RT = strcat(player, '_RT_tmp');
- tmp_name_performance = strcat(player, '_performance_Type');
- tmp_name_classification = strcat(player, '_classification');
- % when the while cycle has stopped
- Par.(tmp_name_RT){Par.tr} = RT;
- Par.(tmp_name_classification){Par.tr} = classification;
- Par.final_design.(tmp_name_performance){Par.tr} = Par.(tmp_name_classification){Par.tr};
- %% read and write
- function [] = JA_inside_fun_READ_WRITE()
- % WRITE ON THE SERIAL AND GET VALUE FROM ARDUINO
- tmp_value = scrittura(s);
-
- % slpit the 3 values that are read from the three pins in arduino
- tmp2 = (strsplit(tmp_value, '_'));
-
- % assign the read value to the tsarget sensor tsens
- tsens.val = str2double(tmp2{reading_from_arduino_position});
- end
- %% check if the pressure has changed from the baseline and charge the charger in case
- function []= JA_inside_fun_CHARGER()
-
- % if the detected pressure is within baseline_percentage values (nothing has changed)
- if tsens.val >= baseline_percentage(1)*baseline && tsens.val <= baseline_percentage(2)*baseline;
- charger_tmp = 0; % caricatore rimane a zero
-
- else % if a significant deviation from baseline has been detected
-
- % in case the pressure is increasing
- if tsens.val > baseline_percentage(2)*baseline
- charger_tmp = estimate(t);%sum(length(t-increase+1:t));
- end
-
- % in case pressure is decreasing
- if tsens.val < baseline_percentage(1)*baseline
- charger_tmp = -estimate(t);
- end
- end
-
- % cumulatively charge the variable charger until it reaches charger_threshold;
- % note that if the charge_threshold is positive(negative) and SBJ is (pressing)lifting, the charger will tend towards 0
- % if no significant change from baseline is detected, charger will
- % remain at the previous level
- charger = charger + charger_tmp;
-
-
- % Set a maximum/minimum
- % In case final_count_down goes above the max or below the min, set
- % it either to the max or to the min
- % if charger >= charger_threshold;
- % charger = charger_threshold;
- % end
- %
- % if charger <= charger_threshold;
- % charger = charger_threshold;
- % end
- if strcmp(Par.final_design.CF_colors{Par.tr}, 'catch_color') && abs(charger)>Par.threshold_catch_response;
- % in a catch trial, if SBJ produces even a brief response that does not charge the charger completely
- % the charger will be set to maximum/minimum --> the script
- % detects a response
- charger = charger_threshold;
- end
-
- end
- %% check charger status and decide what to do based on it
- function [] = JA_inside_fun_CHECK_CHARGER_STATUS()
-
- % get time from color change
- getTime = GetSecs - start_counting;
-
- % if pressed enough time in a press trial
- if charger_threshold > 0 && (charger >= charger_threshold)
-
- if getTime <= valid_response_window(1) % response too fast...
-
- disp('pressed too fast')
- RT = getTime;
- classification = 'out_fast_press';
- done = 1;
-
- else
-
- disp('pressed enough time in a press trial')
- RT = getTime;
- classification = 'press';
- done = 1;
-
- end
- end
-
-
- % if lifted enough time in a lift trial
- if charger_threshold < 0 && (charger <= charger_threshold)
-
- if getTime <= valid_response_window(1) % response too fast...
- disp('lifted too fast')
- RT = getTime;
- classification = 'out_fast_lift';
- done = 1;
-
- else
-
- disp('lifted enough time in a lift trial')
- RT = getTime;
- classification = 'lift';
- done = 1;
-
- end
- end
-
- % if no (correct) response has been provided within the time limits...
- if getTime >= valid_response_window(2) % response too slow, or catch trials
- disp('no (correct) response provided')
- RT = getTime;
- classification = 'no_response';
- done = 1;
- end
-
-
- % for warming_up failed trials...
- if charger_threshold > 0 && (charger <= -Par.threshold_catch_response) && strcmp(Par.relationship, 'warming_up')
-
- RT = getTime;
- classification = 'wrong_response';
- done = 1;
- end
-
-
- if charger_threshold < 0 && (charger >= Par.threshold_catch_response) && strcmp(Par.relationship, 'warming_up')
-
- RT = getTime;
- classification = 'wrong_response';
- done = 1;
- end
-
- end
- end
|