fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Tue Jul 03 10:50:14 2018 +0000
Revision:
22:41163fb3fdc6
Parent:
20:4c06d3041337
Child:
24:e236faf66935
add debounce mechanisms for lick events

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 19:50663f8815b8 10 struct TrialFlag {
gwappa 19:50663f8815b8 11 bool cued;
gwappa 19:50663f8815b8 12 bool responded;
gwappa 19:50663f8815b8 13 bool reset;
gwappa 19:50663f8815b8 14
gwappa 20:4c06d3041337 15 TrialFlag(): cued(false), responded(false), reset(false) {}
gwappa 19:50663f8815b8 16
gwappa 20:4c06d3041337 17 void clear();
gwappa 19:50663f8815b8 18 void writeToSerial();
gwappa 19:50663f8815b8 19 };
gwappa 2:0c241937eabd 20
gwappa 2:0c241937eabd 21 struct Trial {
gwappa 2:0c241937eabd 22 /**
gwappa 2:0c241937eabd 23 * whether the animal whisked during the cue.
gwappa 2:0c241937eabd 24 * + whether the animal waited for the cue.
gwappa 2:0c241937eabd 25 */
gwappa 19:50663f8815b8 26 TrialFlag flag;
gwappa 19:50663f8815b8 27
gwappa 2:0c241937eabd 28 /**
gwappa 2:0c241937eabd 29 * the timestamp when the trial started.
gwappa 2:0c241937eabd 30 */
gwappa 3:991c6d5ce19d 31 trialtime_t starting;
gwappa 2:0c241937eabd 32 /**
gwappa 2:0c241937eabd 33 * the timestamp when the cue started
gwappa 2:0c241937eabd 34 */
gwappa 3:991c6d5ce19d 35 trialtime_t cuestarting;
gwappa 2:0c241937eabd 36 /**
gwappa 2:0c241937eabd 37 * the total waiting period for the animal during this trial before the cue.
gwappa 2:0c241937eabd 38 */
gwappa 2:0c241937eabd 39 unsigned long waiting; // used for calculation of waiting period
gwappa 2:0c241937eabd 40 /**
gwappa 2:0c241937eabd 41 * the duration of the delay period for this trial.
gwappa 2:0c241937eabd 42 */
gwappa 2:0c241937eabd 43 uint16_t delay_dur_ms;
gwappa 2:0c241937eabd 44
gwappa 13:8ea85a33e37a 45 // (passive) visual cue-related params
gwappa 22:41163fb3fdc6 46 uint64_t vis_onset_us;
gwappa 22:41163fb3fdc6 47 uint64_t vis_dur_us;
gwappa 13:8ea85a33e37a 48
gwappa 17:0b241aa1f5b6 49 /**
gwappa 17:0b241aa1f5b6 50 * a buffer for recording licking events during the trial.
gwappa 17:0b241aa1f5b6 51 */
gwappa 3:991c6d5ce19d 52 ArrayList<trialtime_t> licking_events;
gwappa 17:0b241aa1f5b6 53
gwappa 17:0b241aa1f5b6 54 /**
gwappa 17:0b241aa1f5b6 55 * a buffer for recording whisking events during the trial.
gwappa 17:0b241aa1f5b6 56 */
gwappa 3:991c6d5ce19d 57 ArrayList<trialtime_t> whisking_events;
gwappa 3:991c6d5ce19d 58
gwappa 17:0b241aa1f5b6 59 /**
gwappa 17:0b241aa1f5b6 60 * initialize the trial parameters according to the given Task parameter set.
gwappa 17:0b241aa1f5b6 61 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 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 17:0b241aa1f5b6 73 /**
gwappa 17:0b241aa1f5b6 74 * a callback mechanism for marking (timestamping) the start of the trial.
gwappa 17:0b241aa1f5b6 75 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 76 */
gwappa 11:897ecd5413e0 77 void markTrialStart();
gwappa 17:0b241aa1f5b6 78
gwappa 17:0b241aa1f5b6 79 /**
gwappa 17:0b241aa1f5b6 80 * a callback mechanism for marking (timestamping) the end of the waiting period of the trial.
gwappa 17:0b241aa1f5b6 81 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 82 */
gwappa 11:897ecd5413e0 83 void markEndOfWait();
gwappa 17:0b241aa1f5b6 84
gwappa 17:0b241aa1f5b6 85 /**
gwappa 17:0b241aa1f5b6 86 * a callback mechanism for marking (timestamping) the end of the trial.
gwappa 17:0b241aa1f5b6 87 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 88 */
gwappa 11:897ecd5413e0 89 void markTrialEnd();
gwappa 11:897ecd5413e0 90
gwappa 17:0b241aa1f5b6 91 /**
gwappa 17:0b241aa1f5b6 92 * output the result of a trial into a serial port through the IO mechanism.
gwappa 17:0b241aa1f5b6 93 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 94 */
gwappa 2:0c241937eabd 95 void writeToSerial();
gwappa 2:0c241937eabd 96 };
gwappa 2:0c241937eabd 97
gwappa 2:0c241937eabd 98 #endif