Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
trial.h@29:1fb060aab1f8, 2018-10-01 (annotated)
- Committer:
- gwappa
- Date:
- Mon Oct 01 14:54:37 2018 +0000
- Revision:
- 29:1fb060aab1f8
- Parent:
- 28:797536a42b9f
- Child:
- 30:5f975f572ffb
update task structure
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gwappa | 2:0c241937eabd | 1 | #ifndef TRIAL_H_ |
gwappa | 2:0c241937eabd | 2 | #define TRIAL_H_ |
gwappa | 2:0c241937eabd | 3 | |
gwappa | 3:991c6d5ce19d | 4 | #include "arraylist.h" |
gwappa | 26:b4421d1ee57a | 5 | #include "trialtime.h" |
gwappa | 13:8ea85a33e37a | 6 | #include "random.h" |
gwappa | 3:991c6d5ce19d | 7 | |
gwappa | 26:b4421d1ee57a | 8 | #include "task.h" |
gwappa | 2:0c241937eabd | 9 | |
gwappa | 19:50663f8815b8 | 10 | struct TrialFlag { |
gwappa | 19:50663f8815b8 | 11 | bool cued; |
gwappa | 19:50663f8815b8 | 12 | bool responded; |
gwappa | 29:1fb060aab1f8 | 13 | bool rewarded; // only used during Condition mode |
gwappa | 19:50663f8815b8 | 14 | bool reset; |
gwappa | 19:50663f8815b8 | 15 | |
gwappa | 29:1fb060aab1f8 | 16 | TrialFlag(): cued(false), responded(false), rewarded(false), reset(false) {} |
gwappa | 19:50663f8815b8 | 17 | |
gwappa | 20:4c06d3041337 | 18 | void clear(); |
gwappa | 29:1fb060aab1f8 | 19 | void writeToSerial(const Task& task); |
gwappa | 19:50663f8815b8 | 20 | }; |
gwappa | 2:0c241937eabd | 21 | |
gwappa | 2:0c241937eabd | 22 | struct Trial { |
gwappa | 2:0c241937eabd | 23 | /** |
gwappa | 2:0c241937eabd | 24 | * whether the animal whisked during the cue. |
gwappa | 2:0c241937eabd | 25 | * + whether the animal waited for the cue. |
gwappa | 2:0c241937eabd | 26 | */ |
gwappa | 19:50663f8815b8 | 27 | TrialFlag flag; |
gwappa | 19:50663f8815b8 | 28 | |
gwappa | 2:0c241937eabd | 29 | /** |
gwappa | 2:0c241937eabd | 30 | * the timestamp when the trial started. |
gwappa | 2:0c241937eabd | 31 | */ |
gwappa | 3:991c6d5ce19d | 32 | trialtime_t starting; |
gwappa | 2:0c241937eabd | 33 | /** |
gwappa | 2:0c241937eabd | 34 | * the timestamp when the cue started |
gwappa | 2:0c241937eabd | 35 | */ |
gwappa | 3:991c6d5ce19d | 36 | trialtime_t cuestarting; |
gwappa | 24:e236faf66935 | 37 | |
gwappa | 2:0c241937eabd | 38 | /** |
gwappa | 2:0c241937eabd | 39 | * the total waiting period for the animal during this trial before the cue. |
gwappa | 2:0c241937eabd | 40 | */ |
gwappa | 2:0c241937eabd | 41 | unsigned long waiting; // used for calculation of waiting period |
gwappa | 24:e236faf66935 | 42 | |
gwappa | 2:0c241937eabd | 43 | /** |
gwappa | 2:0c241937eabd | 44 | * the duration of the delay period for this trial. |
gwappa | 2:0c241937eabd | 45 | */ |
gwappa | 2:0c241937eabd | 46 | uint16_t delay_dur_ms; |
gwappa | 2:0c241937eabd | 47 | |
gwappa | 29:1fb060aab1f8 | 48 | // (passive) visual cue-related param in the Associate mode. |
gwappa | 22:41163fb3fdc6 | 49 | uint64_t vis_onset_us; |
gwappa | 13:8ea85a33e37a | 50 | |
gwappa | 17:0b241aa1f5b6 | 51 | /** |
gwappa | 17:0b241aa1f5b6 | 52 | * initialize the trial parameters according to the given Task parameter set. |
gwappa | 17:0b241aa1f5b6 | 53 | * typically called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 54 | */ |
gwappa | 2:0c241937eabd | 55 | void reset(const Task& task); |
gwappa | 2:0c241937eabd | 56 | |
gwappa | 13:8ea85a33e37a | 57 | /** |
gwappa | 13:8ea85a33e37a | 58 | * a helper function to assign onset & duration randomly for the (passive) visual cue. |
gwappa | 13:8ea85a33e37a | 59 | * |
gwappa | 13:8ea85a33e37a | 60 | * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`. |
gwappa | 13:8ea85a33e37a | 61 | * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`. |
gwappa | 13:8ea85a33e37a | 62 | */ |
gwappa | 29:1fb060aab1f8 | 63 | void assignAssociative(const Task& task); |
gwappa | 29:1fb060aab1f8 | 64 | |
gwappa | 29:1fb060aab1f8 | 65 | void assignForFeedback(const Task& task); |
gwappa | 13:8ea85a33e37a | 66 | |
gwappa | 17:0b241aa1f5b6 | 67 | /** |
gwappa | 17:0b241aa1f5b6 | 68 | * a callback mechanism for marking (timestamping) the start of the trial. |
gwappa | 17:0b241aa1f5b6 | 69 | * called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 70 | */ |
gwappa | 11:897ecd5413e0 | 71 | void markTrialStart(); |
gwappa | 17:0b241aa1f5b6 | 72 | |
gwappa | 17:0b241aa1f5b6 | 73 | /** |
gwappa | 17:0b241aa1f5b6 | 74 | * a callback mechanism for marking (timestamping) the end of the waiting period of the trial. |
gwappa | 17:0b241aa1f5b6 | 75 | * called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 76 | */ |
gwappa | 11:897ecd5413e0 | 77 | void markEndOfWait(); |
gwappa | 17:0b241aa1f5b6 | 78 | |
gwappa | 17:0b241aa1f5b6 | 79 | /** |
gwappa | 17:0b241aa1f5b6 | 80 | * a callback mechanism for marking (timestamping) the end of the trial. |
gwappa | 17:0b241aa1f5b6 | 81 | * called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 82 | */ |
gwappa | 29:1fb060aab1f8 | 83 | void markTrialEnd(const Task& task); |
gwappa | 11:897ecd5413e0 | 84 | |
gwappa | 17:0b241aa1f5b6 | 85 | /** |
gwappa | 17:0b241aa1f5b6 | 86 | * output the result of a trial into a serial port through the IO mechanism. |
gwappa | 17:0b241aa1f5b6 | 87 | * typically called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 88 | */ |
gwappa | 29:1fb060aab1f8 | 89 | void writeToSerial(const Task& task); |
gwappa | 2:0c241937eabd | 90 | }; |
gwappa | 2:0c241937eabd | 91 | |
gwappa | 2:0c241937eabd | 92 | #endif |