fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Tue Jul 03 13:58:05 2018 +0000
Revision:
24:e236faf66935
Parent:
22:41163fb3fdc6
Child:
26:b4421d1ee57a
(probably) troubleshoot the reward delivery before cue output

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 24:e236faf66935 36
gwappa 2:0c241937eabd 37 /**
gwappa 2:0c241937eabd 38 * the total waiting period for the animal during this trial before the cue.
gwappa 2:0c241937eabd 39 */
gwappa 2:0c241937eabd 40 unsigned long waiting; // used for calculation of waiting period
gwappa 24:e236faf66935 41
gwappa 2:0c241937eabd 42 /**
gwappa 2:0c241937eabd 43 * the duration of the delay period for this trial.
gwappa 2:0c241937eabd 44 */
gwappa 2:0c241937eabd 45 uint16_t delay_dur_ms;
gwappa 2:0c241937eabd 46
gwappa 24:e236faf66935 47 /**
gwappa 24:e236faf66935 48 * the duration of the cued period for this trial.
gwappa 24:e236faf66935 49 */
gwappa 24:e236faf66935 50 uint64_t cued_dur_us;
gwappa 24:e236faf66935 51
gwappa 13:8ea85a33e37a 52 // (passive) visual cue-related params
gwappa 22:41163fb3fdc6 53 uint64_t vis_onset_us;
gwappa 22:41163fb3fdc6 54 uint64_t vis_dur_us;
gwappa 13:8ea85a33e37a 55
gwappa 17:0b241aa1f5b6 56 /**
gwappa 17:0b241aa1f5b6 57 * a buffer for recording licking events during the trial.
gwappa 17:0b241aa1f5b6 58 */
gwappa 3:991c6d5ce19d 59 ArrayList<trialtime_t> licking_events;
gwappa 17:0b241aa1f5b6 60
gwappa 17:0b241aa1f5b6 61 /**
gwappa 17:0b241aa1f5b6 62 * a buffer for recording whisking events during the trial.
gwappa 17:0b241aa1f5b6 63 */
gwappa 3:991c6d5ce19d 64 ArrayList<trialtime_t> whisking_events;
gwappa 3:991c6d5ce19d 65
gwappa 17:0b241aa1f5b6 66 /**
gwappa 17:0b241aa1f5b6 67 * initialize the trial parameters according to the given Task parameter set.
gwappa 17:0b241aa1f5b6 68 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 69 */
gwappa 2:0c241937eabd 70 void reset(const Task& task);
gwappa 2:0c241937eabd 71
gwappa 13:8ea85a33e37a 72 /**
gwappa 13:8ea85a33e37a 73 * a helper function to assign onset & duration randomly for the (passive) visual cue.
gwappa 13:8ea85a33e37a 74 *
gwappa 13:8ea85a33e37a 75 * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`.
gwappa 13:8ea85a33e37a 76 * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`.
gwappa 13:8ea85a33e37a 77 */
gwappa 24:e236faf66935 78 void assignCues(const Task& task, const bool& assignVisual=true);
gwappa 13:8ea85a33e37a 79
gwappa 17:0b241aa1f5b6 80 /**
gwappa 17:0b241aa1f5b6 81 * a callback mechanism for marking (timestamping) the start of the trial.
gwappa 17:0b241aa1f5b6 82 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 83 */
gwappa 11:897ecd5413e0 84 void markTrialStart();
gwappa 17:0b241aa1f5b6 85
gwappa 17:0b241aa1f5b6 86 /**
gwappa 17:0b241aa1f5b6 87 * a callback mechanism for marking (timestamping) the end of the waiting period of the trial.
gwappa 17:0b241aa1f5b6 88 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 89 */
gwappa 11:897ecd5413e0 90 void markEndOfWait();
gwappa 17:0b241aa1f5b6 91
gwappa 17:0b241aa1f5b6 92 /**
gwappa 17:0b241aa1f5b6 93 * a callback mechanism for marking (timestamping) the end of the trial.
gwappa 17:0b241aa1f5b6 94 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 95 */
gwappa 11:897ecd5413e0 96 void markTrialEnd();
gwappa 11:897ecd5413e0 97
gwappa 17:0b241aa1f5b6 98 /**
gwappa 17:0b241aa1f5b6 99 * output the result of a trial into a serial port through the IO mechanism.
gwappa 17:0b241aa1f5b6 100 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 101 */
gwappa 2:0c241937eabd 102 void writeToSerial();
gwappa 2:0c241937eabd 103 };
gwappa 2:0c241937eabd 104
gwappa 2:0c241937eabd 105 #endif