A class to hold the current state of the FSM. More...
Public Member Functions | |
| def | __init__ (self) |
| Initialize the state variable (only needs to be called once). More... | |
| def | set_delta (self, time_us) |
| Respond to a user button and set the time delta, in timer counts. More... | |
| def | record_reaction (self) |
| An asynchronous function to record the last reaction time. More... | |
| def | tick_test (self, timer) |
| Upon update from the timer, move the state forward by one step. More... | |
| def | REPORT (self, message) |
| Schedule a debug message to be reported with a time stamp. More... | |
| def | __init__ (self) |
| Initialize the state variable (only needs to be called once) | |
| def | poll_ADC (self, _) |
| Fill the buffer with ADC data and stop the FSM if a rising edge is detected. More... | |
| def | prune_buffer (self) |
| Prune the buffer to interesting region. More... | |
| def | start (self, _) |
| This is an interrupt that starts ADC polling to be triggered by the button's falling edge. | |
| def | stop (self, _) |
| This is an interrupt that stops ADC polling and indicates that data collection is finished. | |
Static Public Member Functions | |
| def | capture () |
| Measure all state geometry at this instant and update the current state. | |
| def | update () |
| Update the controllers for the current state. | |
| def | enqueue_data (stream) |
| Combine the current state into a JSON string and send it to a file stream. More... | |
| def | collect () |
| Reset the state and enable data collection. | |
Public Attributes | |
| epoch | |
| Set time to zero for debugging #. | |
| trigger_time | |
| Time (in counts) that the LED is turned on. | |
| delta | |
| Reaction time, by number of counts. | |
| button | |
| User button object. More... | |
| timer | |
| The timer that interrupts are based on. More... | |
| ch1 | |
| ch2 | |
| reaction_times | |
| A collection of all the reaction times. | |
| buffer | |
| A buffer of size BUFF_SIZE in which to store ADC counts of up to 16 bit #. | |
| FINISHED | |
| Indicate when the rising edge has been detected #. | |
Static Public Attributes | |
| bool | COLLECTING = False |
| Indicates if the nucleo is collecting data or not. | |
| touch_panel = TouchPanel(Pin.cpu.A7, Pin.cpu.A6, Pin.cpu.A0, Pin.cpu.A1) | |
| Touch panel driver. | |
| driver = MotorDriver() | |
| Motor driver. | |
| list | axies |
| Two axies of the system, each operating independently. More... | |
| float | time = 0.0 |
| Current system time [s]. | |
A class to hold the current state of the FSM.
The current state of the board.
A container for ADC events and buffer.
Sets up a timer with 1us divisions that responds to interrupts. Responsible for cycling the LED and recording reaction times.
After the state is 'started' it will poll the ADC as often as possible. Polling is done in buckets of size BUFF_SIZE with samples taken once every SAMPLE_PERIOD microseconds. Once the response is detected, polling is 'stopped'. This object can also prune buffers to the interesting region (rising edge).
| def main.State.__init__ | ( | self | ) |
Initialize the state variable (only needs to be called once).
Starts a timer to cycle the LED on and off, and record reaction times in between.
|
static |
Combine the current state into a JSON string and send it to a file stream.
| stream | A file object to write the data point to. |
| def main.State.poll_ADC | ( | self, | |
| _ | |||
| ) |
Fill the buffer with ADC data and stop the FSM if a rising edge is detected.
Polls the ADC at a frequency of 100kHz. This frequency provides good resolution without duplicating data points.
| _ | Not used, but required as an interrupt. |
| def main.State.prune_buffer | ( | self | ) |
Prune the buffer to interesting region.
Remove leading values below LOWER_THRESHOLD and trailing values above UPPER_THRESHOLD
| def main.State.record_reaction | ( | self | ) |
An asynchronous function to record the last reaction time.
This function will record the current state to a list of reaction times.
| def main.State.REPORT | ( | self, | |
| message | |||
| ) |
Schedule a debug message to be reported with a time stamp.
| message | The message to be reported. |
| def main.State.set_delta | ( | self, | |
| time_us | |||
| ) |
Respond to a user button and set the time delta, in timer counts.
| time_us | The time in microseconds (timer counts) since the trigger was set. |
| def main.State.tick_test | ( | self, | |
| timer | |||
| ) |
Upon update from the timer, move the state forward by one step.
If the LED is on, turn it off and set the OC timer to trigger randomly between 2-3s. If the LED is off, turn it on for 1 second and set the trigger starting time to now.
| timer | Unused placeholder to respond as an interrupt. |
|
static |
Two axies of the system, each operating independently.
| main.State.button |
User button object.
The button triggers the state to update its time delta value. This button is synchronized with the state clock.
| main.State.timer |
The timer that interrupts are based on.
A timer which starts the poll once ever 5us.
A timer with a period of 4s with 1us divisions, with two interrupt channels. Channel 1 is used for Output Control (Toggling the LED and changing state). Channel 2 is used for Input Capture (triggers when the user button is pressed).