Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
trial.h@13:8ea85a33e37a, 2018-06-25 (annotated)
- Committer:
- gwappa
- Date:
- Mon Jun 25 13:20:00 2018 +0000
- Revision:
- 13:8ea85a33e37a
- Parent:
- 11:897ecd5413e0
- Child:
- 15:20f7f737c256
add random pulse feature
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 | 13:8ea85a33e37a | 54 | bool vis_cued; |
gwappa | 13:8ea85a33e37a | 55 | uint16_t vis_onset_ms; |
gwappa | 13:8ea85a33e37a | 56 | uint16_t vis_dur_ms; |
gwappa | 13:8ea85a33e37a | 57 | |
gwappa | 11:897ecd5413e0 | 58 | uint64_t aud_ticker_cycle; |
gwappa | 11:897ecd5413e0 | 59 | |
gwappa | 3:991c6d5ce19d | 60 | ArrayList<trialtime_t> licking_events; |
gwappa | 3:991c6d5ce19d | 61 | ArrayList<trialtime_t> whisking_events; |
gwappa | 3:991c6d5ce19d | 62 | |
gwappa | 2:0c241937eabd | 63 | void reset(const Task& task); |
gwappa | 2:0c241937eabd | 64 | |
gwappa | 13:8ea85a33e37a | 65 | /** |
gwappa | 13:8ea85a33e37a | 66 | * a helper function to assign onset & duration randomly for the (passive) visual cue. |
gwappa | 13:8ea85a33e37a | 67 | * |
gwappa | 13:8ea85a33e37a | 68 | * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`. |
gwappa | 13:8ea85a33e37a | 69 | * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`. |
gwappa | 13:8ea85a33e37a | 70 | */ |
gwappa | 13:8ea85a33e37a | 71 | void assignRandomStim(const Task& task); |
gwappa | 13:8ea85a33e37a | 72 | |
gwappa | 11:897ecd5413e0 | 73 | void markTrialStart(); |
gwappa | 11:897ecd5413e0 | 74 | void markEndOfWait(); |
gwappa | 11:897ecd5413e0 | 75 | void markTrialEnd(); |
gwappa | 11:897ecd5413e0 | 76 | |
gwappa | 2:0c241937eabd | 77 | void writeToSerial(); |
gwappa | 2:0c241937eabd | 78 | }; |
gwappa | 2:0c241937eabd | 79 | |
gwappa | 2:0c241937eabd | 80 | #endif |