Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
trial.h@17:0b241aa1f5b6, 2018-07-01 (annotated)
- Committer:
- gwappa
- Date:
- Sun Jul 01 13:00:43 2018 +0000
- Revision:
- 17:0b241aa1f5b6
- Parent:
- 16:33c17c62840e
- Child:
- 19:50663f8815b8
change the criterion of a catch trial
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 | 2:0c241937eabd | 4 | #include "task.h" |
gwappa | 3:991c6d5ce19d | 5 | #include "arraylist.h" |
gwappa | 13:8ea85a33e37a | 6 | #include "random.h" |
gwappa | 3:991c6d5ce19d | 7 | |
gwappa | 3:991c6d5ce19d | 8 | typedef int trialtime_t; |
gwappa | 2:0c241937eabd | 9 | |
gwappa | 2:0c241937eabd | 10 | namespace TrialFlags { |
gwappa | 2:0c241937eabd | 11 | // nothing |
gwappa | 2:0c241937eabd | 12 | const char Clear = 0x00; |
gwappa | 2:0c241937eabd | 13 | // flags if the auditory cue is there during the trial |
gwappa | 2:0c241937eabd | 14 | const char Cues = 0x01; |
gwappa | 7:6744ec9ccc25 | 15 | // flags if any "response" is detected during the response window |
gwappa | 2:0c241937eabd | 16 | const char Responded = 0x02; |
gwappa | 2:0c241937eabd | 17 | // flags if licking event is detected during the preparatory/pre-response window |
gwappa | 2:0c241937eabd | 18 | const char Licked = 0x04; |
gwappa | 2:0c241937eabd | 19 | } |
gwappa | 2:0c241937eabd | 20 | |
gwappa | 2:0c241937eabd | 21 | namespace Responses { |
gwappa | 2:0c241937eabd | 22 | const char Hit = 0x03; // cues && responded |
gwappa | 2:0c241937eabd | 23 | const char Miss = 0x01; // cues && ~responded |
gwappa | 2:0c241937eabd | 24 | const char Catch = 0x02; // ~cues && responded |
gwappa | 2:0c241937eabd | 25 | const char Reject = 0x00; // ~cues && ~responded |
gwappa | 2:0c241937eabd | 26 | const char Reset = 0x04; // invalid lick |
gwappa | 2:0c241937eabd | 27 | const char NA = 0x08; // default |
gwappa | 2:0c241937eabd | 28 | } |
gwappa | 2:0c241937eabd | 29 | |
gwappa | 2:0c241937eabd | 30 | struct Trial { |
gwappa | 2:0c241937eabd | 31 | /** |
gwappa | 2:0c241937eabd | 32 | * whether the animal whisked during the cue. |
gwappa | 2:0c241937eabd | 33 | * + whether the animal waited for the cue. |
gwappa | 2:0c241937eabd | 34 | */ |
gwappa | 2:0c241937eabd | 35 | char response; |
gwappa | 2:0c241937eabd | 36 | /** |
gwappa | 2:0c241937eabd | 37 | * the timestamp when the trial started. |
gwappa | 2:0c241937eabd | 38 | */ |
gwappa | 3:991c6d5ce19d | 39 | trialtime_t starting; |
gwappa | 2:0c241937eabd | 40 | /** |
gwappa | 2:0c241937eabd | 41 | * the timestamp when the cue started |
gwappa | 2:0c241937eabd | 42 | */ |
gwappa | 3:991c6d5ce19d | 43 | trialtime_t cuestarting; |
gwappa | 2:0c241937eabd | 44 | /** |
gwappa | 2:0c241937eabd | 45 | * the total waiting period for the animal during this trial before the cue. |
gwappa | 2:0c241937eabd | 46 | */ |
gwappa | 2:0c241937eabd | 47 | unsigned long waiting; // used for calculation of waiting period |
gwappa | 2:0c241937eabd | 48 | /** |
gwappa | 2:0c241937eabd | 49 | * the duration of the delay period for this trial. |
gwappa | 2:0c241937eabd | 50 | */ |
gwappa | 2:0c241937eabd | 51 | uint16_t delay_dur_ms; |
gwappa | 2:0c241937eabd | 52 | |
gwappa | 13:8ea85a33e37a | 53 | // (passive) visual cue-related params |
gwappa | 16:33c17c62840e | 54 | uint16_t vis_onset_us; |
gwappa | 16:33c17c62840e | 55 | uint16_t vis_dur_us; |
gwappa | 13:8ea85a33e37a | 56 | |
gwappa | 11:897ecd5413e0 | 57 | uint64_t aud_ticker_cycle; |
gwappa | 11:897ecd5413e0 | 58 | |
gwappa | 17:0b241aa1f5b6 | 59 | /** |
gwappa | 17:0b241aa1f5b6 | 60 | * a buffer for recording licking events during the trial. |
gwappa | 17:0b241aa1f5b6 | 61 | */ |
gwappa | 3:991c6d5ce19d | 62 | ArrayList<trialtime_t> licking_events; |
gwappa | 17:0b241aa1f5b6 | 63 | |
gwappa | 17:0b241aa1f5b6 | 64 | /** |
gwappa | 17:0b241aa1f5b6 | 65 | * a buffer for recording whisking events during the trial. |
gwappa | 17:0b241aa1f5b6 | 66 | */ |
gwappa | 3:991c6d5ce19d | 67 | ArrayList<trialtime_t> whisking_events; |
gwappa | 3:991c6d5ce19d | 68 | |
gwappa | 17:0b241aa1f5b6 | 69 | /** |
gwappa | 17:0b241aa1f5b6 | 70 | * initialize the trial parameters according to the given Task parameter set. |
gwappa | 17:0b241aa1f5b6 | 71 | * typically called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 72 | */ |
gwappa | 2:0c241937eabd | 73 | void reset(const Task& task); |
gwappa | 2:0c241937eabd | 74 | |
gwappa | 13:8ea85a33e37a | 75 | /** |
gwappa | 13:8ea85a33e37a | 76 | * a helper function to assign onset & duration randomly for the (passive) visual cue. |
gwappa | 13:8ea85a33e37a | 77 | * |
gwappa | 13:8ea85a33e37a | 78 | * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`. |
gwappa | 13:8ea85a33e37a | 79 | * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`. |
gwappa | 13:8ea85a33e37a | 80 | */ |
gwappa | 13:8ea85a33e37a | 81 | void assignRandomStim(const Task& task); |
gwappa | 13:8ea85a33e37a | 82 | |
gwappa | 17:0b241aa1f5b6 | 83 | /** |
gwappa | 17:0b241aa1f5b6 | 84 | * a callback mechanism for marking (timestamping) the start of the trial. |
gwappa | 17:0b241aa1f5b6 | 85 | * called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 86 | */ |
gwappa | 11:897ecd5413e0 | 87 | void markTrialStart(); |
gwappa | 17:0b241aa1f5b6 | 88 | |
gwappa | 17:0b241aa1f5b6 | 89 | /** |
gwappa | 17:0b241aa1f5b6 | 90 | * a callback mechanism for marking (timestamping) the end of the waiting period of the trial. |
gwappa | 17:0b241aa1f5b6 | 91 | * called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 92 | */ |
gwappa | 11:897ecd5413e0 | 93 | void markEndOfWait(); |
gwappa | 17:0b241aa1f5b6 | 94 | |
gwappa | 17:0b241aa1f5b6 | 95 | /** |
gwappa | 17:0b241aa1f5b6 | 96 | * a callback mechanism for marking (timestamping) the end of the trial. |
gwappa | 17:0b241aa1f5b6 | 97 | * called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 98 | */ |
gwappa | 11:897ecd5413e0 | 99 | void markTrialEnd(); |
gwappa | 11:897ecd5413e0 | 100 | |
gwappa | 17:0b241aa1f5b6 | 101 | /** |
gwappa | 17:0b241aa1f5b6 | 102 | * output the result of a trial into a serial port through the IO mechanism. |
gwappa | 17:0b241aa1f5b6 | 103 | * typically called from one of the automaton states. |
gwappa | 17:0b241aa1f5b6 | 104 | */ |
gwappa | 2:0c241937eabd | 105 | void writeToSerial(); |
gwappa | 2:0c241937eabd | 106 | }; |
gwappa | 2:0c241937eabd | 107 | |
gwappa | 2:0c241937eabd | 108 | #endif |