fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Sun Jul 22 16:25:25 2018 +0000
Revision:
28:797536a42b9f
Parent:
26:b4421d1ee57a
Child:
29:1fb060aab1f8
change Pair mode to Condition mode; add scheduler

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 3:991c6d5ce19d 4 #include "arraylist.h"
gwappa 26:b4421d1ee57a 5 #include "trialtime.h"
gwappa 13:8ea85a33e37a 6 #include "random.h"
gwappa 3:991c6d5ce19d 7
gwappa 26:b4421d1ee57a 8 #include "task.h"
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 * initialize the trial parameters according to the given Task parameter set.
gwappa 17:0b241aa1f5b6 58 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 59 */
gwappa 2:0c241937eabd 60 void reset(const Task& task);
gwappa 2:0c241937eabd 61
gwappa 13:8ea85a33e37a 62 /**
gwappa 13:8ea85a33e37a 63 * a helper function to assign onset & duration randomly for the (passive) visual cue.
gwappa 13:8ea85a33e37a 64 *
gwappa 13:8ea85a33e37a 65 * the `onset` will distribute exponentially from `0` to `auddur - respdur - mindur`.
gwappa 13:8ea85a33e37a 66 * the `duration` will distribute uniformly from `mindur` to `phasedur - onset`.
gwappa 13:8ea85a33e37a 67 */
gwappa 28:797536a42b9f 68 void assignCues(const Task& task, const bool& assignVisual=true, const bool& canfail=true);
gwappa 13:8ea85a33e37a 69
gwappa 17:0b241aa1f5b6 70 /**
gwappa 17:0b241aa1f5b6 71 * a callback mechanism for marking (timestamping) the start of the trial.
gwappa 17:0b241aa1f5b6 72 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 73 */
gwappa 11:897ecd5413e0 74 void markTrialStart();
gwappa 17:0b241aa1f5b6 75
gwappa 17:0b241aa1f5b6 76 /**
gwappa 17:0b241aa1f5b6 77 * a callback mechanism for marking (timestamping) the end of the waiting period of the trial.
gwappa 17:0b241aa1f5b6 78 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 79 */
gwappa 11:897ecd5413e0 80 void markEndOfWait();
gwappa 17:0b241aa1f5b6 81
gwappa 17:0b241aa1f5b6 82 /**
gwappa 17:0b241aa1f5b6 83 * a callback mechanism for marking (timestamping) the end of the trial.
gwappa 17:0b241aa1f5b6 84 * called from one of the automaton states.
gwappa 17:0b241aa1f5b6 85 */
gwappa 11:897ecd5413e0 86 void markTrialEnd();
gwappa 11:897ecd5413e0 87
gwappa 17:0b241aa1f5b6 88 /**
gwappa 17:0b241aa1f5b6 89 * output the result of a trial into a serial port through the IO mechanism.
gwappa 17:0b241aa1f5b6 90 * typically called from one of the automaton states.
gwappa 17:0b241aa1f5b6 91 */
gwappa 2:0c241937eabd 92 void writeToSerial();
gwappa 2:0c241937eabd 93 };
gwappa 2:0c241937eabd 94
gwappa 2:0c241937eabd 95 #endif