fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Sat Jun 30 12:28:18 2018 +0000
Revision:
16:33c17c62840e
Parent:
15:20f7f737c256
Child:
17:0b241aa1f5b6
add delay for reward in the Pair paradigm

Who changed what in which revision?

UserRevisionLine numberNew 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 3:991c6d5ce19d 59 ArrayList<trialtime_t> licking_events;
gwappa 3:991c6d5ce19d 60 ArrayList<trialtime_t> whisking_events;
gwappa 3:991c6d5ce19d 61
gwappa 2:0c241937eabd 62 void reset(const Task& task);
gwappa 2:0c241937eabd 63
gwappa 13:8ea85a33e37a 64 /**
gwappa 13:8ea85a33e37a 65 * a helper function to assign onset & duration randomly for the (passive) visual cue.
gwappa 13:8ea85a33e37a 66 *
gwappa 13:8ea85a33e37a 67 * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`.
gwappa 13:8ea85a33e37a 68 * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`.
gwappa 13:8ea85a33e37a 69 */
gwappa 13:8ea85a33e37a 70 void assignRandomStim(const Task& task);
gwappa 13:8ea85a33e37a 71
gwappa 11:897ecd5413e0 72 void markTrialStart();
gwappa 11:897ecd5413e0 73 void markEndOfWait();
gwappa 11:897ecd5413e0 74 void markTrialEnd();
gwappa 11:897ecd5413e0 75
gwappa 2:0c241937eabd 76 void writeToSerial();
gwappa 2:0c241937eabd 77 };
gwappa 2:0c241937eabd 78
gwappa 2:0c241937eabd 79 #endif