Mechatronics
Documentation for ME 405 labs
main.State Class Reference

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].
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ __init__()

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.

Member Function Documentation

◆ enqueue_data()

def main.State.enqueue_data (   stream)
static

Combine the current state into a JSON string and send it to a file stream.

Parameters
streamA file object to write the data point to.

◆ poll_ADC()

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.

Parameters
_Not used, but required as an interrupt.

◆ prune_buffer()

def main.State.prune_buffer (   self)

Prune the buffer to interesting region.

Remove leading values below LOWER_THRESHOLD and trailing values above UPPER_THRESHOLD

Returns
A smaller array of ADC counts characterizing the rising edge.

◆ record_reaction()

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.

◆ REPORT()

def main.State.REPORT (   self,
  message 
)

Schedule a debug message to be reported with a time stamp.

Parameters
messageThe message to be reported.

◆ set_delta()

def main.State.set_delta (   self,
  time_us 
)

Respond to a user button and set the time delta, in timer counts.

Parameters
time_usThe time in microseconds (timer counts) since the trigger was set.

◆ tick_test()

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.

Parameters
timerUnused placeholder to respond as an interrupt.

Member Data Documentation

◆ axies

list main.State.axies
static
Initial value:
= [Axis("x",
Controller(driver.ch2),
Encoder(Pin("C6", mode=Pin.AF_PP, pull=Pin.PULL_NONE, af=Pin.AF3_TIM8),
Pin("C7", mode=Pin.AF_PP, pull=Pin.PULL_NONE, af=Pin.AF3_TIM8),
Timer(8, prescaler=0, period=0xFFFF))),
Axis("y",
Controller(driver.ch1),
Encoder(Pin("B6", mode=Pin.AF_PP, pull=Pin.PULL_NONE, af=Pin.AF2_TIM4),
Pin("B7", mode=Pin.AF_PP, pull=Pin.PULL_NONE, af=Pin.AF2_TIM4),
Timer(4, prescaler=0, period=0xFFFF)))]

Two axies of the system, each operating independently.

◆ button

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.

◆ timer

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).


The documentation for this class was generated from the following file: