fast-feedback virtual target task code on STM Nucleo

Dependencies:   mbed

Committer:
gwappa
Date:
Thu Dec 13 07:18:43 2018 +0000
Revision:
32:1416e015016c
Parent:
30:5f975f572ffb
change to use the Staged state

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 32:1416e015016c 13 bool rewarded; // only used during Pair mode
gwappa 19:50663f8815b8 14 bool reset;
gwappa 19:50663f8815b8 15
gwappa 29:1fb060aab1f8 16 TrialFlag(): cued(false), responded(false), rewarded(false), reset(false) {}
gwappa 19:50663f8815b8 17
gwappa 20:4c06d3041337 18 void clear();
gwappa 29:1fb060aab1f8 19 void writeToSerial(const Task& task);
gwappa 19:50663f8815b8 20 };
gwappa 2:0c241937eabd 21
gwappa 2:0c241937eabd 22 struct Trial {
gwappa 30:5f975f572ffb 23
gwappa 30:5f975f572ffb 24 /**
gwappa 32:1416e015016c 25 * the trial count used during the Pair/Report/Associate modes
gwappa 30:5f975f572ffb 26 */
gwappa 30:5f975f572ffb 27 uint8_t index;
gwappa 30:5f975f572ffb 28
gwappa 2:0c241937eabd 29 /**
gwappa 2:0c241937eabd 30 * whether the animal whisked during the cue.
gwappa 2:0c241937eabd 31 * + whether the animal waited for the cue.
gwappa 2:0c241937eabd 32 */
gwappa 19:50663f8815b8 33 TrialFlag flag;
gwappa 19:50663f8815b8 34
gwappa 2:0c241937eabd 35 /**
gwappa 2:0c241937eabd 36 * the timestamp when the trial started.
gwappa 2:0c241937eabd 37 */
gwappa 3:991c6d5ce19d 38 trialtime_t starting;
gwappa 2:0c241937eabd 39 /**
gwappa 2:0c241937eabd 40 * the timestamp when the cue started
gwappa 2:0c241937eabd 41 */
gwappa 3:991c6d5ce19d 42 trialtime_t cuestarting;
gwappa 24:e236faf66935 43
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 24:e236faf66935 48
gwappa 2:0c241937eabd 49 /**
gwappa 2:0c241937eabd 50 * the duration of the delay period for this trial.
gwappa 2:0c241937eabd 51 */
gwappa 2:0c241937eabd 52 uint16_t delay_dur_ms;
gwappa 2:0c241937eabd 53
gwappa 29:1fb060aab1f8 54 // (passive) visual cue-related param in the Associate mode.
gwappa 22:41163fb3fdc6 55 uint64_t vis_onset_us;
gwappa 13:8ea85a33e37a 56
gwappa 30:5f975f572ffb 57 Trial(): index(1) { }
gwappa 30:5f975f572ffb 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 29:1fb060aab1f8 71 void assignAssociative(const Task& task);
gwappa 29:1fb060aab1f8 72
gwappa 29:1fb060aab1f8 73 void assignForFeedback(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 29:1fb060aab1f8 91 void markTrialEnd(const Task& task);
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 29:1fb060aab1f8 97 void writeToSerial(const Task& task);
gwappa 2:0c241937eabd 98 };
gwappa 2:0c241937eabd 99
gwappa 2:0c241937eabd 100 #endif