fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Mon Jul 02 08:26:44 2018 +0000
Revision:
19:50663f8815b8
Parent:
17:0b241aa1f5b6
Child:
20:4c06d3041337
try changing the flag system over to a set of booleans

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 19:50663f8815b8 15 TrialFlag() cued(false), responded(false), reset(false) {}
gwappa 19:50663f8815b8 16
gwappa 19:50663f8815b8 17 void reset();
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 16:33c17c62840e 46 uint16_t vis_onset_us;
gwappa 16:33c17c62840e 47 uint16_t vis_dur_us;
gwappa 13:8ea85a33e37a 48
gwappa 11:897ecd5413e0 49 uint64_t aud_ticker_cycle;
gwappa 11:897ecd5413e0 50
gwappa 17:0b241aa1f5b6 51 /**
gwappa 17:0b241aa1f5b6 52 * a buffer for recording licking events during the trial.
gwappa 17:0b241aa1f5b6 53 */
gwappa 3:991c6d5ce19d 54 ArrayList<trialtime_t> licking_events;
gwappa 17:0b241aa1f5b6 55
gwappa 17:0b241aa1f5b6 56 /**
gwappa 17:0b241aa1f5b6 57 * a buffer for recording whisking events during the trial.
gwappa 17:0b241aa1f5b6 58 */
gwappa 3:991c6d5ce19d 59 ArrayList<trialtime_t> whisking_events;
gwappa 3:991c6d5ce19d 60
gwappa 17:0b241aa1f5b6 61 /**
gwappa 17:0b241aa1f5b6 62 * initialize the trial parameters according to the given Task parameter set.
gwappa 17:0b241aa1f5b6 63 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 64 */
gwappa 2:0c241937eabd 65 void reset(const Task& task);
gwappa 2:0c241937eabd 66
gwappa 13:8ea85a33e37a 67 /**
gwappa 13:8ea85a33e37a 68 * a helper function to assign onset & duration randomly for the (passive) visual cue.
gwappa 13:8ea85a33e37a 69 *
gwappa 13:8ea85a33e37a 70 * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`.
gwappa 13:8ea85a33e37a 71 * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`.
gwappa 13:8ea85a33e37a 72 */
gwappa 13:8ea85a33e37a 73 void assignRandomStim(const Task& task);
gwappa 13:8ea85a33e37a 74
gwappa 17:0b241aa1f5b6 75 /**
gwappa 17:0b241aa1f5b6 76 * a callback mechanism for marking (timestamping) the start of the trial.
gwappa 17:0b241aa1f5b6 77 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 78 */
gwappa 11:897ecd5413e0 79 void markTrialStart();
gwappa 17:0b241aa1f5b6 80
gwappa 17:0b241aa1f5b6 81 /**
gwappa 17:0b241aa1f5b6 82 * a callback mechanism for marking (timestamping) the end of the waiting period of the trial.
gwappa 17:0b241aa1f5b6 83 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 84 */
gwappa 11:897ecd5413e0 85 void markEndOfWait();
gwappa 17:0b241aa1f5b6 86
gwappa 17:0b241aa1f5b6 87 /**
gwappa 17:0b241aa1f5b6 88 * a callback mechanism for marking (timestamping) the end of the trial.
gwappa 17:0b241aa1f5b6 89 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 90 */
gwappa 11:897ecd5413e0 91 void markTrialEnd();
gwappa 11:897ecd5413e0 92
gwappa 17:0b241aa1f5b6 93 /**
gwappa 17:0b241aa1f5b6 94 * output the result of a trial into a serial port through the IO mechanism.
gwappa 17:0b241aa1f5b6 95 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 96 */
gwappa 2:0c241937eabd 97 void writeToSerial();
gwappa 2:0c241937eabd 98 };
gwappa 2:0c241937eabd 99
gwappa 2:0c241937eabd 100 #endif